当我从相机捕获图像失去了图像的质量?该怎么办? [英] When i capture image from camera it lost the quality of image? What to do?
本文介绍了当我从相机捕获图像失去了图像的质量?该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的点击图片代码如下:
My code of click on image is like below:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 300);
活动代码结果:
if (requestCode == 300) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File destination = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".jpg");
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if(number.equalsIgnoreCase("1"))
{
imageViewOneNumber.setImageBitmap(thumbnail);
image1="";
image1= getEncoded64ImageStringFromBitmap(thumbnail);
}
else
{
RelativeLayoutImage2.setVisibility(View.GONE);
FrameImage2.setVisibility(View.VISIBLE);
imageViewTwoNumber.setImageBitmap(thumbnail);
image2="";
image2= getEncoded64ImageStringFromBitmap(thumbnail);
}
}
相机捕获演示的图片:
< a href =https://i.stack.imgur.com/kqfnS.png =nofollow noreferrer>
Image of camera capture demo:
请帮我解决这个问题。当我点击相机的照片,它减小了图像的大小。
Please help me to solve this problem. When i click the photo from camera it decrease the size of image.
推荐答案
从 docs
Android相机应用程序保存全尺寸照片b $ ba文件保存到。
The Android Camera application saves a full-size photo if you give it a file to save into. You must provide a fully qualified file name where the camera app should save the photo.
范例程式码
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
...
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
String mCurrentPhotoPath;
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 = Environment.getExternalStoragePublicDirectory(
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;
}
这篇关于当我从相机捕获图像失去了图像的质量?该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文