【问题标题】:Create bitmap from file return null picture从文件返回空图片创建位图
【发布时间】:2019-06-26 07:06:38
【问题描述】:

我想做一个应用程序来共享图库中的图片以供学习,并且我希望将图片重命名,因此我使用位图来检索图片的数据。但问题是文件总是返回空值。 我有一个代码,但我不知道问题出在哪里。

File file = new File(this.getFilesDir().getAbsolutePath(), "logo");
if (!file.exists()) {
    file.mkdirs();
}
File iconf = new File(file, "icon_launcher.png");
iconf.createNewFile();
OutputStream ios = new FileOutputStream(iconf);

example.compress(Bitmap.CompressFormat.PNG, 80, ios);
ios.flush();
ios.close();


//String uricon=       MediaStore.Images.Media.insertImage(getContentResolver(),iconf.getAbsolutePath(),"icon_launcher.png","drawing");

Uri iconurl = Uri.parse(iconf.getAbsolutePath());

Intent email = new Intent(Intent.ACTION_SEND);
email.setType("image/png");

email.putExtra(Intent.EXTRA_STREAM, iconurl);

startActivityForResult(Intent.createChooser(email, "Envoyer par mail"), 1);

提前感谢您的帮助:)

【问题讨论】:

    标签: java android image file bitmap


    【解决方案1】:

    我已成功使代码工作,我忘记使用 FileProvider 因为我没有外部存储。所以你必须使用 FileProvider 来使用内部存储。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      相关资源
      最近更新 更多