简体   繁体   English

以高分辨率保存画布图像

[英]Saving Canvas Image at high resolution

I am creating an android app where an user can draw, add text or image on to the canvas. 我正在创建一个Android应用程序,用户可以在画布上绘制,添加文本或图像。 After the user has finished editing on th canvas there is an option for saving. 用户在画布上完成编辑后,有一个保存选项。 When I try to save that as an image, the resulting output image is of very low resolution. 当我尝试将其保存为图像时,生成的输出图像的分辨率非常低。

            canvas.setDrawingCacheEnabled(true);                
            canvas.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
            Bitmap bitmap = canvas.getDrawingCache();
            String path = Environment.getExternalStorageDirectory().getAbsolutePath();
            File file = new File(path+"/image.jpg");
            FileOutputStream ostream;
            try {
                file.createNewFigle();
                ostream = new FileOutputStream(file);
                bitmap.compress(CompressFormat.JPEG, 100, ostream);
                ostream.flush();
                ostream.close();
                Toast.makeText(getApplicationContext(), "image saved", 5000).show();
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), "error", 5000).show();
            }

I want the image to be saved as A3 300dpi. 我希望图像保存为A3 300dpi。 Is there any possible way? 有什么办法吗?

尝试将文本,图像和所有绘图保存为对象,当用户单击保存按钮时,创建一个具有所需分辨率的新位图,并将当前画布转换为所需的位图

I think this is because of using bitmap.compress(CompressFormat.JPEG, 100, ostream); 我认为这是因为使用了bitmap.compress(CompressFormat.JPEG,100,ostream); use PNG instread of JPEG Hope you be ok 使用JPEG的PNG instread希望你没事

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM