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

前端之家收集整理的这篇文章主要介绍了提高用Android相机拍摄的照片的质量/清晰度/亮度前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 Android应用程序,我正在使用Android相机拍照.然后在一点点后,我设法让我的照片在我想要的地方和我想要的.最后的问题是图像的质量.

当我的预览开始时,一切都看起来非常清晰和伟大,但在拍摄照片并显示最终结果后,图像看起来并不好看.

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

  1. public void surfaceChanged(SurfaceHolder holder,int format,int w,int h) {
  2. Log.e(TAG,"surfaceChanged");
  3. if (mPreviewRunning) {
  4. mCamera.stopPreview();
  5. }
  6.  
  7. Camera.Parameters p = mCamera.getParameters();
  8. List<Size> sizes = p.getSupportedPictureSizes();
  9.  
  10. System.out.println("Lista de parametrii este urmatoarea:"+sizes);
  11. Size size = sizes.get(7);
  12. p.setPictureSize(size.width,size.height);
  13. mCamera.setParameters(p);
  14. try {
  15. mCamera.setPreviewDisplay(holder);
  16. } catch (IOException e) {
  17. // TODO Auto-generated catch block
  18. e.printStackTrace();
  19. }
  20. mCamera.startPreview();
  21. mPreviewRunning = true;
  22. }

Coudl有人告诉我提高照片质量的方法是什么.谢谢!

编辑:

在拍摄照片的活动A中,我使用一个包将图像发送到另一个活动B,我将其存储在SDCARD上.这就是我的工作方式:

活动A:

  1. Camera.PictureCallback mPictureCallback = new Camera.PictureCallback(){
  2. public void onPictureTaken(byte[] imageData,Camera c) {
  3.  
  4. if (imageData != null) {
  5.  
  6. Intent mIntent = new Intent();
  7. Bundle b = new Bundle();
  8. b.putByteArray("imageData",imageData);
  9. Intent i = new Intent(mContext,ImageDisplayActivity.class);
  10. i.putExtras(b);
  11. startActivity(i);
  12.  
  13. setResult(FOTO_MODE,mIntent);
  14. finish();
  15.  
  16. }
  17. }
  18. };

在活动B中:

  1. Bundle extras = getIntent().getExtras();
  2. BitmapFactory.Options options=new BitmapFactory.Options();
  3. options.inSampleSize = 5;
  4. byte[] imageData = extras.getByteArray("imageData");
  5. Bitmap myImage = BitmapFactory.decodeByteArray(imageData,imageData.length,options);
  6.  
  7. Matrix mat=new Matrix();
  8. mat.postRotate(90);
  9. bitmapResult = Bitmap.createBitmap(myImage,myImage.getWidth(),myImage.getHeight(),mat,true);
  10.  
  11. Canvas c = new Canvas(bitmapResult);
  12. drawTextImage(bitmapResult);

我收到我把它放在一个位图中的图片,我旋转它并在方法drawTextImage()中绘制一个文本.
毕竟,我使用以下方法将bitmapResult存储在SD卡上:

  1. public static boolean StoreByteImage(Context mContext,Bitmap bitmap,int quality,String expName) {
  2.  
  3.  
  4. FileOutputStream fileOutputStream = null;
  5. String extStorageDirectory=Environment.getExternalStorageDirectory().toString();
  6. File myNewFolder = new File(extStorageDirectory + newFolder);
  7. if(myNewFolder.mkdirs())
  8. {
  9. myNewFolder.mkdir();
  10. }
  11. try {
  12.  
  13. //fileOutputStream = new FileOutputStream(sdImageMainDirectory.toString() +"/image.jpg");
  14. fileOutputStream = new FileOutputStream(myNewFolder +"/"+expName+".jpg");
  15. BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
  16.  
  17. bitmap.compress(CompressFormat.JPEG,quality,bos);
  18.  
  19. bos.flush();
  20. bos.close();
  21.  
  22. } catch (FileNotFoundException e) {
  23. // TODO Auto-generated catch block
  24. e.printStackTrace();
  25. } catch (IOException e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. }
  29.  
  30. return true;
  31. }

我这样称它为:StoreByteImage(getBaseContext(),bitmapResult,100,String.valueOf(value));
谢谢

解决方法

我有这个问题因为禁用了自动对焦.

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

  1. <uses-feature android:name="android.hardware.camera.autofocus" />

猜你在找的Android相关文章