当前位置:   article > 正文

Android保存Bitmap图片到指定文件夹_android 将bitmap保存到根目录

android 将bitmap保存到根目录

 

        在内存中先读取到一张图片,格式为Bitmap之后要将其保存到自己游戏安装目录下的某一文件夹中代码如下(函数的参数为

一Bitmap的数据):


  1. public void save(Bitmap bitmap) {
  2. try {
  3. File file = new File(Environment.getExternalStorageDirectory()
  4. + "/Android/data/com.XXX.XXX/files");
  5. if (!file.exists()) {
  6. file.mkdirs();
  7. }
  8. File myFaceFile = new File(
  9. Environment.getExternalStorageDirectory()
  10. + "/Android/data/com.XXX.XXX/files/Name.png");
  11. if (myFaceFile.exists()) {
  12. return;
  13. }
  14. OutputStream stream = new FileOutputStream(myFaceFile);
  15. bitmap.compress(CompressFormat.PNG, 100, stream);
  16. stream.close();
  17. Intent intent = new Intent();
  18. intent.setAction(Intent.ACTION_MEDIA_MOUNTED);
  19. intent.setData(Uri.fromFile(Environment
  20. .getExternalStorageDirectory()));
  21. sendBroadcast(intent);
  22. this.runOnUiThread(new Runnable() {
  23. public void run() {
  24. Toast.makeText(ThisContext, "保存图片成功", Toast.LENGTH_SHORT)
  25. .show();
  26. }
  27. });
  28. UnityPlayer.UnitySendMessage("1PanelOfUserAccount", "ChangeFace",
  29. "Name.png");
  30. } catch (Exception e) {
  31. this.runOnUiThread(new Runnable() {
  32. public void run() {
  33. Toast.makeText(ThisContext, "保存图片失败", Toast.LENGTH_SHORT)
  34. .show();
  35. }
  36. });
  37. e.printStackTrace();
  38. }
  39. try {
  40. File tempFile = null;
  41. tempFile.delete();
  42. } catch (Exception e) {
  43. e.printStackTrace();
  44. }
  45. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/303729
推荐阅读
相关标签
  

闽ICP备14008679号