我在不使用 Canvas 的情况下想出了答案,使用 onTouch() 进行图像视图:
public class Test extends Activity {
ArrayList<Integer> array_x = new ArrayList<Integer>();
ArrayList<Integer> array_y = new ArrayList<Integer>();
Button btnArray;
Bitmap charscropped;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
ImageView img = (ImageView) findViewById(R.id.imageView1);
final ImageView img2 = (ImageView) findViewById(R.id.imageCroppd);
img.setImageBitmap(CaptureActivity.staticBitmap);
btnArray = (Button) findViewById(R.id.btn_for_array);
btnArray.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < array_x.size(); i++) {
Log.e("Array Index-" + i, " - " + array_x.get(i));
}
int xBegin = array_x.get(0);
int xEnd = array_x.get(array_x.size()-1);
int yBegin = array_y.get(0);
int yEnd = array_y.get(array_y.size()-1);
CaptureActivity.staticBitmap.getWidth();
CaptureActivity.staticBitmap.getHeight();
//charscropped = Bitmap.createBitmap(CaptureActivity.staticBitmap, xBegin, yBegin, img2.getWidth(), img2.getHeight());
charscropped = Bitmap.createBitmap(CaptureActivity.staticBitmap, xBegin, yBegin-20, 200, 40);
img2.setImageBitmap(charscropped);
}
});
img.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
array_x.add(x);
return array_y.add(y);
}
});
}
}