如何保存图像的android库 [英] How save image in android gallery
本文介绍了如何保存图像的android库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试保存imagen画质到WathsappIMG但是当我去到图片库的android我没有看到的图像与图像那里进入目录,我可以从ES看到文件浏览器
的OutputStream输出;
//找到SD卡路径
文件的文件路径= Environment.getExternalStorageDirectory();
//创建在SD卡一个新的文件夹
文件DIR =新的文件(filepath.getAbsolutePath()
+/ WhatSappIMG /);
dir.mkdirs();
//检索从资源文件夹中的图像
BitmapDrawable绘制=(BitmapDrawable)principal.getDrawable();
位图bitmap1 = drawable.getBitmap();
//用于保存的图像创建一个名称
档案文件=新的文件(目录,Wallpaper.jpg);
尝试 {
输出=新的FileOutputStream(文件);
//的COM preSS为0%PNG格式的图片 - 100%
bitmap1.com preSS(Bitmap.Com pressFormat.JPEG,100,输出);
output.flush();
output.close();
}
赶上(例外五){
// TODO自动生成的catch块
e.printStackTrace();
}
解决方案
的库不显示(不一定)从外部存储器中的文件。
这是一个常见的错误。
存储在媒体存储提供画廊显示图像
您可以使用此方法来存储介质存储提供的图像文件:
公共静态无效addImageToGallery(最后字符串文件路径,最终的上下文语境){
ContentValues值=新ContentValues();
values.put(Images.Media.DATE_TAKEN,System.currentTimeMillis的());
values.put(Images.Media.MIME_TYPE,为image / jpeg);
values.put(MediaStore.MediaColumns.DATA,文件路径);
。context.getContentResolver()插入(Images.Media.EXTERNAL_CONTENT_URI,价值观);
}
I try save the imagen into WathsappIMG but when I go to image gallery android I don't see the image and the image there into the directory I can see from ES File Explorer
OutputStream output;
// Find the SD Card path
File filepath = Environment.getExternalStorageDirectory();
// Create a new folder in SD Card
File dir = new File(filepath.getAbsolutePath()
+ "/WhatSappIMG/");
dir.mkdirs();
// Retrieve the image from the res folder
BitmapDrawable drawable = (BitmapDrawable) principal.getDrawable();
Bitmap bitmap1 = drawable.getBitmap();
// Create a name for the saved image
File file = new File(dir, "Wallpaper.jpg" );
try {
output = new FileOutputStream(file);
// Compress into png format image from 0% - 100%
bitmap1.compress(Bitmap.CompressFormat.JPEG, 100, output);
output.flush();
output.close();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
解决方案
the gallery don't displaying (necessarily) files from external storage.
this is a common mistake.
the gallery displays images stored on the media store provider
you can use this method to store image file on media store provider:
public static void addImageToGallery(final String filePath, final Context context) {
ContentValues values = new ContentValues();
values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.MediaColumns.DATA, filePath);
context.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
}
这篇关于如何保存图像的android库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文