android - 如何将 BitmapDrawable 设置到 ImageView 中?

标签 android image imageview save

tapimageview 是我想在单击保存图像后显示 mBitmapDrawableImageView。我做的对吗?

    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());
            }
        }
    });
}

最佳答案

这可能是您正在寻找的东西吗?

tapimageview.setImageBitmap(mBitmapDrawable.getBitmap());   

关于android - 如何将 BitmapDrawable 设置到 ImageView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21916565/

相关文章:

android - 无法取消选中动态单选组中已选中的单选按钮

wpf - 单元测试 - 在测试项目中使用图像作为资源

image - 如何使用 Microsoft Access 显示来自 Sql Server 的图像?

android - Framelayout onclick 内的 ImageView 仅在第二次单击时触发

android - 运行使用@string 作为主机名的 Instant App 时为 "URL not defined in the manifest"

java - ExpandableListView Android 中的多个 Textview

android获取picasa图片网址

image - "JPG"/"JPEG"/"PNG"/"BMP"/"GIF"/"TIFF"图像有什么区别?

Android ImageView布局对齐

android - ImageView 适合宽度裁剪​​底部