我有一个 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;
}
有人可以告诉我有什么方法可以提高我的照片质量吗?谢谢!
EDIT:
In 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();
}
}
};
in 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
on 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));
Thanks