I want to crop the image in my application. I tried a lot, but could not. Its a challenge to the Android developer. Is there any idea or link to the implementation of functions, moving, scaling and cropping an image in android, for example, facebook pic upload image. Now I can move, scale and crop and image. But not always like facebook. I want to set a fixed scale of images based on orientation. I attached screen shot-3.
My code is as below: -
crop_image.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > <FrameLayout android:id="@+id/flCrop" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" > <ImageView android:id="@+id/img" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="matrix" android:src="@drawable/nature" /> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:scaleType="fitXY" android:src="@drawable/blur_with_frame" android:visibility="visible" /> <ImageView android:id="@+id/troll_face" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginLeft="10dp" android:layout_gravity="bottom" /> </FrameLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="btnSelectPic" android:layout_marginRight="10dp" android:text="select Pic" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:onClick="btnCrop" android:text="Crop" /> </LinearLayout> </LinearLayout>
MainActivity.java
package com.hotveryspicy.maskimage; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.graphics.PointF; import android.net.Uri; import android.os.Bundle; import android.util.FloatMath; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import com.ipaulpro.afilechooser.utils.FileUtils; public class MainActivity extends Activity implements OnTouchListener{ ImageView img; FrameLayout flCrop; int framWidth = 0; int framHeight = 0; int imageHeight ; int imageWidth ; int cropImageWidth = 320; int cropImageHeight = 263; public static int SELECT_PHOTO =0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crop_image); img = (ImageView) findViewById(R.id.img); flCrop = (FrameLayout) findViewById(R.id.flCrop); img.setOnTouchListener(this); } public void btnCrop(View v) { ImageView troll_face = (ImageView) findViewById(R.id.troll_face); makeMaskImage(troll_face, R.drawable.nature); } public void btnSelectPic(View v){ Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, 0); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (resultCode) { case RESULT_OK: Uri targetUri = data.getData(); final String path = FileUtils.getPath(this, targetUri); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bitmap = null; try { bitmap = BitmapFactory .decodeFile(path); } catch (Exception e) {
Looking at my demo like: -
Screenshot 1 
When zoomed out, the image looks as follows: Screenshot-2 
What exactly I'm looking for: Screenshot-3

If anyone has an idea. Please help me. Thanks in advance...
android image move scale crop
jagdish
source share