提高用Android相机拍摄的照片的质量/清晰度/亮度

时间:2011-08-02 14:06:52

标签: android photo

我有一个Android应用程序,我正在使用安卓摄像头拍摄照片。经过一段时间的构思我设法让我的照片在我想要的地方和我想要的。最后的问题是质量图像。

当我的预览开始时,一切看起来都很清晰,但在拍完照片并显示最终结果后,图像看起来并不好看。

以下是我的surfaceChanged()方法的样子 - 我在哪里设置一些参数:

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Log.e(TAG, "surfaceChanged");
        if (mPreviewRunning) {
            mCamera.stopPreview();
        }

        Camera.Parameters p = mCamera.getParameters();
        List<Size> sizes = p.getSupportedPictureSizes();

 System.out.println("Lista de parametrii este urmatoarea:"+sizes);
       Size   size = sizes.get(7);
      p.setPictureSize(size.width,size.height);
       mCamera.setParameters(p);
        try {
            mCamera.setPreviewDisplay(holder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mCamera.startPreview();
        mPreviewRunning = true;
    }

Coudl有人告诉我提高照片质量的方法。谢谢!

编辑:

在拍摄照片的activity A中,我使用一个包将图像发送到另一个activity B,然后将其存储在SDCARD上。我是这样做的:

Activity A

 Camera.PictureCallback mPictureCallback = new Camera.PictureCallback(){
        public void onPictureTaken(byte[] imageData, Camera c) {

            if (imageData != null) {

                Intent mIntent = new Intent();
                Bundle b = new Bundle();
                b.putByteArray("imageData", imageData);
                Intent i = new Intent(mContext,ImageDisplayActivity.class);
                i.putExtras(b);
                startActivity(i);

                setResult(FOTO_MODE, mIntent);
                finish();

            }
        }
    };
activity B中的

Bundle extras = getIntent().getExtras();
        BitmapFactory.Options options=new BitmapFactory.Options();
        options.inSampleSize = 5;
        byte[] imageData = extras.getByteArray("imageData");
        Bitmap myImage = BitmapFactory.decodeByteArray(imageData , 0, imageData.length,options);

       Matrix mat=new Matrix();
        mat.postRotate(90);
        bitmapResult = Bitmap.createBitmap(myImage, 0, 0,  myImage.getWidth(),myImage.getHeight(), mat, true); 

        Canvas c = new Canvas(bitmapResult);
        drawTextImage(bitmapResult);

我收到了我把它放在位图中的图片,我将其旋转并在方法drawTextImage()中绘制文本。 完成所有这些后,我使用以下内容将bitmapResult存储在sdcard上:

  public static boolean StoreByteImage(Context mContext, Bitmap bitmap, int quality, String expName) {


        FileOutputStream fileOutputStream = null;
        String extStorageDirectory=Environment.getExternalStorageDirectory().toString();
        File myNewFolder = new File(extStorageDirectory + newFolder);
        if(myNewFolder.mkdirs())
        {
        myNewFolder.mkdir();
        }
        try {     

            //fileOutputStream = new FileOutputStream(sdImageMainDirectory.toString() +"/image.jpg");
            fileOutputStream = new FileOutputStream(myNewFolder +"/"+expName+".jpg");
            BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);

            bitmap.compress(CompressFormat.JPEG, quality, bos);

            bos.flush();
            bos.close();

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return true;
    }

我通常称之为:StoreByteImage(getBaseContext(),bitmapResult,100,String.valueOf(value)); 感谢

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题,因为自动对焦被禁用了。

尝试将此权限添加到Android Manifest:

 <uses-feature android:name="android.hardware.camera.autofocus" />
相关问题