java - Android: Resizing Bitmaps without losing quality -


i've searched through on entire web before posting. problem cannot resize bitmap without losing quality of image (the quality bad , pixelated).

i take bitmap camera , have downscale it, can upload server faster.

this function sampling

public bitmap resizebitmap(bitmap bitmap){          canvas canvas = new canvas();          bitmap resizedbitmap = null;          if (bitmap !=null) {                 int h = bitmap.getheight();                 int w = bitmap.getwidth();                 int newwidth=0;                 int newheight=0;                  if(h>w){                     newwidth = 600;                     newheight = 800;                 }                  if(w>h){                     newwidth = 800;                     newheight = 600;                     }                  float scalewidth = ((float) newwidth) / w;                 float scaleheight = ((float) newheight) / h;                    matrix matrix = new matrix();                 // resize bit map                 matrix.prescale(scalewidth, scaleheight);                  resizedbitmap  = bitmap.createbitmap(bitmap, 0, 0, w, h, matrix, true);                    paint paint = new paint();                 paint.setantialias(true);                 paint.setfilterbitmap(true);                 paint.setdither(true);                  canvas.drawbitmap(resizedbitmap, matrix, paint);                }           return resizedbitmap;    

and how image activity result

 protected void onactivityresult(int requestcode, int resultcode,              intent data) {          if(resultcode != result_canceled){           if (requestcode == 0) {              if (resultcode == result_ok) {                       getcontentresolver().notifychange(mimageuri, null);                     contentresolver cr = this.getcontentresolver();                      try                     {                         b = android.provider.mediastore.images.media.getbitmap(cr, mimageuri);                         log.d("foto", integer.tostring(b.getwidth()));                         log.d("foto", integer.tostring(b.getheight()));                         addphoto.setimagebitmap(b);                      }                     catch (exception e)                     {                         toast.maketext(this, "failed load", toast.length_short).show();                         log.d("tag", "failed load", e);                     }                 }          } 

i'm starting think best way small picture size set camera resolution. else can help?

try bitmap.createscaledbitmap. has option filter source.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -