【发布时间】:2011-10-18 07:25:22
【问题描述】:
我有一个 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;
}
谁能告诉我提高照片质量的方法。谢谢!
编辑:
在拍摄照片的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));
谢谢
【问题讨论】:
-
但它看起来很糟糕。一定有什么,因为当我用相机拍照时,在应用程序之外......只是为了好玩,照片看起来很漂亮!
-
我希望我能找到解决办法,否则......我不知道我要做什么!
-
质量的具体含义是什么?解决?明晰?亮度?对比?色彩均衡?影响照片质量的因素有很多。
-
清晰度/亮度....我的图像现在看起来很模糊
-
Android 相机软件可能会在拍照时考虑手机的运动。我怀疑你的软件照片模糊是因为你按下相机按钮时手机在移动。