如何將圖像複製到內部存儲器並在此之後恢復?將圖像複製到內部存儲器
3
A
回答
12
您可以使用openFileOutput()和Bitmap.compress()的以下組合,以將圖像存儲到內部存儲。
// Create a BitMap object of the image to be worked with
final Bitmap bm = BitmapFactory.decodeStream(..some image..);
// The openfileOutput() method creates a file on the phone/internal storage in the context of your application
final FileOutputStream fos = openFileOutput("my_new_image.jpg", Context.MODE_PRIVATE);
// Use the compress method on the BitMap object to write image to the OutputStream
bm.compress(CompressFormat.JPEG, 90, fos);
1
我會做的方式如下:
//read bitmap from resource
public InputStream getBitmapStreamFromResource(Context context, int recourceId)
{
return context.getResources().getAssets().open(recourceId);
}
// convert stream into Bitmap
public Bitmap getBitmapFromStream(InputStream is)
{
return BitmapFactory.decodeStream(is);
}
//inflate bitmap in a given parent View
public View inflateToView(Context context, ViewGroup parent, Bitmap bitmap)
{
ViewGroup layout=new LinearLayout(context);
layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
ImageView imageView=new ImageView(context);
imageView.setEnabled(true);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(bitmap);
layout.addView(imageView);
parent.addView(layout);
return layout;
}
+0
我需要在內部存儲器中複製圖像 – Alex 2010-11-09 16:54:43
相關問題
- 1. 將存儲的圖像檢索到內部存儲器
- 2. 將圖像插入內部存儲器
- 3. 將Android內部存儲器中的圖像文件複製到相冊
- 4. 從沙盒複製圖像並將其粘貼到iPad/iphone內部存儲器
- 5. 將創建的位圖圖像保存到內部存儲器
- 6. 下載圖像到內部存儲器
- 7. 如何將圖像保存到內部存儲器
- 8. Android,如何將圖像存儲在內部存儲器中?
- 9. 無法將圖像存儲到內部存儲目錄中
- 10. 在Android中將文件從內部複製到外部存儲
- 11. 將文件複製到外部存儲或從外部存儲中複製
- 12. 捕獲圖像並將其保存在內部存儲器上
- 13. Android如何將文件夾從內部存儲器複製到外部
- 14. 使用硒將瀏覽器內存中的圖像複製到python內存中
- 15. 如何從內部存儲器拍照並將拍攝圖像保存在內部存儲器android中?
- 16. 將文件複製到科爾多瓦的內部存儲中
- 17. 在android內部存儲器中存儲圖像
- 18. 無法在內部存儲器中存儲圖像
- 19. 共享存儲在內部存儲器中的圖像
- 20. 在內部存儲器中存儲圖像的位置?
- 21. android-在內部存儲器中存儲圖像
- 22. 將圖像保存到外部存儲器(如果可用)
- 23. 將圖像保存到內部存儲器,並會出現在畫廊
- 24. 如何將從相機拍攝的圖像保存到內部存儲器
- 25. Github將存儲庫內容複製到另一個存儲庫
- 26. 將圖像資源映射到內部存儲運行時
- 27. Android:無法從內部存儲器加載圖像到webview
- 28. 如何從內部存儲器共享圖像到Gmail?
- 29. Winrt c#將資產中的圖像複製到本地存儲
- 30. 將圖像文件複製到手機存儲
你是什麼意思恢復?你可以說得更詳細點嗎? – 2010-11-09 16:21:32