使用 WEBP_LOSSLSS 的图像压缩有时会增加图像的大小而不是对其进行压缩

问题描述

````````for converting to bitmap
    button.setonClickListener(v -> {
                 BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView3.getDrawable();
                            Bitmap bitmap = bitmapDrawable.getBitmap();
                            saveImage(bitmap);
            

压缩图像并将其保存在文件夹“test”中...

private void saveImage(Bitmap bitmap) {
                    OutputStream fos;
             long currentTime = Calendar.getInstance().getTimeInMillis();
                    String timestamp = DateFormat.getDateTimeInstance().format(currentTime);
            try {
                        if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.Q){
                            ContentResolver resolver = getContentResolver();
                            ContentValues contentValues = new ContentValues();
                            contentValues.put(MediaStore.MediaColumns.disPLAY_NAME,"Image"+timestamp+".jpg");
                            contentValues.put(MediaStore.MediaColumns.MIME_TYPE,"image/jpg");
                            contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH,Environment.DIRECTORY_PICTURES + File.separator + "test");
                            imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);
                            fos = (FileOutputStream) resolver.openOutputStream(Objects.requireNonNull(imageUri));
                            bitmap.compress(Bitmap.CompressFormat.WEBP_LOSSLESS,100,fos);
                            Objects.requireNonNull(fos);
            
                            Toast.makeText(this,"Image saved",Toast.LENGTH_SHORT).show();
                        }
            
            
                    }

 if (resultCode == RESULT_OK && requestCode == PICK_IMAGE && data != null){
        
                    imageUri = data.getData();
                    imageView3.setimageURI(imageUri);
  }
  • 问题
  • 如何解决压缩后图像大小增加的问题?
  • 我可以将图像压缩到特定大小吗,比如说 500kb?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)