Android 在相机中拍照并编辑
我需要拍张照片并编辑它。 我使用了origin camera并返回大尺寸图像,所以当我尝试创建新模板图像进行编辑时,应用程序将关闭,因为outOfMemoryError。 在将图像加载到应用程序之前,是否有任何方法可以帮助我调整图像大小 我的代码在照相机中拍摄图像:Android 在相机中拍照并编辑,android,android-camera,android-camera-intent,Android,Android Camera,Android Camera Intent,我需要拍张照片并编辑它。 我使用了origin camera并返回大尺寸图像,所以当我尝试创建新模板图像进行编辑时,应用程序将关闭,因为outOfMemoryError。 在将图像加载到应用程序之前,是否有任何方法可以帮助我调整图像大小 我的代码在照相机中拍摄图像: void loadImageFromCamera(){ Intent takePicture = new Intent("android.media.action.IMAGE_CAPTURE"); File phot
void loadImageFromCamera(){
Intent takePicture = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = null;
try{
// place where to store camera taken picture
photo = this.createTemporaryFile("picture", ".jpg");
photo.delete();
} catch(Exception e){
}
mImageUri = Uri.fromFile(photo);
takePicture.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(takePicture, 0);
}
private File createTemporaryFile(String part, String ext) throws Exception{
File tempDir = Environment.getExternalStorageDirectory();
tempDir = new File(tempDir.getAbsolutePath() + "/.temp/");
if(!tempDir.exists()){
tempDir.mkdir();
}
return File.createTempFile(part, ext, tempDir);
}
public void grabImage(){
this.getContentResolver().notifyChange(mImageUri, null);
ContentResolver cr = this.getContentResolver();
try {
originImage = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri);
}catch (Exception e){
}
}
是的,您可以调整图像的大小 使用以下方法调整图像的大小
public static Bitmap getResizedBitmap(Bitmap image, int newHeight, int newWidth) {
int width = image.getWidth();
int height = image.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(image, 0, 0, width, height,
matrix, false);
return resizedBitmap;
}
是的,您可以调整图像的大小 使用以下方法调整图像的大小
public static Bitmap getResizedBitmap(Bitmap image, int newHeight, int newWidth) {
int width = image.getWidth();
int height = image.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(image, 0, 0, width, height,
matrix, false);
return resizedBitmap;
}
加载图像时无法调整图像大小,因为outOfMemoryError\n我尝试添加您的代码,但不起作用:|。我需要它在加载到我的应用程序之前调整大小。谢谢兄弟,但我需要它在加载之前调整大小。加载前是否有调整图像大小的方法?为什么不试试这个方法?将图像缩小到您想要的大小并加载,然后进行相应的编辑?我在这里发布的代码是缩小您在活动中使用的图像大小,将图像字符串按您所需的宽度和高度添加到图像中,然后您将获得调整大小的图像您可以在上使用它,这样所有的大小调整都与加载后的应用程序相关,而不是预加载的应用程序。您无法在加载图像时调整图像大小,因为outOfMemoryError\n我尝试添加您的代码,但不起作用:|。我需要它在加载到我的应用程序之前调整大小。谢谢兄弟,但我需要它在加载之前调整大小。加载前是否有调整图像大小的方法?为什么不试试这个方法?将图像缩小到您想要的大小并加载,然后进行相应的编辑?我在这里发布的代码是缩小您在活动中使用的图像大小,将图像字符串按您所需的宽度和高度添加到图像中,然后您将获得调整大小的图像您可以在上使用它,以便所有大小调整都与加载应用程序后而不是加载应用程序前相关