在android中使用位图的最佳方式;)
我必须为平板电脑创建android应用程序,该应用程序将显示新杂志和他的页面。每本杂志大约有70页,每一页的封面都是图像,重约70万字节。应用程序主页显示大图片和小图片库(图片库视图)。我使用andrid 3.2开发emulator。当我将图像添加到gallery并尝试滑动它时,它无法顺利工作。有时无法加载所有图像,LogCat会显示以下信息:在android中使用位图的最佳方式;),android,bitmap,imageview,galleryview,Android,Bitmap,Imageview,Galleryview,我必须为平板电脑创建android应用程序,该应用程序将显示新杂志和他的页面。每本杂志大约有70页,每一页的封面都是图像,重约70万字节。应用程序主页显示大图片和小图片库(图片库视图)。我使用andrid 3.2开发emulator。当我将图像添加到gallery并尝试滑动它时,它无法顺利工作。有时无法加载所有图像,LogCat会显示以下信息: 11-17 14:30:51.598: D/skia(5868): libjpeg error 105 < Ss=%d, Se=%d, Ah=%
11-17 14:30:51.598: D/skia(5868): libjpeg error 105 < Ss=%d, Se=%d, Ah=%d, Al=%d> from read_scanlines [128 168]
11-17 14:30:51.598: D/skia(5868): --- decoder->decode returned false
在未来,我将有更多的图片在画廊,我无法想象它将如何工作
我的问题是:我应该做什么?我应该如何加载图像?您提出了一个一般性问题,因此我只能给您一个一般性的答案。你不应该在杂志中有一整页的位图。您应该只对页面的图片部分使用位图。其余部分应为实际文本。这将大大减少你的记忆足迹。此外,您应该延迟加载这些位图。签出此文件以获取有关如何延迟加载图像的建议。我必须将任何页面封面用作图像;/但是,谢谢您的回复;)
public Bitmap decodeFile(String f) {
try {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
final int REQUIRED_SIZE=75;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true) {
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
public View getView(int position, View convertView, ViewGroup parent) {
View retval = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewitem, null);
ImageView iV = (ImageView) retval.findViewById(R.id.image);
String path = ArrayHelper.list.get(position).get("pageId").toString();
Bitmap bP = decodeFile(Environment.getExternalStorageDirectory() + "/MCW/" + path + "/head.jpg");
iV.setImageBitmap(bP);
return retval;
}