0

我在 Android 活动中有一个布局,我将其转换为图像,然后在不同的社交网络上分享。问题是质量根本不好,图像上有伪影,质量取决于屏幕的大小。

有什么办法可以提高质量吗?我无法将完整的布局图像作为静态图像存储在应用程序目录中,我需要在旅途中生成它。

这是我用来将布局转换为 PNG 的代码。

Bitmap bitmap = null;   
        try {
            bitmap = Bitmap.createBitmap(dashboardView.getWidth(),
                    dashboardView.getHeight(), Bitmap.Config.ARGB_4444);
            dashboardView.draw(new Canvas(bitmap));
        } catch (Exception e) {
            // Logger.e(e.toString());
        }

        FileOutputStream fileOutputStream = null;
        File path = Environment
                .getExternalStorageDirectory();
        File file = new File(path, "wayzupDashboard" + ".png");
        try {
            fileOutputStream = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
        bitmap.compress(CompressFormat.PNG, 100, bos);
        try {
            bos.flush();
            bos.close();
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

编辑:我的错,我离开了 ARGB_4444,事实上我在 SO 上发布问题之前做了很多测试,我只是忘了把 ARGB_8888 放进去。在小屏幕的 Android 手机上图像质量仍然很差。如果我能告诉在捕获布局时始终使用 HDPI drawable 就好了。

4

2 回答 2

1

ARGB_4444 means that you have only 4 bits per channel (a really poor quality).

Use ARGB_8888.

于 2013-01-10T10:22:06.647 回答
0

you are using Bitmap.Config.ARGB_4444. I suggest you to use ARGB_8888, like Google tells us

ARGB_4444 This field was deprecated in API level . Because of the poor quality of this configuration, it is advised to use ARGB_8888 instead.

于 2013-01-10T10:21:17.960 回答