Question

I must create android application for tablets, app will be shows new magazines and his pages. Every magazine has about 70 pages, and every page have cover as image which weighs about 700 000 bytes. Main page of app show big image and small gallery (Gallery View) with images. I work on emulator with andrid 3.2. When I add images to gallery and I try slide it, it does't work smoothly. Sometimes does't load all images and LogCat show me this info:

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

Now I put into gallery about 7 images which I scale like this:

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;
}

and show in gallery like this:

    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;
    }

in future I will be have more imges in gallery and I can's imagine how it will be working.

My question is: what i should be doing ? How I should load images ?

Was it helpful?

Solution

You've asked a general question, so the best I can do is give you a general answer. You shouldn't have a bitmap for an entire page in the magazine. You should only use bitmaps for the picture portions of the page. The rest should be actual text. This will dramatically cut down your memory foot print. Furthermore, you should then lazy load those bit maps. Checkout this discussion for advice on how to lazy load images.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top