【问题标题】:Image Saved is too small why?保存的图像太小为什么?
【发布时间】:2018-09-17 17:56:07
【问题描述】:

我想用相机拍照并保存到图片文件夹中...唯一无法解决的是为什么我的图像保存为小尺寸...

Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, TAKE_PICTURE);

protected void onActivityResult(int requestCode, int resultCode, Intent imageReturned) {
    super.onActivityResult(requestCode, resultCode, imageReturned);

    switch(requestCode) {
        case TAKE_PICTURE:
            if(resultCode == RESULT_OK)
            { 
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                photo.compress(Bitmap.CompressFormat.PNG, 100, bytes);                  

                File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+ File.separator + "test3.png");
                try {
                    f.createNewFile();
                    //write the bytes in file
                     FileOutputStream fo = new FileOutputStream(f);
                     fo.write(bytes.toByteArray());
                     fo.flush();
                     // remember close de FileOutput
                     fo.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }    
            }
    }
}

【问题讨论】:

标签: android image


【解决方案1】:

您应该考虑阅读文档:

http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE

它总是给你一个较小的图像,除非你将它设置为给你全尺寸:

直接来自开发站点

调用者可能会传递一个额外的 EXTRA_OUTPUT 来控制此图像的位置 将被写入。如果 EXTRA_OUTPUT 不存在,那么一个小的 大小的图像作为额外字段中的位图对象返回。这是 对于只需要小图像的应用程序很有用。如果 EXTRA_OUTPUT 存在,则全尺寸图像将被写入 EXTRA_OUTPUT 的 Uri 值。

【讨论】:

    猜你喜欢
    • 2018-12-05
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 2021-01-21
    相关资源
    最近更新 更多