我正在製作一個聊天應用程序,其中用戶也可以選擇發送圖片。我想將圖像保存到應用程序文件夾中,以便我可以訪問這些圖像,以便使用圖片和文本填充聊天窗口。所以我的問題是如何將圖像添加到應用程序文件夾? 感謝將圖像保存在應用程序文件夾中?
-1
A
回答
1
首先你要創建的應用程序名稱的文件夾到SD卡,那麼你有你的文件/圖片寫進去
String SDCardRoot = Environment.getExternalStorageDirectory().toString();
String filename = "fileName" + ".jpg";
File myDir = new File(SDCardRoot + "/AppName");
myDir.mkdirs();
File file = new File(myDir, filename);
FileOutputStream fileOutput = new FileOutputStream(file);
//write the file into the sdcard folder specify your buffer , bufferLength
fileOutput.write(buffer, 0, bufferLength);
fileOutput.close();
那麼只有你可以從應用程序文件夾中訪問這些文件
File imgFile;
String path = Environment.getExternalStorageDirectory() + "/AppName/" + ".jpg";
imgFile = new File(path);
if (imgFile.exists()) {
Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(bitmap);
}
+0
非常感謝您的幫助! – revipod
+0
歡迎,如果它對你有幫助,然後接受我的答案 –
相關問題
- 1. 將圖像保存到應用程序文件夾中
- 2. iPhone - UIImagePickerController - >將圖像保存到應用程序文件夾
- 3. 將png文件保存在應用程序圖像文件夾中而不使用保存對話框文件
- 4. 將文件保存在應用程序文件夾中
- 5. UWP應用程序試圖將文件保存到文件夾
- 6. 在Silverlight的應用程序圖像文件夾中保存PNG文件
- 7. 將圖像保存到照片文件夾在hololens應用程序
- 8. 如何將圖像文件保存到應用程序中?
- 9. PhoneGap - 如何複製圖像並保存在應用程序文件夾中?
- 10. 將圖像保存在應用程序文檔中
- 11. 將文件保存到MyDocuments +應用程序文件夾
- 12. Android:將圖像保存到文件夾
- 13. C#:將圖像保存到文件夾
- 14. 將圖像文件保存到IBM Bluemix Node.js應用程序
- 15. 將圖像/視頻文件保存到子文件夾中的應用程序內部存儲器
- 16. ios:緩存應用程序文件夾中的圖像
- 17. 使用for循環將圖像保存在文件夾中
- 18. 將文件保存在Windows 8應用程序的本地文件夾中
- 19. 錯誤:試圖將文件保存到UWP應用程序文件夾
- 20. 將我的圖片文件夾中的圖像保存到Windows 8中的本地應用程序文件夾Metro應用程序
- 21. 從iOS上的UIView保存圖像到應用程序文檔文件夾
- 22. ios應用程序中保存圖像
- 23. 將圖像存儲在iOS應用程序的xml文件中
- 24. 在應用程序的保存箱中創建文件夾
- 25. 將BitMapImage保存到應用程序文件夾
- 26. 如何將JDeveloper 11g應用程序保存到新文件夾?
- 27. 如何從iPhone的應用程序文檔文件夾中將圖像保存在我的設備圖像庫文件夾中?
- 28. 無法將圖像保存在Android應用程序中
- 29. 使用matlab保存文件夾中的圖像序列
- 30. 將VB.net aspx web應用程序中的XML文件保存到文件夾
我假設你是指包應用程序可繪製文件夾。不知道你能做到這一點。您必須使用應用程序緩存存儲或內部/外部存儲文件夾,您可以在其中創建和存儲圖像 – Tasos