java – How to display the drawn image in ImageView?

Question:

I draw like this:

    Bitmap bitmap = Bitmap.createBitmap(w, w, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawARGB(1, 178, 229, 255);
    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(Color.BLACK);
    p.setStyle(Paint.Style.STROKE);
    p.setStrokeWidth(1);
    canvas.drawCircle(400, 400, 100, p); 

There is a component:

ImageView iv = (ImageView) findViewById(R.id.iv);

How now to display the drawn on the screen in the ImageView component?

Answer:

To do this, there is a method ImageView#setImageBitmap(Bitmap bitmap) . In your case:

iv.setImageBitmap(bitmap);

You also need to make sure that when creating a Bitmap , its width is noticeable (i.e. not 0 or 1 etc), which was the cause of the problem in this particular case

Scroll to Top
AllEscort