如何将整个画布另存为android画布中的jpeg图像?

尼丁·萨科(Nitin Thakor)

我已经在画布上绘制了一些东西,我想将此图另存为jpeg图像在我的存储中。遵循以下方法,我将其保存在目录中,但未保存空白黑色图像,其大小为14.49kb。

这是该方法

public Bitmap savebit(){

        Bitmap  saveBitmap = Bitmap.createBitmap(this.getWidth(), this.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(saveBitmap);
        canvas.setBitmap(saveBitmap);
        this.draw(canvas);

        File file = new File(Environment.getExternalStorageDirectory() + "/sign.jpg");

        try {
            saveBitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(file));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return saveBitmap;
    }
索海尔·扎希德(Sohail Zahid)

您的班级abcView会在布局中的某些位置使用,您可以轻松地进行屏幕截图。

Abc abc;

Bitmap bmp = viewToBitmap(abc);
Bitmap bmp = viewToBitmap(frameLayout);
Bitmap bmp = viewToBitmap(LinearLayout);
Bitmap bmp = viewToBitmap(AnyView);

public Bitmap viewToBitmap(View view) {
        Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        view.draw(canvas);
        return bitmap;
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章