我正在使用Scissors by Lyft在我的应用中裁剪图片。裁剪器可以处理特定尺寸的图像,但无法将大图像加载到裁剪视图中。我尝试使用Picasso将图像加载到cropView中,但这也不起作用。
我不能在这里上传我的全班,但这里有相关的片段。
import com.lyft.android.scissors.CropView;
private CropView mCropView;
//This is where it fails. For big images I get an Out Of Memory Exception and the cropView remains blank.
private void handleImagePickedFromGallery(Intent data) {
Uri imageUri = data.getData();
mCropView.extensions().load(imageUri);
}
//this is called when the user clicks on the
//crop button below the cropView
private void onCropClicked() {
mCroppedImage = mCropView.crop(); //get cropped image
ImageView imageView = findViewById(R.id.ic_image);
mCropView.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);
imageView.setImageBitmap(mCroppedImage); //load cropped image
mFab.setImageDrawable(getDrawable(R.drawable.ic_check)); //change crop icon to done
}
这就是XML(怀疑这会有用):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.rbc.imageselector.ImageControllerActivity">
<ImageView
android:id="@+id/ic_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="Image selected by user"
android:visibility="gone"/>
<com.lyft.android.scissors.CropView
android:id="@+id/crop_view"
android:layout_alignTop="@id/ic_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cropviewViewportRatio="1" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/crop_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:src="@drawable/ic_crop" />
</RelativeLayout>