开发者

Android bitmap.getwidth returns null?

开发者 https://www.devze.com 2023-03-28 06:38 出处:网络
I want to get the width of a bitmap after loading it and i am using this code where mybackground is an int that is equal to R.drawable.background.

I want to get the width of a bitmap after loading it and i am using this code where mybackground is an int that is equal to R.drawable.background.

background=BitmapFactory.decodeResource(开发者_JAVA技巧context.getResources(),mybackground );

scalefactorbackx=WindowInfo.Width/background.getWidth();
scalefactorbacky=WindowInfo.Height/background.getHeight();

So far it returns a null pointer exception on this line. I have to be doing something fundamentally wrong for this to fail. Tutorials online that I read appeared to just call the .getWidth() function and it was suppose to work.

Thanks


Your bitmap may be incorrect. Otherwise try to simplify your code to see where's the error. Or just check out some web pages.

0

精彩评论

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