无法将合并的图像保存在正确的位置

时间:2013-11-18 10:31:40

标签: android image bitmap

我是android的新手。第一次使用这段代码。  我正在保存三个图像,两个图像很小,一个很大。我正在尝试调整大的小位置并将该图像合并为一个,但是当我点击完成按钮时,它不能正确保存在我为小图像选择的位置上。我正在移动小图像n大图像并尝试将图像保存在我停止的位置。制作像app这样的照片编辑器。

我的代码是:     对于“保存”按钮

case R.id.bdone:
mTempDir = Environment.getExternalStorageDirectory()+"/";//location
File mtempFile = new File(mTempDir);
if(!mtempFile.exists())
{
    mtempFile.mkdir();
}
mSaveImageName = "Test.jpg";//name of image to be merged

//myImage.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
//myImage.layout(0, 0, myImage.getMeasuredWidth(), myImage.getMeasuredHeight());

myImage.buildDrawingCache();
myBitmap  =  myImage.getDrawingCache();
myImage1.buildDrawingCache();
myBitmap1 = myImage1.getDrawingCache();
myImage2.buildDrawingCache();
myBitmap2 = myImage2.getDrawingCache();
Bitmap mBackground = Bitmap.createBitmap(myBitmap.getWidth(),myBitmap.getHeight(),myBitmap.getConfig());
myImage.setImageBitmap(mBackground);//Main bitmap
mCanvas = new Canvas(mBackground);
mCanvas.drawBitmap(myBitmap ,new Matrix(), null);
mCanvas.drawBitmap(myBitmap1,x-dx,y-dy, null);
mCanvas.drawBitmap(myBitmap2,x-dx,y-dx, null);
try
{
    mBitmapDrawable = new BitmapDrawable(mBackground);
    Bitmap mNewSaving = mBitmapDrawable .getBitmap();
    String ftoSave = mTempDir + mSaveImageName;
    File mFile = new File(ftoSave);
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    FileOutputStream out = new FileOutputStream(mFile);
    mNewSaving.compress(CompressFormat.JPEG,100, out);
    Toast.makeText(getApplicationContext(), "Image Saved",Toast.LENGTH_SHORT).show();
    out.flush();
    out.close();
}
catch(FileNotFoundException  e)
{
    e.printStackTrace();
} 
catch (IOException e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}
break;

请尽快回答我的问题。

0 个答案:

没有答案