当我将布局转换为PNG格式的图像时,尝试使用回收的位图android.graphics。

时间:2018-10-27 22:06:38

标签: java android bitmap android-bitmap

visitingCardDialog.setContentView(R.layout.visitingcardtemplate1);
        Button button = (Button) visitingCardDialog.findViewById(R.id.button2);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RelativeLayout shareLayout = (RelativeLayout) visitingCardDialog.findViewById(R.id.vistingcard);
                shareLayout.setDrawingCacheEnabled(true);
                shareLayout.buildDrawingCache();
                Bitmap bm = shareLayout.getDrawingCache();
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                bm.compress(Bitmap.CompressFormat.PNG, 100, bytes);
                loadImage(bm)

                visitingCardDialog.dismiss();
            }
        });
        visitingCardDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        visitingCardDialog.show();

这是我的加载功能 它在photoeditorview上加载位图 photoeditorview是Photoeditorview类的对象

private void loadImage(Bitmap image) {

    phoroEditorView.getSource().setImageBitmap(image);



}

1 个答案:

答案 0 :(得分:0)

这对我有用!

RelativeLayout shareLayout = (RelativeLayout) visitingCardDialog.findViewById(R.id.vistingcard);
                shareLayout.setDrawingCacheEnabled(true);
                shareLayout.buildDrawingCache();
                Bitmap bm = shareLayout.getDrawingCache();
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                bm.compress(Bitmap.CompressFormat.PNG, 100, bytes);

                try {
                   bm = BitmapFactory.decodeStream(getAssets().open("1024x768.jpg"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                bm.compress(Bitmap.CompressFormat.PNG, 100, out);
                Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));

                //Snapshot.CroppedBitmap= Bitmap.createBitmap(shareLayout.getDrawingCache(true));
                loadImage(decoded);


                visitingCardDialog.dismiss();