Quality Loss When storing images into SD card from GridView Android -


to images gallery used follwing code,

string[] projection = new string[]{     mediastore.images.media._id,     mediastore.images.media.bucket_display_name,     mediastore.images.media.date_taken,     mediastore.images.media.data,     mediastore.images.media.default_sort_order };  uri images = mediastore.images.media.external_content_uri;  cursor cur = managedquery(images,     projection, // columns return     "",         // rows return (all rows)     null,       // selection arguments (none)     ""          // ordering     );  if (cur.movetofirst()) { string bucket; string id; string filepath; int bucketcolumn = cur.getcolumnindex(     mediastore.images.media.bucket_display_name);  int datecolumn = cur.getcolumnindex(     mediastore.images.media._id); int datacolumnindex = cur.getcolumnindex(mediastore.images.media.data);  {     // field values     bucket = cur.getstring(bucketcolumn);     id = cur.getstring(datecolumn);     data=cur.getstring(datacolumnindex);      // values.     log.i("listingimages", " bucket=" + bucket         + "  date_taken=" + id + "data = "+filepath);  } while (cur.movetonext());  } 

and diplayed images in grid view using bitmap sampling method

private bitmap decodefile(string filepath){         //decode image size         bitmapfactory.options o = new bitmapfactory.options();         o.injustdecodebounds = true;         bitmapfactory.decodefile(filepath, o);          //find correct scale value. should power of 2.         final int required_size=70;          int width_tmp=o.outwidth, height_tmp=o.outheight;         int scale=1;          while(o.outwidth/scale/2>=required_size && o.outheight/scale/2>=required_size)     scale*=2;          //decode insamplesize         bitmapfactory.options o2 = new bitmapfactory.options();         o2.insamplesize=scale;         bitmap bitmap=bitmapfactory.decodefile(filepath, o2);          return bitmap; } 

then wanted select images grid view , store selected images sd card different sizes 640*480 , 120*90 means general image , thumbnail images

to store images sd card used following code,

file root = new file(environment.getexternalstoragedirectory()+ "/wo_photos");  if(!root.exists())      root.mkdirs();   bitmap selectedbitmap=bitmap.createbitmap(yourselectedimage.getwidth(), yourselectedimage.getheight(), bitmap.config.rgb_565);  canvas canvas = new canvas(selectedbitmap);     rect dstrect = new rect(0,0, yourselectedimage.getwidth(), yourselectedimage.getheight());      canvas.drawbitmap(yourselectedimage, dstrect, dstrect, null);  bytearrayoutputstream bytes = new bytearrayoutputstream();  bitmap bitmap=bitmap.createscaledbitmap(selectedbitmap, 640, 480, false);  bitmap.compress(bitmap.compressformat.jpeg, 100, bytes);  //you can create new file name "test.jpg" in sdcard folder. file f = new file(root,pos+"wo_image.jpg"); f.createnewfile(); //write bytes in file  fileoutputstream fo = new fileoutputstream(f); fo.write(bytes.tobytearray());  // remember close de fileoutput fo.close(); fout.close();    when see images in sd card has quality loss.however when store images without sampling bitmap gives outofmemory exeption.i belive quality loss in images giving sampling size.  images without quality loss should do?  thanks, 


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -