Java Android Eclipse - Resize/Scale image from directory storage -
this question has answer here:
i have string this
string path = "storage/sdcard0/pictures/location/img.jpg";
that string location file img.jpg. how can scale/resize image. thanks..
/* * resizing image size */ public static bitmap decodefile(string filepath, int width, int hight) { try { file f = new file(filepath); bitmapfactory.options o = new bitmapfactory.options(); o.injustdecodebounds = true; bitmapfactory.decodestream(new fileinputstream(f), null, o); final int required_width = width; final int required_hight = hight; int scale = 1; while (o.outwidth / scale / 2 >= required_width && o.outheight / scale / 2 >= required_hight) scale *= 2; bitmapfactory.options o2 = new bitmapfactory.options(); o2.insamplesize = scale; return bitmapfactory.decodestream(new fileinputstream(f), null, o2); } catch (filenotfoundexception e) { e.printstacktrace(); } return null; } bitmap image = decodefile(_filepaths.get(position), imagewidth, imageheight); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setlayoutparams(new gridview.layoutparams(imagewidth, imagewidth)); imageview.setimagebitmap(image);
Comments
Post a Comment