可能重复:
如何在android中裁剪解析后的图像?
我在res/drawable文件夹中有一个图像,我想在将图像加载到ImageView时裁剪(即切出图像的某些部分)图像.但是我不确定如何做到这一点,有什么建议吗?
我在android中创建应用程序.在该应用中,存在裁剪图像的一部分.当我用谷歌搜索它时,我得到了一些基于图像裁剪的想法,但我有一些问题,因为我有一个男人的形象.在这里,我需要完全裁剪男人的脸,但我的代码只适用于sdcard中的矩形和覆盖图像.我对那段代码感到困惑..任何人都可以帮助我...
编辑:
super.onCreate(icicle);
mContentResolver = getContentResolver();
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.cropimage);
mImageView = (CropImageView) findViewById(R.id.image);
showStorageToast(this);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
if (extras.getString("circleCrop") != null) {
mCircleCrop = true;
mAspectX = 1;
mAspectY = 1;
}
mImagePath = extras.getString("image-path");
mSaveUri = getImageUri(mImagePath);
mBitmap = getBitmap(mImagePath);
mAspectX = extras.getInt("aspectX");
mAspectY = extras.getInt("aspectY");
mOutputX = extras.getInt("outputX");
mOutputY = extras.getInt("outputY");
mScale = extras.getBoolean("scale", true);
mScaleUp = extras.getBoolean("scaleUpIfNeeded", true);
}
if (mBitmap == null) {
Log.d(TAG, "finish!!!");
finish();
return; …
Run Code Online (Sandbox Code Playgroud) 请参见下图
我想通过拖动它的角来改变高亮显示视图的形状..拖动角落后的视图应该是矩形的,它可以是任意形状的任何形状
如何实现这个?
现在我已经完成了触摸事件中可移动的4个角落但形状没有变化
package com.assignment.DragDrop;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
public class DrawView extends View {
Point point1,point2,point3,point4;
private ColorBall[] colorballs = new ColorBall[4]; // array that holds the balls
private int balID = 0; // variable to know what ball is being dragged
Paint paint;
Canvas canvas;
public DrawView(Context context) {
super(context);
paint=new Paint();
setFocusable(true); //necessary for getting the touch events …
Run Code Online (Sandbox Code Playgroud)