简体   繁体   English

从文件创建位图返回空图片

[英]Create bitmap from file return null picture

I wanted to do an app for sharing pictures from the gallery for learning and i want the picture to be renamed so i use a bitmap that retrieve the data of the picture. 我想做一个分享图片库中的图片以供学习的应用程序,并且我想将图片重命名,以便使用位图检索图片数据。 But the thing is the file is always returning null. 但问题是文件始终返回null。 I have a code and i don't know where is the problem. 我有一个代码,我不知道问题出在哪里。

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);

Thank you in advance for the help :) 预先感谢您的帮助:)

我已成功使代码正常工作,我忘记使用FileProvider了,因为我没有外部存储。因此,您必须使用FileProvider才能使用内部存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM