我已经设法实现了ACTION_IMAGE_CAPTURE的使用目的,以便在我的应用程序中拍照。出于某种原因,拍摄照片时,预览图像(在将图像发回给我的应用程序之前,使用刻度/十字图标显示的图像)的分辨率是正方形且非常低,即使我设法保存到存储不是。我已经完成了所有关于返回低质量图像的问题,并且所有答案都提供了有关如何在应用程序本身中获得更高质量图像的解决方案,而不是如何告诉相机应用程序使用全面质量预览。任何帮助将非常感激!使用ACTION_IMAGE_CAPTURE时为什么预览图像模糊
1
A
回答
0
不是如何告诉相机应用中使用全质量预览
那是因为没有办法为你告诉相机应用“使用全质量预览”。
有成千上万的Android设备型号。这些设备型号中有数百个内置相机应用程序,还有更多可从Play商店等地下载。的ACTION_IMAGE_CAPTURE
行为是达到这些应用程序的开发,其中包括:
他们是否有一个确认屏幕(‘用它发回给我的应用程序之前,周期/十字图标显示’)
图像的样子是确认屏幕
比EXTRA_OUTPUT
其他的,有在输入方面没有其他documented aspect to the ACTION_IMAGE_CAPTURE
protocol,所以摄像头的应用程序并不需要提供任何东西。
无论出于何种原因,您的特定相机应用程序未实现得特别好。
0
尝试检查下面的代码工作为我的应用程序完美。
TakeImageActivity.java
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class TakeImageActivity extends ActivityBase implements OnClickListener {
File file,mFileTemp;
Button buttonTakeImageCam;
ImageView imageView;
Uri mPhotoUri;
Bitmap thumbnail;
private Uri fileUri;
private static final String IMAGE_DIRECTORY_NAME = "PhotoEditor Camera";
public static final int MEDIA_TYPE_IMAGE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.take_image_activity);
file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/FrameImages");
initializetion();
}
private void initializetion() {
// TODO Auto-generated method stub
buttonTakeImageCam = (Button) findViewById(R.id.buttonTakeImageCam);
buttonTakeImageCam.setOnClickListener(this);
if (!isDeviceSupportCamera()) {
Toast.makeText(getApplicationContext(),
"Sorry! Your device doesn't support camera",
Toast.LENGTH_LONG).show();
// will close the app if the device does't have camera
finish();
}
}
private boolean isDeviceSupportCamera() {
if (getApplicationContext().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA)) {
// this device has a camera
return true;
} else {
// no camera on this device
return false;
}
}
public Uri getOutputMediaFileUri(int type) {
return Uri.fromFile(getOutputMediaFile(type));
}
private static File getOutputMediaFile(int type) {
// External sdcard location
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
IMAGE_DIRECTORY_NAME);
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
+ IMAGE_DIRECTORY_NAME + " directory");
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
} else {
return null;
}
return mediaFile;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.buttonTakeImageCam:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, 2);
break;
default:
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode != RESULT_OK)
return;
switch (requestCode) {
case 2:
if (resultCode == RESULT_OK) {
// successfully captured the image
// display it in image view
previewCapturedImage();
} else if (resultCode == RESULT_CANCELED) {
// user cancelled Image capture
Toast.makeText(getApplicationContext(),
"User cancelled image capture", Toast.LENGTH_SHORT)
.show();
} else {
// failed to capture image
Toast.makeText(getApplicationContext(),
"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}
break;
}
}
private void previewCapturedImage() {
try {
// bimatp factory
BitmapFactory.Options options = new BitmapFactory.Options();
// downsizing image as it throws OutOfMemory Exception for larger
// images
options.inSampleSize = 2;
final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),
options);
//Set image here
imgPreview.setImageBitmap(bitmap);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
public Bitmap getPreview(String fileName) {
File image = new File(fileName);
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeFile(image.getPath(), bounds);
if ((bounds.outWidth == -1) || (bounds.outHeight == -1)) {
return null;
}
int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
: bounds.outWidth;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = originalSize/64;
// opts.inSampleSize = originalSize;
return BitmapFactory.decodeFile(image.getPath());
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
}
take_image_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
<Button
android:id="@+id/buttonTakeImageCam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textSize="25sp"
android:text="Camera"/>
</RelativeLayout>
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.camera.photo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="true"/>
<application
android:icon="@drawable/ic_launcher"
android:largeHeap="true"
android:label="@string/app_name" >
<activity
android:name=".TakeImageActivity"
android:hardwareAccelerated="false"
android:screenOrientation="portrait"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
相关问题
- 1. 为什么图像模糊?
- 2. 为什么GetThumbnailImage创建模糊图像
- 3. 使用ACTION_IMAGE_CAPTURE时返回什么数据?
- 4. 为什么这个SVG图像缩小时会模糊?
- 5. 为什么图像在运动补间时会模糊?
- 6. 模糊图像? Chrome上没有模糊图片,只有IE/FF ...为什么?
- 7. Winforms打印预览模糊
- 8. 使用Java模糊图像?
- 9. 使用url填充模式为svg圈时图像模糊
- 10. Android展示模糊预览,而大图像加载
- 11. 为什么使用Surface视图的相机图像与使用Intent捕捉的图像不同(ACTION_IMAGE_CAPTURE)
- 12. 使用OpenGL 2.0在Android上模糊实时相机预览
- 13. 使用Reportlab预览图像?
- 14. 使用fileupload预览图像
- 15. 模仿UICollectionView图像预览
- 16. Chrome浏览器的模糊SVG图像
- 17. 图像模糊
- 18. 模糊图像
- 19. 为什么使用PHP裁剪图像时图像背景颜色显示模糊?
- 20. 为什么UITableViewCell的backgroundView模糊的图像
- 21. 为什么上传android后图像模糊?
- 22. 为什么在手机版全屏幕背景图像模糊?
- 23. 我的图像模糊!为什么不是WPF的SnapsToDevicePixels工作?
- 24. 为什么在去除噪音后图像变得模糊?
- 25. 使用UIKit/Coregraphics呈现为PDF时的模糊图像
- 26. DrawToBitmap使图像模糊
- 27. stretchableImageWithLeftCapWidth使图像模糊
- 28. 上传图像时的图像预览
- 29. cwac相机显示模糊图像预览即使在连续对焦
- 30. iPhoto像使用jQuery的图像预览?
这是默认来到ra应用程序在使用网络摄像头的android模拟器上。 –
@BenWainwright:这并没有改变答案。 – CommonsWare