I have written my own custom view, in the custom view i have done free hand drawing using canvas.. After that i've added the custom view to linear layout.. how to add the custom view to image view.. please help me out...Thanks in advance...
Asked
Active
Viewed 1.4k times
2 Answers
7
This question isn't that clear but if you have a Bitmap and want draw it in an ImageView you just call ImageView.setImageBitmap().

Robby Pond
- 73,164
- 16
- 126
- 119
-
@Override protected void onDraw(Canvas canvas) { canvas.drawColor(0xFFAAAAAA); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); if(item_id==3){ canvas.drawText(AppModel.contents, 100, 100, mPaint); } else{ canvas.drawPath(mPath, mPaint); } } – saranya krishnan Mar 05 '11 at 14:40
-
how to set the above canvas into imageView?? – saranya krishnan Mar 05 '11 at 14:41
-
please update question with your code , and take a look at this link http://stackoverflow.com/questions/4918079/android-drawing-a-canvas-to-an-imageview – Burak Dede Mar 05 '11 at 17:13
0
In this case, you can convert your custom view to Bitmap
image by using the following snippet:
public static Bitmap getBitmapFromView(View view) {
//Define a bitmap with the same size as the view
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
//Bind a canvas to it
Canvas canvas = new Canvas(returnedBitmap);
//Get the view's background
Drawable bgDrawable =view.getBackground();
if (bgDrawable!=null)
//has background drawable, then draw it on the canvas
bgDrawable.draw(canvas);
else
//does not have background drawable, then draw white background on the canvas
canvas.drawColor(Color.WHITE);
// draw the view on the canvas
view.draw(canvas);
//return the bitmap
return returnedBitmap;
}
Then you can add bitmap to image view by using the following method:
imageview.setBitmapImage(returnedBitmap);

Satan Pandeya
- 3,747
- 4
- 27
- 53

Thiruvettai Athithiyan S
- 125
- 1
- 3
- 7