放大后如何绘制一个圆圈

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

这是我使用的代码,

  1. ImageView view = (ImageView) findViewById(R.id.imageView);
  2. view.setOnTouchListener(this);
  3.  
  4. Options options = new BitmapFactory.Options();
  5. options.inScaled = false;
  6. original = BitmapFactory.decodeResource(getResources(),R.drawable.mainscreen,options);
  7. original= getResizedBitmap(original,width,200);
  8. myBitmap = func(original);
  9.  
  10. Resources r = getResources();
  11. layers = new Drawable[2];
  12. layers[0] = new BitmapDrawable(original);
  13. layers[1] = new BitmapDrawable(myBitmap);
  14. LayerDrawable layerDrawable = new LayerDrawable(layers);
  15. view.setImageDrawable(layerDrawable);
  16.  
  17. bitmap = Bitmap.createBitmap(width,200,Config.ARGB_8888);
  18. pcanvas = new Canvas();
  19. pcanvas.setBitmap(bitmap);
  20. pcanvas.drawBitmap(grayScale,null);
  21.  
  22.  
  23. public boolean onTouch(View v,MotionEvent rawEvent) {
  24. WrapMotionEvent event = WrapMotionEvent.wrap(rawEvent);
  25. // ...
  26. ImageView view = (ImageView) v;
  27.  
  28. // Dump touch event to log
  29. // dumpEvent(event);
  30. if (isZoomrequired == false)
  31. {
  32. x = (int) rawEvent.getX();
  33. y = (int) rawEvent.getY();
  34. r = SettingsActivity.brushsize;
  35.  
  36. pcanvas.drawCircle(x,y,r,mPaint);
  37. layers[1] = new BitmapDrawable(bitmap);
  38. LayerDrawable layerDrawable = new LayerDrawable(layers);
  39. view.setImageDrawable(layerDrawable);
  40.  
  41. }
  42. else
  43. {
  44. // Handle touch events here...
  45. switch (event.getAction() & MotionEvent.ACTION_MASK) {
  46. case MotionEvent.ACTION_DOWN:
  47. savedMatrix.set(matrix);
  48. start.set(event.getX(),event.getY());
  49. Log.d(TAG,"mode=DRAG");
  50. mode = DRAG;
  51. break;
  52. case MotionEvent.ACTION_POINTER_DOWN:
  53. oldDist = spacing(event);
  54. Log.d(TAG,"oldDist=" + oldDist);
  55. if (oldDist > 10f) {
  56. savedMatrix.set(matrix);
  57. midPoint(mid,event);
  58. mode = ZOOM;
  59. Log.d(TAG,"mode=ZOOM");
  60. }
  61. break;
  62. case MotionEvent.ACTION_UP:
  63. case MotionEvent.ACTION_POINTER_UP:
  64. mode = NONE;
  65. Log.d(TAG,"mode=NONE");
  66. break;
  67. case MotionEvent.ACTION_MOVE:
  68. if (mode == DRAG) {
  69. // ...
  70. matrix.set(savedMatrix);
  71. matrix.postTranslate(event.getX() - start.x,event.getY() - start.y);
  72. }
  73. else if (mode == ZOOM) {
  74. float newDist = spacing(event);
  75. Log.d(TAG,"newDist=" + newDist);
  76. if (newDist > 10f) {
  77. matrix.set(savedMatrix);
  78. float scale = newDist / oldDist;
  79. matrix.postScale(scale,scale,mid.x,mid.y);
  80. }
  81. }
  82. break;
  83. }
  84.  
  85.  
  86. view.setImageMatrix(matrix);
  87.  
  88. }
  89. return true; // indicate event was handled
  90. }

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

任何帮助将不胜感激.

解决方法

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

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

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

猜你在找的Android相关文章