我必须为平板电脑创建android应用程序,应用程序将显示新的杂志和他的页面。每本杂志约70页,每页以图片形式封面,重约70万字节。应用程序的主页显示大图像和小画廊(画廊视图)与图像。我使用andrid3.2开发模拟器。当我将图像添加到图库中并尝试滑动它时,它不能顺利地工作。有时无法加载所有图像,而LogCat会显示以下信息:
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现在我在画廊里放了大约7张图片,我的比例如下:
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;
}在未来,我将有更多的图片在画廊中,我可以想象它将如何工作。
我的问题是:我应该做什么?我应该如何加载图像?
发布于 2011-11-17 23:30:01
你已经问了一个一般性的问题,所以我只能给你一个一般性的答案。你不应该在杂志中有一整页的位图。您应该只对页面的图片部分使用位图。其余部分应该是实际的文本。这将大大减少你的内存占用空间。此外,您还应该延迟加载这些位图。请查看此discussion以获取有关如何延迟加载图像的建议。
https://stackoverflow.com/questions/8169726
复制相似问题