在android中的imageview上绘制多个点

时间:2018-05-08 11:00:42

标签: android android-imageview android-canvas bitmapimage

  

如何在图像视图上添加多个点。   这就是我想要的

    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);

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

尝试一下:

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);
}