简体   繁体   English

发送后位图质量不好(Android / Java)

[英]Bitmap quality bad after sending (Android/Java)

I'm getting a Bitmap with: 我正在使用以下位图:

View v1 = (View) wpm.getParent().getParent();

        Bitmap cs = null;
        v1.setDrawingCacheEnabled(true);
        v1.buildDrawingCache(true);
        cs = Bitmap.createBitmap(v1.getDrawingCache(true));
        Canvas canvas = new Canvas(cs);
        v1.draw(canvas);
        canvas.save();
        v1.setDrawingCacheEnabled(false);

        String path = Images.Media.insertImage(getContext().getContentResolver(), cs, "MyImage", null);
        Uri file = Uri.parse(path);

        OutputStream outStream = null;
        try {
            outStream = getContext().getContentResolver().openOutputStream(file);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        cs.compress(Bitmap.CompressFormat.JPEG, 100, outStream);

        //file senden
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.putExtra(Intent.EXTRA_STREAM, file);
        sharingIntent.setType("image/jpeg");
        getContext().startActivity(Intent.createChooser(sharingIntent,"Erfolg teilen!"));

When I send it via Facebook, Whatsapp,... the Quality is very bad. 当我通过Facebook,Whatsapp发送邮件时,...质量很差。 But if I copy it to my PC it looks normally and before I send it via Facebook I can check how it will look and there it looks normally too. 但是,如果我将其复制到PC上,它看起来正常,那么在通过Facebook发送之前,我可以检查它的外观以及那里的外观。 Only after sending it it looks bad. 仅在发送后看起来很糟糕。 How can I change this? 我该如何更改?

Try to set: 尝试设置:

yourView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

If your starting bitmap have a bad quality, you can't make it better with bitmap.compress. 如果您的起始位有品质不好,你不能使它与bitmap.compress更好。

REMEMBER that better quality need more memory. 请记住 ,更好的质量需要更多的内存。

The problem comes from the following line: 问题来自以下行:

cs.compress(Bitmap.CompressFormat.JPEG, 100, outStream);

The quality 100 is too high, and the size of generated jpg file is too large to be accepted by Facebook. 质量100太高,并生成JPG文件的大小过大,无法通过Facebook的被接受。 So Facebook compresses this image and reduces its quality. 因此,Facebook的这个压缩图像,并减少其质量。 Use the following code may solve your problem: 使用以下代码可以解决您的问题:

cs.compress(Bitmap.CompressFormat.JPEG, 70, outStream);

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

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