android通过bitmap生成新图片关键性代码


1、关键性代码
复制代码 代码如下:

//R.drawable.test为当前工程里的一张图片
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.test);
FileOutputStream fos = null;
try
{
File file = new File("/mnt/sdcard/testfile");
if (!file.exists())
{
file.mkdir();
}
fos = new FileOutputStream("/mnt/sdcard/testfile/test.jpg");
// Bitmap.CompressFormat.PNG
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} catch (FileNotFoundException e)
{
e.printStackTrace();
}

2、权限
复制代码 代码如下:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />

附:最近写的一个小程序,是关于图片缩放的,缩放完成后可以在本地生成新的图片,这个只能在资源里下载了
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3