タブレット用の Android アプリケーションを作成する必要があります。アプリは新しい雑誌と彼のページを表示します。各雑誌は約 70 ページあり、各ページには約 700 000 バイトの画像として表紙があります。アプリのメイン ページには、大きな画像と画像付きの小さなギャラリー (ギャラリー ビュー) が表示されます。私はandrid 3.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;
}
将来的には、ギャラリーにさらに多くの画像が表示されるようになり、それがどのように機能するか想像できます.
私の質問は次のとおりです。私は何をすべきですか? 画像を読み込むにはどうすればよいですか?