android项目中Drawable资源的大小或数量有限制吗?

发布于 2024-11-29 13:05:55 字数 1062 浏览 1 评论 0原文

我正在尝试使用我在paint.net中创建的.png文件作为可绘制资源来绘制到画布上,但我注意到一个问题...

我尝试创建一些500x500px的.png文件,并将它们复制到res 文件夹像平常一样,没有错误并且编译得很好。

但是,当应用程序运行时,它应该将图像绘制为 100x100px。

当在运行时检索可绘制对象时,应用程序会因空指针异常而崩溃。

这里的罪魁祸首是什么?可绘制图像是否太大?或者调整图像大小是否有限制?

此外,res 文件夹中的文件数量或大小是否有限制?

编辑:好的,这里是一些代码,当然我遗漏了很多,但要点如下:

这是我如何创建句柄并为其提供正确的资源:

Drawable pic;
pic = context.getResources().getDrawable(R.drawable.picture);

这是我如何将其绘制到画布上:

pic.setBounds(x, y, x + 100, y + 100);
pic.draw(c); 

更新

这让我抓狂! 这个问题显然是java或eclipse中的错误,即使它是本地化到我的机器上的。 我做了一些实验,发现这个问题可能会受到影响。 假设我的可绘制文件夹中有 10 张图像。除了 7 号之外,所有图像都可以毫无错误地引用。我遇到的错误示例是,如果我删除 6 号,则将显示 7 号,但现在 8 号将出现错误。这清楚地告诉我,png 文件本身没有错误,但问题出在它们的检索方式上。它还与图像的顺序有关。

我已经尝试了一切。清理/构建不起作用。我什至重新上传了整个可绘制文件,错误仍然发生。

就好像可绘制文件中存在可以用 png 填充的“洞”,但随后它们就无法使用了。填充漏洞后,按字母顺序排列的文件不在漏洞中。如果你明白我的意思。

我偶尔也会遇到一个奇怪的错误,似乎突然每个引用都检索到错误的图像。例如:在 10 个图像的示例中,引用 10 将显示 9,9 将显示 8,8 将显示 7,依此类推。在清理和重建后,这个错误似乎消失了,但我忍不住相信它是相关的。

I'm attempting to use .png files I've created in paint.net as drawable resources to draw to a canvas, but I've noticed a problem...

I tried creating a few .png's that are 500x500px I copied them into the res folder like normal, got no errors and it compiled fine.

However, when the app is running it's supposed to draw the image as 100x100px.

Well when the drawable is retrieved at run time, the app crashes with a null pointer exception.

What is the culprit here? Is the drawable image too big? or Is there a limitation in re-sizing the image?

Additionally, is there a limit to the number of files in the res folder or a size limitation in general?

Edit: ok here is some code, of course i'm leaving a lot out but here's the jist:

Here's how I create a handle and give it the correct resource:

Drawable pic;
pic = context.getResources().getDrawable(R.drawable.picture);

Here's how I draw it to the canvas:

pic.setBounds(x, y, x + 100, y + 100);
pic.draw(c); 

UPDATE

THIS IS DRIVING ME NUTS!
the problem is clearly an error in java or eclipse, even if it's localized to my machine.
I've done some experimenting and found that the problem could be influenced.
Let's say I have 10 images in my drawable folder. All of the images can be referenced without error except number 7. An example of an error i'm getting is that if I delete number 6, number 7 will display but now number 8 will get the error. This tells me clearly that there aren't errors with the png files themselves, but that the problem is occurring in how they are being retrieved. It also has something to do with the order the images are in.

I've tried everything. clean / build doesn't work. I even re-uploaded the entire drawable file and the error still occurs identically.

It's almost as though there are "holes" in the drawable file that can be filled with pngs, but then they are unusable. and after you fill the holes the files alphabetically after it are not in holes. If you get my meaning.

I've also occasionally run into an odd error where it seems all the sudden every reference retrieves the wrong image. For example: in the example of 10 images referencing 10 would display 9, 9would display 8, 8 would display 7, and so on. This error seems to vanish after a clean and rebuild but I can't help but believe its related.

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

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

发布评论

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

评论(1

凌乱心跳 2024-12-06 13:05:55

事实证明,这个问题与图像本身没有任何关系,我还没有完全缩小原因,但通过一些长时间、耗时的故障排除,我发现图像不是问题,我个人有一些其他错误。稍后我将就该主题发布一个更具体的问题。

It turns out that this problem didn't have anything to do with the images themselves, I have not narrowed down the cause completely but through some long, time-consuming troubleshooting I have discovered that the pictures are not the problem, I personally have some other error. I will post a more specific question on the topic later.

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