Saving a bitmap file in android and reading back to display in Imageview -


i have bitmap file need upload php server file large decided resize , save it. later on try read display resized image. time not getting same image below code writing image , returning file

public static file savebitmap(bitmap bmp) throws ioexception {     bytearrayoutputstream bytes = new bytearrayoutputstream();     bmp.compress(bitmap.compressformat.jpeg, 100, bytes);     file f = new file(environment.getexternalstoragedirectory()             + file.separator + "testimage.jpg");     f.createnewfile();     fileoutputstream fo = new fileoutputstream(f);     fo.write(bytes.tobytearray());     fo.close();     return f;  } 

below code reading , displaying

file file=imageutil.savebitmap(this.bitmap);             this.imgchoosenimage.setimageuri(uri.parse(file.getabsolutepath())); 

please tell me going wrong here

first check images saved in ur path defined, , make sure ur giving correct path retriving image. have used below code saving imge in gallery

string iconsstoragepath = environment.getexternalstoragedirectory()+ file.separator;         file sdiconstoragedir = new file(iconsstoragepath);         //create storage directories, if don't exist         sdiconstoragedir.mkdirs();         try {             string filepath = null;             filepath = environment.getexternalstoragedirectory() + file.separator + "testimage" + ".jpg";             fileoutputstream fileoutputstream = new fileoutputstream(filepath);             bufferedoutputstream bos = new bufferedoutputstream(fileoutputstream);             bmp.compress(bitmap.compressformat.jpg, 100, bos);             bos.flush();             bos.close();         } catch (ioexception e) {             log.w("tag", "error saving image file: " + e.getmessage());             toast.maketext(getapplicationcontext(), "failed create folder",                     toast.length_short).show();         } 

for bitmap display in imageview :

file imgfile = new  file("/sdcard/images/testimage.jpg");     //here file file = ur file path     if(imgfile.exists())     {     bitmap mybitmap = bitmapfactory.decodefile(imgfile.getabsolutepath());     imageview myimage = (imageview) findviewbyid(r.id.imageviewtest);     myimage.setimagebitmap(mybitmap);     } 

permissions:

<uses-permission android:name="android.permission.write_external_storage" />         <uses-permission android:name="android.permission.read_external_storage" /> 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -