barzos
barzos

Reputation: 857

How can I decrease the size of a bitmap without loss of resolution in Android?

I have an application that takes a picture from the camera and then I do some image processing operations on that picture. But that's taking too long, so I want to decrease the size of the bitmap before the image processing operations. The important part is that resolution must be good in the smaller image also. Is there a library in android or is there anybody who knows an algorithm for that operation?

Upvotes: 3

Views: 3255

Answers (2)

Pranav
Pranav

Reputation: 237

    { 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

Upvotes: 0

Mark Ransom
Mark Ransom

Reputation: 308176

One method is to take the average of every n*n block and convert it to a single pixel. It isn't the absolutely sharpest method and won't be completely free of artifacts, but I think you'll find the real-world results to be acceptable - and it's very fast.

Upvotes: 1

Related Questions