android 摄像头拍照获取的图片设置质量,android – 如何提高CameraManager拍摄的照片质量...

These are some methods when we working on Camer manager,this method

may help you.

Android Camera应用程序对Intent中的照片进行编码

传递给onActivityResult()作为附加内容中的一个小位图

关键的“数据”.以下代码检索此图像并显示

它在ImageView中.

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {

Bundle extras = data.getExtras();

Bitmap imageBitmap = (Bitmap) extras.get("data");

mImageView.setImageBitmap(imageBitmap);

}

}

private File createImageFile() throws IOException {

// Create an image file name

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());

String imageFileName = "JPEG_" + timeStamp + "_";

File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);

File image = File.createTempFile(

imageFileName, /* prefix */

".jpg", /* suffix */

storageDir /* directory */

);

// Save a file: path for use with ACTION_VIEW intents

mCurrentPhotoPath = "file:" + image.getAbsolutePath();

return image;

}

private void setPic() {

// Get the dimensions of the View

int targetW = mImageView.getWidth();

int targetH = mImageView.getHeight();

// Get the dimensions of the bitmap

BitmapFactory.Options bmOptions = new BitmapFactory.Options();

bmOptions.inJustDecodeBounds = true;

BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);

int photoW = bmOptions.outWidth;

int photoH = bmOptions.outHeight;

// Determine how much to scale down the image

int scaleFactor = Math.min(photoW/targetW, photoH/targetH);

// Decode the image file into a Bitmap sized to fill the View

bmOptions.inJustDecodeBounds = false;

bmOptions.inSampleSize = scaleFactor;

bmOptions.inPurgeable = true;

Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);

mImageView.setImageBitmap(bitmap);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android应用程序中使用摄像头可以实现拍照、录像、实时预览等功能。Android提供了Camera API和Camera2 API两种方式来操作摄像头。 使用Camera API(适用于Android 5.0以下版本)的一般步骤如下: 1. 获取摄像头实例:使用Camera类的open()方法获取摄像头实例。通常前置摄像头为0,后置摄像头为1。 2. 配置摄像头参数:通过Camera.Parameters类设置摄像头的预览尺寸、图像格式、闪光灯等参数。 3. 实时预览:创建一个SurfaceView作为预览界面,并通过Camera类的setPreviewDisplay()方法将其与摄像头关联起来。然后调用startPreview()方法开始实时预览。 4. 拍照:使用Camera类的takePicture()方法拍照,并通过回调接口处理拍照结果。 使用Camera2 API(适用于Android 5.0及以上版本)的一般步骤如下: 1. 获取摄像头管理器:使用CameraManager获取摄像头管理器实例。 2. 配置摄像头参数:通过CameraCharacteristics类获取摄像头的特性,并设置预览尺寸、图像格式、闪光灯等参数。 3. 创建预览会话:使用CameraDevice类打开摄像头,并创建一个预览会话。 4. 实时预览:创建一个TextureView作为预览界面,并通过setSurfaceTextureListener()方法将其与摄像头关联起来。在TextureView.SurfaceTextureListener的回调方法中,使用CaptureRequest.Builder类创建一个预览请求,并发送给摄像头设备。 5. 拍照:创建一个ImageReader对象,设置图像格式和大小,并通过CameraCaptureSession.CaptureCallback处理拍照结果。 具体实现的代码较为复杂,涉及到相机权限的获取、图像处理等方面的内容。您可以参考Android官方文档以及一些开源项目来学习和实践摄像头的使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值