0

I'm creating an application for placing one image view on the another image view and made to single image and save into SD card. I run the application it creates image and save to SD card but this image is blank. Both images are not showing on one single image which is save in the SD card.

Here is my code.

@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");



        }
halfer
  • 19,824
  • 17
  • 99
  • 186
tazeenmulani
  • 600
  • 5
  • 18
  • 43

1 Answers1

0

You have a few excess lines:

image2.buildDrawingCache();
mBackImage  = image2.getDrawingCache();
// delete next line
mBackImage  = Bitmap.createBitmap(100 , 100 ,Bitmap.Config.ARGB_8888);

image.buildDrawingCache();
mTopImage = image.getDrawingCache();
// delete next line
mTopImage = Bitmap.createBitmap(100 , 100 , Bitmap.Config.ARGB_8888);
liquid_code
  • 577
  • 7
  • 12
  • Delete this two lines after '// delete next line' comment. You lose the bitmap when create a new one. – liquid_code Jun 20 '13 at 13:25
  • But when i delete this two lines it shows error on this two line fatal exception and NullPointerException : (mCanvas.drawBitmap(mBackImage ,0f , 0f , null); mCanvas.drawBitmap(mTopImage, 12f , 12f , null);) – tazeenmulani Jun 20 '13 at 13:31
  • So, I imagine, your image2 and image objects do not contain an image. Print mBackImage after 'image2.getDrawingCache();' line. If it's null, then your problem in ImageView's content. – liquid_code Jun 20 '13 at 13:40
  • Image is present in image2 and image but is not getting in ( mCanvas = new Canvas(mBackGround); mBitmapDrawable = new BitmapDrawable(mBackGround); ) I have already set the images in object of image view but i don't understand where is the problem ? – tazeenmulani Jun 20 '13 at 13:48
  • Make sure image2.getDrawingCache(); returns not null. If it returns null then try to get bitmap from ImageView with different manner: mBackImage = ((BitmapDrawable) image2.getDrawable()).getBitmap(); – liquid_code Jun 20 '13 at 14:00
  • Thank you so much your idea is very help full for solving the problem. – tazeenmulani Jun 21 '13 at 05:47
  • But my created single image(imag2 + image = mBackGround ) is showing only half image not display proper full image = (mBitmapDrawable = new BitmapDrawable(mBackGround);). – tazeenmulani Jun 21 '13 at 05:51