如何放大的android后画一个圆 [英] How to draw a circle after zoom in android

查看:151
本文介绍了如何放大的android后画一个圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的图像查看和使用layerDrawable绘制覆盖图像。 我已经使用了两个位图原件和MYBITMAP。 放大后,我在正确的位置,不能画圈子,它画在不同的位置。

I am using Image view and drawing overlay image using layerDrawable. I have used two bitmaps original and myBitmap. After zoom I am not able draw circle in correct location, it's drawn in different location.

这是在code我使用,

This is the code I am using,

    ImageView view = (ImageView) findViewById(R.id.imageView);
    view.setOnTouchListener(this);

    Options options = new BitmapFactory.Options();
    options.inScaled = false;
    original = BitmapFactory.decodeResource(getResources(), R.drawable.mainscreen,options); 
    original= getResizedBitmap(original, width, 200);
    myBitmap = func(original);

    Resources r = getResources();
    layers = new Drawable[2];
    layers[0] = new BitmapDrawable(original);
    layers[1] = new BitmapDrawable(myBitmap);
    LayerDrawable layerDrawable = new LayerDrawable(layers);
    view.setImageDrawable(layerDrawable);

    bitmap =  Bitmap.createBitmap(width, 200, Config.ARGB_8888);
    pcanvas = new Canvas();
    pcanvas.setBitmap(bitmap);  
    pcanvas.drawBitmap(grayScale, 0, 0, null);


   public boolean onTouch(View v, MotionEvent rawEvent) {
      WrapMotionEvent event = WrapMotionEvent.wrap(rawEvent);
      // ...
      ImageView view = (ImageView) v;

      // Dump touch event to log
     // dumpEvent(event);
      if (isZoomRequired == false)
      {
          x = (int) rawEvent.getX();
          y = (int) rawEvent.getY();
          r = SettingsActivity.brushsize;

          pcanvas.drawCircle(x, y, r, mPaint);
          layers[1] = new BitmapDrawable(bitmap);
          LayerDrawable layerDrawable = new LayerDrawable(layers);
          view.setImageDrawable(layerDrawable);

      }
      else
      {
      // Handle touch events here...
      switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
         savedMatrix.set(matrix);
         start.set(event.getX(), event.getY());
         Log.d(TAG, "mode=DRAG");
         mode = DRAG;
         break;
      case MotionEvent.ACTION_POINTER_DOWN:
         oldDist = spacing(event);
         Log.d(TAG, "oldDist=" + oldDist);
         if (oldDist > 10f) {
            savedMatrix.set(matrix);
            midPoint(mid, event);
            mode = ZOOM;
            Log.d(TAG, "mode=ZOOM");
         }
         break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
         mode = NONE;
         Log.d(TAG, "mode=NONE");
         break;
      case MotionEvent.ACTION_MOVE:
         if (mode == DRAG) {
            // ...
            matrix.set(savedMatrix);
            matrix.postTranslate(event.getX() - start.x,
                  event.getY() - start.y);
         }
         else if (mode == ZOOM) {
            float newDist = spacing(event);
            Log.d(TAG, "newDist=" + newDist);
            if (newDist > 10f) {
               matrix.set(savedMatrix);
               float scale = newDist / oldDist;
               matrix.postScale(scale, scale, mid.x, mid.y);
            }
         }
         break;
      }


      view.setImageMatrix(matrix);

      }
      return true; // indicate event was handled
   }

请帮我。我需要绘制圆的正确位置变焦之后。

Kindly help me. I need to draw circle in correct location after zoom.

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

你能不能添加图像,显示它是什么,你正在试图获得和PIC显示你会得到什么呢?

Could you add images showing what it is you're trying to get and a pic showing what you get instead?

有一点要记住的是,某些操作使用不同的零点y轴。我已经在一个surfaceview,其中我不得不计算,因为一次操作中使用的视图的顶部为y = 0和矩阵操作中使用的视图的底部为y = 0的修正系数打击这一对矩阵运算,所以实际的矩阵运算需要的是这样的:。matrixY =(totalHeightY - Yposition)

One thing to keep in mind is that certain operations use a different zero point for the y axis. I've been fighting this on matrix operations on a surfaceview, where I've had to calculate a correction factor because one operation used the top of the view as y=0 and the matrix operation used the bottom of the view as y=0, so the actual matrix operation needed something like: matrixY = (totalHeightY - Yposition).

但显示你所期望的,你在说什么,将有助于诊断问题,速度比运行,并通过您的code工作:)

But showing what you expect and what you're getting would help diagnose the problem quicker than running and working through your code :)

这篇关于如何放大的android后画一个圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆