0
我必須爲平板電腦創建android應用程序,應用程序將顯示新雜誌和他的頁面。每本雜誌大約有70頁,每一頁都有一個圖像,重量約爲700 000字節。應用程序的主頁顯示大圖像和小圖庫(圖庫視圖)與圖像。我使用andrid 3.2工作在模擬器上。當我將圖像添加到圖庫,然後嘗試將其滑動時,效果不理想。有時簡化版,負載的所有圖像和logcat的告訴我這個信息:在Android中使用位圖的最佳方式;)
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;
}
未來我會在畫廊裏展示更多imges,我可以想象它將如何工作。
我的問題是:我該怎麼做?我應該如何加載圖像?
我必須使用任何頁面封面作爲圖像; /但是,thx的答覆;) –