在位图图像上绘制圆形onTouch

时间:2015-05-31 18:56:05

标签: java android canvas bitmap point

我在位图图像上的drawCircle上做了一个项目。我的问题是,当我画画时,重点不在于我的触摸。它与drawBitmap问题有关?我不知道如何解释。 lets see the image ..当我触摸蓝点时(据说它是我的光标,我只是编辑了图片),它会给出红点上的圆圈。为什么它不跟随触摸?对不起,如果我的问题不是很好,但我只是困惑。

 protected void onActivityResult(int requestCode, int resultCode,
  Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);

if (resultCode == RESULT_OK) {
     if (requestCode == 0) {
  Uri imageFileUri = intent.getData();
  try {
    BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
    bmpFactoryOptions.inJustDecodeBounds = true;
    bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(
            imageFileUri), null, bmpFactoryOptions);

    bmpFactoryOptions.inJustDecodeBounds = false;
    bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(
            imageFileUri), null, bmpFactoryOptions);

    alteredBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp
        .getHeight(), Config.ARGB_8888);
   alteredBitmap = alteredBitmap.copy(bmp.getConfig(), true);
    canvas = new Canvas(alteredBitmap);
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.RED);
 //   paint.setStrokeWidth(10);
  //  matrix = new Matrix();
    canvas.drawBitmap(bmp, 0,0, null);

    choosenImage.setImageBitmap(alteredBitmap);
    choosenImage.setOnTouchListener(this);
  } catch (Exception e) {
    Log.v("ERROR", e.toString());
  }
}

. //other codes here
. 
. 

 public boolean onTouch(View v, MotionEvent event) {
 if(event.getAction() != MotionEvent.ACTION_DOWN)
   return super.onTouchEvent(event);
  Point point = new Point();
  point.x1 = (int) event.getX();
  point.y1 = (int) event.getY();

  points.add(point);
  Log.d(TAG, "point: " + point);



  canvas.drawCircle( point.x1, point.y1,20, paint );
  choosenImage.invalidate();

更像是http://www.java2s.com/Code/Android/2D-Graphics/DrawonPictureandsave.htm。我按照他的教程。

0 个答案:

没有答案