【问题标题】:Draw multiple points over imageview in android在android中的imageview上绘制多个点
【发布时间】:2019-08-09 18:34:34
【问题描述】:

如何在图像视图上添加多个点。 这就是我正在尝试的

    myView = (ImageView) findViewById(R.id.my_view);
        View view = LayoutInflater.from(ZoomTouchActivity.this).inflate(R.layout.layout_custom_view, null);
        CircularImageView imgView = view.findViewById(R.id.site_image);
        TextView siteName = view.findViewById(R.id.site_text);
        imgView.setImageResource(R.drawable.ic_launcher_background);
        siteName.setText("est");
        Bitmap bitmap = getBitmapFromView(view);
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.BLACK);
//        canvas.drawCircle(50, 50, 10, paint);
        canvas.drawBitmap(bitmap, 50, 50, paint);
        myView.setImageBitmap(bitmap);

【问题讨论】:

  • 到目前为止你做了什么?你身边的任何努力
  • 我已经尝试过这些相关的帖子,但对我不起作用stackoverflow.com/questions/26016655/…
  • @El Ruso 更新。我想你现在可以了

标签: android android-imageview android-canvas bitmapimage


【解决方案1】:

您可以通过简单地将图像的位图放在画布中,在画布上绘制并将绘制的画布设置为图像视图来在 ImageView 上绘图。您可以查看this 答案以获取更多详细信息。更多关于如何绘制的细节,可以查看android文档here

【讨论】:

    【解决方案2】:

    试试这个:

    BitmapFactory.Options myOptions;
    Canvas canvas;
    Bitmap mutableBitmap;
    Bitmap workingBitmap;
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_open= findViewById(R.id.btn_open);
        image2= findViewById(R.id.imageView);
        myOptions = new BitmapFactory.Options();
        bitmap = BitmapFactory.decodeResource(getResources(), 
        R.drawable.image000880,myOptions);
        paint= new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.WHITE);
    
        workingBitmap = Bitmap.createBitmap(bitmap);
        mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
        canvas = new Canvas(mutableBitmap);
    
       private void drawpoint(ImageView imageView,float x,float y, int raduis){
        myOptions.inDither = true;
        myOptions.inScaled = false;
        myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
        myOptions.inPurgeable = true;
    //  ArrayList<Point> list= new ArrayList<>();
        canvas.drawCircle(x,y, raduis, paint);
        imageView = (ImageView)findViewById(R.id.imageView);
        imageView.setAdjustViewBounds(true);
        imageView.setImageBitmap(mutableBitmap);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      相关资源
      最近更新 更多