我有一个
Android应用程序,我正在使用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有人告诉我提高照片质量的方法是什么.谢谢!
编辑:
在拍摄照片的活动A中,我使用一个包将图像发送到另一个活动B,我将其存储在SDCARD上.这就是我的工作方式:
活动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();
- }
- }
- };
在活动B中:
- Bundle extras = getIntent().getExtras();
- BitmapFactory.Options options=new BitmapFactory.Options();
- options.inSampleSize = 5;
- byte[] imageData = extras.getByteArray("imageData");
- Bitmap myImage = BitmapFactory.decodeByteArray(imageData,imageData.length,options);
- Matrix mat=new Matrix();
- mat.postRotate(90);
- bitmapResult = Bitmap.createBitmap(myImage,myImage.getWidth(),myImage.getHeight(),mat,true);
- Canvas c = new Canvas(bitmapResult);
- drawTextImage(bitmapResult);
我收到我把它放在一个位图中的图片,我旋转它并在方法drawTextImage()中绘制一个文本.
毕竟,我使用以下方法将bitmapResult存储在SD卡上:
- 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));
谢谢