Android - 从资产中绘制图像,发生了奇怪的事情
我正在从资产文件夹加载图像以在谷歌地图视图上绘制为叠加层。在我的 try-catch 语句中,我尝试加载图像,否则返回 null。
我不明白的是,在一次又一次地单步执行代码时,它到达加载线并失败,从而返回 null,但由于某种原因,尽管返回空图像,但图像实际上已正确加载并绘制...??
如果我正常运行程序,它会加载图像并正确显示它,但该函数每次仍然返回空位图。我在这里错过了什么吗?
这是我用来加载图像的代码:
BitmapFactory.decodeStream(myActivity.getAssets().open("squirrel.jpg"));
编辑: 我尝试了另一个随机图像,这次是 .png,它仍然做同样的事情,但仍然正确加载和绘制。
I am loading an image from the assets folder to draw on a google map view as an overlay. In my try-catch statement, I attempt to load the image, otherwise return null.
What i don't understand is, upon stepping through the code time and time again, it gets to the load line and fails, thus returning null, but for some reason, despite returning a null image, the image is actually correctly loaded and drawing...??
If i run the program normally, it loads the image and displays it correctly as it should but the function is still returning a null bitmap everytime. Have i missed something here?
Here is the code I am using to load the image:
BitmapFactory.decodeStream(myActivity.getAssets().open("squirrel.jpg"));
Edit:
I tried another random image, this time a .png and it is still doing the same thing but still loaded and drawing correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的调试器可能会跳到 catch 语句中的 return null 行,因为调试器喜欢让您认为它正在返回实际上不是的行。
Your debugger might be skipping to the return null line in the catch statement, because the debugger likes to make you think it's returning on a line that it actually isn't.