问题描述
我找到了这两部分代码,以了解如何在Android中使用相机拍照:
I found these two part of code, to how to take a photo from the camera in Android:
在onCreate()
方法内部:
Button capture;
capture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
}
});
还有
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
}
}
它确实有效,但是问题在于结果图像的质量非常低!我想知道如何指定想要拍摄的图像质量?
And it works, but the problem is that, the quality of the result image is very low! I like to know how can I specify what quality of image I want to take?
还想知道,bitmap
还有其他用于存储或处理图像的选项吗?
Also like to know, are there other options that bitmap
to store or work on images?
这是我按下捕获"按钮之前看到的内容:
This is what I see before pushing the capture button:
这是按下捕获"按钮后需要执行的操作(它会降低质量):
And this is what it takes after pushing the capture button(it reduces the quality):
我必须说,当我用手机拍照时(我是说在这个应用程序之外),它可以很好地工作,但是在我编写的应用程序中,它会降低所拍摄的图像质量!
I must say, when I take photos with my phone(outside of this app I mean) it works good, but inside the my written app, it reduces the taken image quality!
**另外我还有一个问题...如何在拍摄完图像后删除显示的第二个页面(该页面显示我的意思是RETRY-OK
选项).
**Also I have another question...how can I remove this second page that shows after it took the image(the page shows RETRY-OK
options I mean).
推荐答案
检查以下解决方案以解决您的问题.
Check below solution for your problem.
public static File IMAGE_PATH = null;
public static final int CAMERA_REQUEST = 100;
private void openCameraApp(Context mContext) {
Intent picIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
String file_path = Environment.getExternalStorageDirectory().toString() +
"/" + mContext.getResources().getString(R.string.app_name);
File dir = new File(file_path);
if (!dir.exists())
dir.mkdirs();
IMAGE_PATH = new File(dir, mContext.getResources().getString(R.string.app_name) + System.currentTimeMillis() + ".png");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
picIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(mContext, mContext.getPackageName()+".fileprovider", IMAGE_PATH));
}
else {
picIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(IMAGE_PATH));
}
((Activity) mContext).startActivityForResult(picIntent, CAMERA_REQUEST);
}
这篇关于如何在Android上指定拍摄的图像质量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!