异常:Resources$NotFoundException:资源 ID #0x4

发布于 2024-12-13 05:40:39 字数 783 浏览 2 评论 0原文

我需要放大图像,我正在使用以下代码

  int imageId =  (Integer) intent.getExtras().get(ProfilePageNormalUser.class.getName());
  imageView = (ImageView)findViewById(R.id.imageviewEnlarged);
  System.out.println("*********"+imageId);

  InputStream is = this.getResources().openRawResource(imageId);
  Bitmap originalBitmap = BitmapFactory.decodeStream(is);
  Matrix imageMatrix = new Matrix(); imageMatrix.postRotate(90);
  Bitmap scaledBitmap = Bitmap.createBitmap(originalBitmap, imageView.getWidth(), imageView.getHeight(), originalBitmap.getWidth(), originalBitmap.getHeight(), imageMatrix, false);
  imageView.setImageBitmap(scaledBitmap);

,但给了我上述异常。

         Resources$NotFoundException: Resource ID #0x4

谁能告诉我哪里可能有问题。 谢谢

I need to enlarge image I am using the following code for it

  int imageId =  (Integer) intent.getExtras().get(ProfilePageNormalUser.class.getName());
  imageView = (ImageView)findViewById(R.id.imageviewEnlarged);
  System.out.println("*********"+imageId);

  InputStream is = this.getResources().openRawResource(imageId);
  Bitmap originalBitmap = BitmapFactory.decodeStream(is);
  Matrix imageMatrix = new Matrix(); imageMatrix.postRotate(90);
  Bitmap scaledBitmap = Bitmap.createBitmap(originalBitmap, imageView.getWidth(), imageView.getHeight(), originalBitmap.getWidth(), originalBitmap.getHeight(), imageMatrix, false);
  imageView.setImageBitmap(scaledBitmap);

But is giving me the above exception .

         Resources$NotFoundException: Resource ID #0x4

Can anyone tell me where could be the problem.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

动次打次papapa 2024-12-20 05:40:39

我想使用 this.getResources().openRawResource(id) 。您必须将资源移动到 res/raw 文件夹。

尝试在 res 文件夹下创建一个名为 raw 的文件夹,并将您的资源粘贴到其中。

让我知道进展如何..

i think to use this.getResources().openRawResource(id). You'll have to move your resource to res/raw folder.

Try creating a folder named raw under res folder and paste your resource there.

Let me know how it goes..

梦忆晨望 2024-12-20 05:40:39

OpenRawResource 无法从您正在使用的 imageId 找到资源。

检查您的图像 ID。

您可以直接使用:我认为:InputStream ins = getResources().openRawResource(R.raw.my_db_file);

像上面提到的那样从原始文件夹中指定imageId。

先这样检查一下是否有效。

OpenRawResource couldn't find the resouce from imageId that you are using.

Check your imageId.

You can use directly: I think : InputStream ins = getResources().openRawResource(R.raw.my_db_file);

the specify imageId like mentioned above from raw folder.

Check first like this , it works or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文