使用getDrawingCache提高图像质量 - android [英] Improve image quality while using getDrawingCache - android

查看:1616
本文介绍了使用getDrawingCache提高图像质量 - android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 getDrawingCache()方法捕获我的布局视图并从中创建图像。
代码工作正常,图像生成,但问题是,生成的图像质量非常低。我希望生成的图像的分辨率高,这样每当我将它设置为 ImageView 时,它就不会被拉伸。

I am capturing my layout view using getDrawingCache() method and creating image from it. The code works fine and image gets generated, but the problem here is, the generated image quality is very low. I want the resolution of generated image to be high so that whenever i set it to ImageView it don't get stretched.

以下是我正在使用的代码:

RelativeLayout layout =(RelativeLayout)findViewById(R。 id.layout);
layout.setDrawingCacheEnabled(true);
位图bmp = layout.getDrawingCache();
文件f =新文件(Environment.getExternalStorageDirectory()。getAbsolutePath()+ System.currentTimeMillis()+。jpg);
try {
FileOutputStream out = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.JPEG,100,out);
out.flush();
out.close();
} catch(IOException e){
e.printStackTrace();
}

P.S。 - 我也尝试使用 layout.buildDrawingCache(true); layout.setDrawingCacheQuality(RelativeLayout.DRAWING_CACHE_QUALITY_HIGH); 在调用 layout.getDrawingCache(); 之前,但没有找到质量变化。

P.S. - I also tried using layout.buildDrawingCache(true); and layout.setDrawingCacheQuality(RelativeLayout.DRAWING_CACHE_QUALITY_HIGH); before calling layout.getDrawingCache(); but no changes in quality were found.

任何人都可以请帮助关于这一点,我怎样才能提高生成图像的质量?
提前致谢。

Can anyone please help me out on this, how can I improve quality of the image being generated? Thanks in advance.

推荐答案

在搜索了很长时间并尝试了不同的解决方案之后,最后我得到了捕获的图像质量比以前好。

After Searching for very long and trying out different solutions, Finally I got the captured Image quality better than it was earlier.

我将代码更改为:

RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
layout.setDrawingCacheEnabled(true);
layout.buildDrawingCache(true);
final Bitmap bmp = Bitmap.createBitmap(layout.getDrawingCache());
layout.setDrawingCacheEnabled(false);
Canvas c= new Canvas(bmp);


File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/" + System.currentTimeMillis()+".jpg");
try {

    FileOutputStream out = new FileOutputStream(f);
    c.drawBitmap(bmp, 0, 0, null);
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);

    out.flush();
    out.close();
} catch (IOException e) {
    e.printStackTrace();
}

这对我有帮助。希望它也能帮助别人。

This is what helped me. Hope it'll help others too.

这篇关于使用getDrawingCache提高图像质量 - android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆