有关自定义画廊IM使用与imageviews的GridView创建,我想读从标清存储的图像。这给了我巨大的性能比较的问题,因为它会读取整个图像,而这个加载到ImageView的。
我怎样才能读取一个大的图像在运行时用拇指强调性能?
文件imgFile =新的文件(img.getInternalImagePath());如果(imgFile.exists()){ 位图MYBITMAP; 尝试{ BitmapFactory.Options选项=新BitmapFactory.Options(); options.inSampleSize = 4; MYBITMAP = BitmapFactory.de codeStream(新FlushedInputStream(新 的FileInputStream(imgFile)),空,期权); picture.setImageBitmap(MYBITMAP);
先谢谢了。
/安迪
编辑:增加了一些code看看
解决方案 最终诠释THUMBNAIL_SIZE = 64;FIS的FileInputStream =新的FileInputStream(文件名);位图imageBitmap = BitmapFactory.de codeStream(FIS);imageBitmap = Bitmap.createScaledBitmap(imageBitmap,THUMBNAIL_SIZE,THUMBNAIL_SIZE,FALSE);ByteArrayOutputStream BAOS =新ByteArrayOutputStream();imageBitmap.com preSS(Bitmap.Com pressFormat.JPEG,100,BAOS);为imageData = baos.toByteArray();
或
位图thumbBitmap = ThumbnailUtils.extractThumbnail(BitmapFactory.de codeFILE(文件路径),thumbWidth,thumbHeight);
For a custom gallery im creating using a gridview with imageviews, i wish to read an image from sd storage. This gives me huge perfomance issues, because it will read the whole image, and load this into the imageview.
How can i read a large image as a thumb in runtime with emphasis on performance?
File imgFile = new File(img.getInternalImagePath());
if(imgFile.exists()){
Bitmap myBitmap;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
myBitmap = BitmapFactory.decodeStream(new FlushedInputStream(new
FileInputStream(imgFile)),null,options);
picture.setImageBitmap(myBitmap);
Thanks in advance.
/Andy
EDIT: Added some code to look at
解决方案final int THUMBNAIL_SIZE = 64;
FileInputStream fis = new FileInputStream(fileName);
Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
OR
Bitmap thumbBitmap = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(filePath), thumbWidth, thumbHeight);