【问题标题】:Image quality has been lost when taken from camera in android app从 Android 应用程序中的相机拍摄时,图像质量已丢失
【发布时间】:2013-11-11 08:58:07
【问题描述】:

我从画廊和相机拍摄图像 当我从相机上传图像时,它会丢失质量 但画廊图像的质量是实际质量

来自相机

来自画廊

这是我从相机和画廊上传图像的代码

从摄像头获取图像

    Intent in = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
 File out = Environment.getExternalStorageDirectory();
 String fileName=GetFileName().replace('.', ' ')+".png";
 out = new File(out, fileName); 
in.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));
 startActivityForResult(in, cameraIdNotSdCard);

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//from camera
    wb.loadUrl(sendUrl);

        if (requestCode == cameraIdNotSdCard) {
            if (data != null && resultCode == RESULT_OK ) {
                bm = (Bitmap) data.getExtras().get("data");

                int width = 350;
                int height = 400;
                if (HomePage.permistionArray.length > 4) {

                    width = Integer.valueOf(HomePage.permistionArray[3]);
                    height = Integer.valueOf(HomePage.permistionArray[4]);
                }

                // Log.d("ddddddddddddd", width+":"+height);

                Bitmap resizeBitmap = Bitmap.createScaledBitmap(bm, width,
                        height, true);

                    ByteArrayOutputStream boas = new ByteArrayOutputStream();
                // bm.compress(Bitmap.CompressFormat.PNG, 100, boas);

                resizeBitmap.compress(Bitmap.CompressFormat.JPEG  ,100, boas);

                byte[] b = boas.toByteArray();
                imageS = Base64.encodeToString(b, 0);

                // call custom class which class web service in background which
                // save image ..
                new imageSaveClass(getApplicationContext()).execute();

            }
        }
        // form gallery result
           if (requestCode == galleryRsultCode && resultCode == RESULT_OK
                    && data != null) {

            Uri selectedImage = data.getData();


            String[] filePathColum = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColum, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColum[0]);

            String picturePath = cursor.getString(columnIndex);

            Bitmap myBitmap = BitmapFactory
                    .decodeFile(picturePath);
            if(myBitmap!=null)
            {
                int width = 350;
                int height = 400;
                if (HomePage.permistionArray.length > 4) {

                    width = Integer.valueOf(HomePage.permistionArray[3]);
                    height = Integer.valueOf(HomePage.permistionArray[4]);
                } 

                // Log.d("ddddddddddddd", width+":"+height);

                Bitmap resizeBitmap = Bitmap.createScaledBitmap(myBitmap, width,
                        height, true);

                ByteArrayOutputStream boas = new ByteArrayOutputStream();
                // bm.compress(Bitmap.CompressFormat.PNG, 100, boas);

                resizeBitmap.compress(Bitmap.CompressFormat.PNG, 100, boas);

                byte[] b = boas.toByteArray();
                imageS = Base64.encodeToString(b, 0);

                // call custom class which class web service in background which
                // save image ..
                new imageSaveClass(getApplicationContext()).execute();
            }

        }

我从画廊和相机拍摄图像 当我从相机上传图像时,它会丢失质量 但画廊图像的质量是实际质量

如何提高相机的质量

【问题讨论】:

  • 在 onActivityResult 中,您正在获取用于缩略图目的的图像,它不是实际图像。 stackoverflow.com/questions/10779789/…
  • 我使用此代码从 cam Intent 获取图像 in = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);文件输出 = Environment.getExternalStorageDirectory();字符串文件名=GetFileName().replace('.', '')+".png";输出 = 新文件(输出,文件名); in.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out)); startActivityForResult(in, cameraIdNotSdCard);

标签: android image


【解决方案1】:

尝试更改压缩格式。

您正在使用相机:

 resizeBitmap.compress(Bitmap.CompressFormat.JPEG  ,100, boas);

对于画廊:

 resizeBitmap.compress(Bitmap.CompressFormat.PNG ,100, boas);

另请阅读this

【讨论】:

  • 你找到解决办法了吗?
猜你喜欢
  • 2016-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-15
  • 2011-07-31
  • 1970-01-01
  • 1970-01-01
  • 2017-07-14
相关资源
最近更新 更多