我正在将包含 ImageView 和 EditText 的布局保存为位图。
我正在使用以下代码:
public void saveToImage(RelativeLayout content){
Bitmap bitmap = Bitmap.createBitmap(content.getWidth(), content.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
content.layout(0, 0, content.getLayoutParams().width, content.getLayoutParams().height);
content.draw(c);
try{
File file,f = null;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
{
file =new File(android.os.Environment.getExternalStorageDirectory(),"TTImages_cache");
if(!file.exists())
{
file.mkdirs();
}
f = new File(file.getAbsolutePath()+file.separator+ "filename"+".png");
}
FileOutputStream ostream = new FileOutputStream(f);
bitmap.compress(CompressFormat.PNG, 10, ostream);
ostream.close();
}
catch (Exception e){
e.printStackTrace();
}
}
然而,我保存的图像看起来是这样的: