开发者

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

开发者 https://www.devze.com 2023-03-27 17:04 出处:网络
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'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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消