user3317993
user3317993

Reputation: 111

How will I set the BitmapDrawable into the ImageView?

The tapimageview is the ImageView that I want to show the mBitmapDrawable once I click the save image. Am I doing the right thing?

    save.setOnClickListener(new View.OnClickListener() {
        @SuppressWarnings("deprecation")
        public void onClick(View v) {
            Log.v(TAG, "Save Tab Clicked");
            viewBitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);//i is imageview whch u want to convert in bitmap
            canvas = new Canvas(viewBitmap);
            tapimageview.draw(canvas);
            canvas.drawBitmap(bmp, 0, 0, paint);
            canvas.drawBitmap(drawingBitmap, matrix, paint);
            canvas.drawBitmap(bmpstickers, matrix, paint);
            try {
                mBitmapDrawable = new BitmapDrawable(viewBitmap);
                tapimageview.setImageMatrix(mBitmapDrawable);
                mCurrent = "PXD_" + new SimpleDateFormat("yyyyMMdd_HHmmss",
                Locale.getDefault()).format(new Date()) + ".jpg";

                mNewSaving = ((BitmapDrawable) mBitmapDrawable).getBitmap();
                String FtoSave = mTempDir + mCurrent;
                File mFile = new File(FtoSave);
                mFileOutputStream = new FileOutputStream(mFile);
                mNewSaving.compress(CompressFormat.JPEG, 100, mFileOutputStream);
                mFileOutputStream.flush();
                mFileOutputStream.close();
            }
            catch (FileNotFoundException e) {
                Log.v(TAG, "FileNotFoundExceptionError " + e.toString());
            }
            catch (IOException e) {
                Log.v(TAG, "IOExceptionError " + e.toString());
            }
        }
    });
}

Upvotes: 2

Views: 103

Answers (1)

donfuxx
donfuxx

Reputation: 11321

Is that maybe what you were looking for?

tapimageview.setImageBitmap(mBitmapDrawable.getBitmap());   

Upvotes: 2

Related Questions