简体   繁体   English

android 项目中可绘制资源的大小或数量是否有限制?

[英]Is there a limit on the size or number of Drawable resources in an android project?

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...我正在尝试使用我在paint.net中创建的.png文件作为可绘制资源来绘制到canvas,但我注意到了一个问题......

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.我尝试创建一些 500x500px 的.png 我像往常一样将它们复制到 res 文件夹中,没有错误并且编译良好。

However, when the app is running it's supposed to draw the image as 100x100px.但是,当应用程序运行时,它应该将图像绘制为 100x100 像素。

Well when the drawable is retrieved at run time, the app crashes with a null pointer exception.好吧,当在运行时检索可绘制对象时,应用程序会因 null 指针异常而崩溃。

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?此外,res文件夹中的文件数量是否有限制或一般有大小限制?

Edit: ok here is some code, of course i'm leaving a lot out but here's the jist:编辑:好的,这是一些代码,当然我遗漏了很多,但这是 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:这是我将它绘制到 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.这让我抓狂,问题显然是 java 或 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.假设我的可绘制文件夹中有 10 张图像。 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.除编号 7 外,所有图像都可以毫无错误地引用,我遇到的一个错误示例是,如果我删除编号 6。将显示编号 7,但现在编号 8 会出现错误,这清楚地告诉我有png 文件本身不会出错。 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.就好像可绘制文件中存在可以用 png 填充的“洞”,但随后它们无法使用。 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.例如:在 10 个图像的示例中,引用 10 将显示 9,9 将显示 8,8 将显示 7,依此类推。 This error seems to vanish after a clean and rebuild but I can't help but believe its related.在清理和重建后,这个错误似乎消失了,但我不禁相信它是相关的。

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.稍后我将发布关于该主题的更具体的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM