Android stores images to the data directory and reads images from the data directory

Source: Internet
Author: User

Public voidStorepic (StringTabIDStringKeyBitmapBitmap) {
logutils.LOGD(TAG,"Storepic Begin tabid ="+ TabID +"key ="+ key);
FileOutputStreamFOS =NULL;
Try{
FOS = Getactivity (). Openfileoutput (TabID +"_" + Key, Context.mode_private);
Bitmap.compress (Bitmap.compressformat.PNG, -, FOS);
}Catch(FileNotFoundExceptionE) {
logutils.LOGE(TAG,"Storepic filenotfoundexception e ="+E);
}finally{
if(Fos! =NULL) {
Try{
Fos.flush ();
Fos.close ();
}Catch(IOExceptionE) {
logutils.LOGE(TAG,"Storepic ioexception e ="+E);
}
}
}
}

PublicBitmapGetstorepic (StringTabIDStringKey) {
logutils.LOGD(TAG,"Getstorepic Begin tabid ="+ TabID +"key ="+ key);
FileInputStreamFin =NULL;
BitmapBitmap =NULL;
Try{
Fin = getactivity (). Openfileinput (TabID +"_" + key);
Bitmap =bitmapfactory.Decodestream(Fin);
}Catch(FileNotFoundExceptionE) {
logutils.LOGE(TAG,"Getstorepic filenotfoundexception e ="+ e);
}
returnBitmap
}


Total and process:
Store Picture code:

[Java]View PlainCopy
  1. String str1 = "Icon.png"  ;
  2.   
  3. fileoutputstream localfileoutputstream1 = openfileoutput (str1, < Span style= "margin:0px; padding:0px; Border:none; Color: #c00000; Background-color:inherit ">0
  4. Bitmap.compressformat Localcompressformat = Bitmap.CompressFormat.PNG;
  5. &NBSP;&NBSP;
  6. bitmap.compress (Localcompressformat, 100 , localfileoutputstream1 );   
  7. Localfileoutputstream1.close ();

To read the image code:

[Java]View PlainCopy
  1. string localiconnormal =  " icon.png " ;&NBSP;&NBSP;
  2. FileInputStream Localstream = Openfileinput (localiconnormal);
  3. Bitmap Bitmap = Bitmapfactory.decodestream (Localstream));

Android stores pictures to the data directory and reads pictures under the data directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.