CMA*_*CMA 1 android android-canvas
我正在开发一个Android应用程序,我可以在画布上绘制.我想将我的画布转换为位图,然后将其以jpeg格式保存在我的SD卡上.
我怎么能正确地做到这一点?
这样的东西应该工作:
http://developer.android.com/reference/android/view/View.html#getDrawingCache(boolean)
public void toJPEGFile(){
File folder = new File(Environment.getExternalStorageDirectory()+"/folder/");
if(!folder.exists()) folder.mkdirs();
try {
this.setDrawingCacheEnabled(true);
FileOutputStream fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory()+"/folder/file"));
Bitmap bitmap = this.getDrawingCache();
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5401 次 |
| 最近记录: |