How to reduce the size of a bitmap without losing resolution in Android?

I have an application that takes a picture from the camera, and then perform some image processing operations on this picture. But it takes too much time, so I want to reduce the size of the bitmap to image processing operations. The important part is that the resolution should be good and in a smaller image. Is there a library in android or is there anyone who knows the algorithm for this operation?

+3
source share
2 answers

One method is to take the average value for each n * n block and convert it to one pixel. This is not a very sharp method and will not be completely free of artifacts, but I think that you will find the real world results acceptable - and it is very fast.

+1
source
    { Bitmap bit=Shrinkmethod(arrpath1[position], 100, 100); 
       //This reduce the size of image in 1kb size so u can also consider VM nativeheap memory

                    iv.setImageBitmap(bit);//ImageView Obj.

    }


    //To reduce the byte size of image in program

//user defined method to reduce size of image without reducing the quality of img.
        Bitmap Shrinkmethod(String file,int width,int height){
            BitmapFactory.Options bitopt=new BitmapFactory.Options();
            bitopt.inJustDecodeBounds=true;
            Bitmap bit=BitmapFactory.decodeFile(file, bitopt);

            int h=(int) Math.ceil(bitopt.outHeight/(float)height);
            int w=(int) Math.ceil(bitopt.outWidth/(float)width);

            if(h>1 || w>1){
                if(h>w){
                    bitopt.inSampleSize=h;

                }else{
                    bitopt.inSampleSize=w;
                }
            }
            bitopt.inJustDecodeBounds=false;
            bit=BitmapFactory.decodeFile(file, bitopt);



            return bit;

        }

//Try to upload ur project code and idea so that like u and me can get that to develop more android application..

Regard,
pranav
0
source

All Articles