我正在创建一个应用程序,用于将一个图像视图放在另一个图像视图上,并将其制作为单个图像并保存到 SD 卡中。我运行它创建图像并保存到 SD 卡的应用程序,但该图像是空白的。两张图片都没有显示在一张保存在 SD 卡中的图片上。
这是我的代码。
@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView image2 = (ImageView) findViewById(R.id.ImageViewTwo);
final ImageView image = (ImageView) findViewById(R.id.ImageViewOne);
mTempDir = Environment.getExternalStorageDirectory()+"/"+"TestTemp";
File mtempFile = new File(mTempDir);
if(!mtempFile.exists())
{
mtempFile.mkdir();
}
mSaveImageName = "Test.png";
mBackGround = Bitmap.createBitmap(100 , 100 ,Bitmap.Config.ARGB_8888);
image2.buildDrawingCache();
mBackImage = image2.getDrawingCache();
mBackImage = Bitmap.createBitmap(100 , 100 ,Bitmap.Config.ARGB_8888);
image.buildDrawingCache();
mTopImage = image.getDrawingCache();
mTopImage = Bitmap.createBitmap(100 , 100 , Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBackGround);
//mCanvas.drawBitmap(mBackImage, (mCanvas.getWidth() / 2), 0, null);
mCanvas.drawBitmap(mBackImage ,0f , 0f , null);
mCanvas.drawBitmap(mTopImage, 12f , 12f , null);
try
{
mBitmapDrawable = new BitmapDrawable(mBackGround);
Bitmap mNewSaving = mBitmapDrawable .getBitmap();
String ftoSave = mTempDir + mSaveImageName;
File mFile = new File(ftoSave);
mFileOutputStream = new FileOutputStream(mFile);
mNewSaving.compress(CompressFormat.PNG, 95 , mFileOutputStream);
mFileOutputStream.flush();
mFileOutputStream.close();
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i(TAG, "Image Created");
}