放大后如何绘制一个圆圈

前端之家收集整理的这篇文章主要介绍了放大后如何绘制一个圆圈前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用图像视图并使用layerDrawable绘制叠加图像.
我已经使用了两个位图原始和myBitmap.
放大后,我不能在正确的位置绘制圆,它被绘制在不同的位置.

这是我使用的代码,

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,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
   }

请帮助我放大后,我需要在正确的位置绘制圆形.

任何帮助将不胜感激.

解决方法

你可以添加显示你想要获得什么的图像,还有一个图片显示你所得到的?

要记住的一件事是,某些操作对于y轴使用不同的零点.我一直在对Surfaceview进行矩阵运算,在这里我不得不计算一个校正因子,因为一个操作将视图的顶部用作y = 0,矩阵运算用作视图的底部为y = 0,所以实际的矩阵运算需要类似于:matrixY =(totalHeightY – Yposition).

显示您期望的和您获得的将有助于诊断问题比运行和通过您的代码更快地运行:)

原文链接:https://www.f2er.com/android/311887.html

猜你在找的Android相关文章