【发布时间】:2015-01-26 14:52:05
【问题描述】:
我使用自定义形状创建了图像视图 siyamed/android-shape-imageview 现在我想用形状将图像保存在 SD 卡上。 我怎样才能做到这一点?
【问题讨论】:
我使用自定义形状创建了图像视图 siyamed/android-shape-imageview 现在我想用形状将图像保存在 SD 卡上。 我怎样才能做到这一点?
【问题讨论】:
由于自定义视图只是一个 ImageView,因此请尝试在单击事件的按钮上添加类似的内容,以将图像保存为位图;
ImageView imageViewCustom = (ImageView) findViewById(R.id.image_view_to_save);
try {
imageViewCustom.setDrawingCacheEnabled(true);
FileOutputStream fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory()+"/ACustomShapeFolder/file1234.jpg"));
Bitmap bitmap = imageViewCustom.getDrawingCache();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Toast.makeText(this, "Error occured", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(this, "Error occured", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
希望这会有所帮助!
【讨论】: