java - 拍照并保存到 SD 而不会降低质量

标签 java android camera compression photo

我有一个可以拍照并将其存储到 SD 卡的应用程序,但是我拍摄的每张照片都经过了极度压缩,质量非常低。我以完整质量压缩它,所以我不确定为什么要这样做。有什么建议么?这是代码:

protected void takePhoto()
{
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent, 0); 
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    currPhoto = (ImageView) findViewById(R.id.imageView1);

    if (requestCode== 0 && resultCode == Activity.RESULT_OK){
        Bitmap x = (Bitmap) data.getExtras().get("data");
        currPhoto.setImageBitmap(x);
        ContentValues values = new ContentValues();
        values.put(Images.Media.MIME_TYPE, "image/jpeg");
        Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
        OutputStream outstream;
        try {
            outstream = getContentResolver().openOutputStream(uri);

        x.compress(Bitmap.CompressFormat.JPEG, 90, outstream);
        outstream.close();
        } catch (FileNotFoundException e) {
            //
        }catch (IOException e){
            //
        }
    }
}

编辑:事实上它似乎只将缩略图保存到 SD。

example

最佳答案

来自documentation :

public static final String ACTION_IMAGE_CAPTURE

Added in API level 3 Standard Intent action that can be sent to have the camera application capture an image and return it.

The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.

关于java - 拍照并保存到 SD 而不会降低质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15857777/

相关文章:

java - 为什么 String.getBytes() 在编译后的 jar 中表现不同?

java - 在 Java Web 应用程序中使用属性文件连接到数据库

java - Apache Tiles - 无法访问 Spring MVC 中自定义 ViewPreparer 中的 bean

android - 使用openCV库时necessitas中的错误

java - Java 的 SQL 解析器库 - 检索 SQL 语句中存在的表名列表

android - 如何解决警告 : You are installing software that contain unsigned content and authenticity and validity of this software can not established

java - 调用另一个类中的方法将对象转换为该类

android - 如何在 VR 模式下显示相机 View ?

android - 如何使用phonegap-2.9.0相机并存储在Android设备中?

Android 相机照片预览即将倒转