字节 [] 到图像 android
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2714700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
byte[] to image android
提问by Sephy
My issue is as follows : I have stored a few pictures into the sqlite database, using the blob format, which seems to work ok. now i want to get my pictures out of the DB and put then back into images... to complicate the matter, their format is variable (png, jpg, maybe something else, im not sure) Is there a way of doing so in android?
我的问题如下:我使用 blob 格式将一些图片存储到 sqlite 数据库中,这似乎可以正常工作。现在我想把我的照片从数据库中取出然后放回图像中......让问题复杂化,它们的格式是可变的(png,jpg,也许是别的,我不确定)有没有办法这样做安卓?
thank you
谢谢你
回答by systempuntoout
Use BitmapFactory.decodeByteArray()method:
使用BitmapFactory.decodeByteArray()方法:
byte[] blob=c.getBlob("yourcolumnname");
Bitmap bmp=BitmapFactory.decodeByteArray(blob,0,blob.length);
ImageView image=new ImageView(this);
image.setImageBitmap(bmp);
Look at thisthread too.
也看看这个线程。
回答by Dan Lew
回答by J.S.R - Silicornio
I prefer to convert the array of bytes to Drawable directly. It is the best format to use in Android. Bitmaps generated leaks in the past.
我更喜欢将字节数组直接转换为 Drawable。这是在 Android 中使用的最佳格式。位图过去会产生泄漏。
Drawable d = Drawable.createFromStream(new ByteArrayInputStream(ARRAY_BYTES), null);