我正在使用我在GitHub上找到的裁剪工具。当我在一个单独的模块上实现它时,它工作得很好。但是,当我在实际应用程序中使用相同的代码时,我看到" OutOfMemoryError" .Below是代码片段。我花了很多时间在这上面,任何帮助都会受到高度赞赏。
扫描活动:
SELECT Distinct S.[Last Name] , S.Status, R.Risk
FROM Status S
INNER JOIN Risk R
ON R.[Last Name] = S.[Last Name]
// 441
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
Uri imageUri = getPickImageResultUri(data);
activity_scan.xml: 仅发布基本代码
((CropImageView) findViewById(R.id.CropImageView)).setImageUri(imageUri);
}
}
Log cat说:
<com.theartofdev.edmodo.cropper.CropImageView
android:id="@+id/CropImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/layout1"
android:layout_gravity="center_horizontal"
android:background="@color/white"
android:layout_marginTop="2dp"
/>
<ImageView
android:id="@+id/croppedImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_below="@+id/CropImageView"
android:background="@color/white"/>
CropImageView:
java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:928)
at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
at android.graphics.Bitmap.createBitmap(Bitmap.java:833)
at com.theartofdev.edmodo.cropper.util.ImageViewUtil.rotateBitmap(ImageViewUtil.java:239)
at com.theartofdev.edmodo.cropper.util.ImageViewUtil.rotateBitmapByExif(ImageViewUtil.java:124)
at com.theartofdev.edmodo.cropper.util.ImageViewUtil.rotateBitmapByExif(ImageViewUtil.java:97)
at com.theartofdev.edmodo.cropper.CropImageView.setImageUri(CropImageView.java:295)
at com.example.simcoeappco.Clync.ScanActivity.onActivityResult(ScanActivity.java:441)
at android.app.Activity.dispatchActivityResult(Activity.java:5643)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3576)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3623)
at android.app.ActivityThread.access$1400(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1328)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
// 295
public void setImageUri(Uri uri) {
if (uri != null) {
DisplayMetrics metrics = getResources().getDisplayMetrics();
double densityAdj = metrics.density > 1 ? 1 / metrics.density : 1;
int width = (int) (metrics.widthPixels * densityAdj);
int height = (int) (metrics.heightPixels * densityAdj);
ImageViewUtil.DecodeBitmapResult decodeResult =
ImageViewUtil.decodeSampledBitmap(getContext(), uri, width, height);
ImageViewUtil.java
ImageViewUtil.RotateBitmapResult rotateResult =
ImageViewUtil.rotateBitmapByExif(getContext(), decodeResult.bitmap, uri);
setImageBitmap(rotateResult.bitmap);
mLoadedImageUri = uri;
mLoadedSampleSize = decodeResult.sampleSize;
mDegreesRotated = rotateResult.degrees;
}
}
// 97
public static RotateBitmapResult rotateBitmapByExif(Context context, Bitmap bitmap, Uri uri) {
try {
File file = getFileFromUri(context, uri);
if (file.exists()) {
ExifInterface ei = new ExifInterface(file.getAbsolutePath());
ImageViewUtil.java
return rotateBitmapByExif(bitmap, ei);
}
} catch (Exception ignored) {
}
return new RotateBitmapResult(bitmap, 0);
}
// 124
public static RotateBitmapResult rotateBitmapByExif(Bitmap bitmap, ExifInterface exif) {
int degrees = 0;
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degrees = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degrees = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degrees = 270;
break;
}
if (degrees > 0) {
ImageViewUtil.java
bitmap = rotateBitmap(bitmap, degrees);
}
return new RotateBitmapResult(bitmap, degrees);
}
// 239
public static Bitmap rotateBitmap(Bitmap bitmap, int degrees) {
Matrix matrix = new Matrix();
matrix.setRotate(degrees);