標籤:code style icon view string 流程 .net splay out
public void storePic(String tabid, String key, Bitmap bitmap) {
LogUtils.LOGD(TAG, "storePic begin tabid = " + tabid + "key = " + key);
FileOutputStream fos = null;
try {
fos = getActivity().openFileOutput(tabid + "_" + key, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (FileNotFoundException e) {
LogUtils.LOGE(TAG, "storePic FileNotFoundException e = " +e);
} finally {
if(fos != null) {
try {
fos.flush();
fos.close();
} catch (IOException e) {
LogUtils.LOGE(TAG, "storePic IOException e = " +e);
}
}
}
}
public Bitmap getStorePic(String tabid, String key) {
LogUtils.LOGD(TAG, "getStorePic begin tabid = " + tabid + "key = " + key);
FileInputStream fin = null;
Bitmap bitmap = null;
try {
fin = getActivity().openFileInput(tabid + "_" + key);
bitmap = BitmapFactory.decodeStream(fin);
} catch (FileNotFoundException e) {
LogUtils.LOGE(TAG, "getStorePic FileNotFoundException e = " + e);
}
return bitmap;
}
總而流程:
儲存圖片代碼:[java] view plain copy
- String str1 = "icon.png";
-
- FileOutputStream localFileOutputStream1 = openFileOutput(str1, 0);
-
- Bitmap.CompressFormat localCompressFormat = Bitmap.CompressFormat.PNG;
-
- bitmap.compress(localCompressFormat, 100, localFileOutputStream1);
-
- localFileOutputStream1.close();
讀取圖片代碼:
[java] view plain copy
- String localIconNormal = "icon.png";
-
- FileInputStream localStream = openFileInput(localIconNormal);
-
- Bitmap bitmap = BitmapFactory.decodeStream(localStream));
android 儲存圖片到data目錄和讀取data目錄下的圖片