Android 位图上方和下方的额外空间
我正在从网站下载位图,然后将其显示在我的应用程序中。每当我下载此图像并将其设置到 ImageView 中时,实际图像的上方或下方总是有很多额外的空间。这个额外的空间是 ImageView 的一部分,并且仅在我将 ImageBitmap 设置为下载的位图后才存在。 所以,这让我认为额外的空间在某种程度上是位图的一部分。 但是,当我在 Webview 中下载相同的图像时,没有多余的空间。
如果您对为什么会发生这种情况有任何想法,请告诉我!如果您需要更多信息,请告诉我,谢谢。
编辑:这是我获取位图的代码:
InputStream in = null;
Message msg = Message.obtain();
msg.what = 1;
try{
in = openHttpConnection(_url);
if (in != null)
{
Bitmap bit = BitmapFactory.decodeStream(in);
Bundle b = new Bundle();
b.putParcelable("bitmap", bit);
msg.setData(b);
in.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
_handle.sendMessage(msg);
这就是我用于 ImageView 的代码,我从上面的代码中获取位图:
imageV.setImageBitmap(comic);
编辑 2: 在尝试使用来自不同网站的其他一些图像后,我发现这个空白并不总是存在。鉴于此,并且代码可能没有任何问题,是否有任何关于删除此额外空间的建议,因为它没有显示在在线实际图像中或网络视图中?
I am downloading a bitmap from a website and then displaying it in my application. Whenever I download this image and set it into an ImageView, there is always a lot of extra space above or below the actual image. This extra space is part of the ImageView and is only there after I set the ImageBitmap to the downloaded bitmap.
So, this is making me think that the extra space is somehow part of the bitmap.
However, when I download the same image in a Webview, there is no extra space.
If you have any ideas on why this could be happening, please let me know! Let me know if you need any more information, thanks.
Edit: Here's my code getting the bitmap:
InputStream in = null;
Message msg = Message.obtain();
msg.what = 1;
try{
in = openHttpConnection(_url);
if (in != null)
{
Bitmap bit = BitmapFactory.decodeStream(in);
Bundle b = new Bundle();
b.putParcelable("bitmap", bit);
msg.setData(b);
in.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
_handle.sendMessage(msg);
And this is what I use to then for the ImageView, I get the bitmap from the code above and:
imageV.setImageBitmap(comic);
Edit 2:
After trying this with some other images from different website, I've found that this white space is not always there. Given that, and there's probably not anything wrong with the code, are there any suggestions on removing this extra space since it doesn't show up in the actual image online nor in a webview?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
imageSize = din.readInt();
图像名称 = din.readUTF();
字节 b[] = 新字节[图像大小];
din.readFully(b);
bmImg = BitmapFactory.decodeByteArray(b,0,b.length);
//这对我有用......
//din 是 DataInputStream 对象。
imageSize = din.readInt();
imageName = din.readUTF();
byte b[] = new byte[imageSize];
din.readFully(b);
bmImg = BitmapFactory.decodeByteArray(b,0,b.length);
//This works for me....
//din is DataInputStream object.