Zooming lines created by Canvas
I've created lines over the ImageViewTouch using Canvas. However whenever I zoom in/out the Image, the line created keeps with the same size. Is it possible to also zoom the drawn line? Or is it at least possible to have the X and Y destination of a point?
I've solved my problem. Now I'm drawing the lines over the ImageViewTouch, then I convert it to bitmap and call setImageBitmap again.
@femosso I've met the same problem as yours. Can you paste a sample code here? Thank you!
Basically I did this:
mImage.setDesenhaCaminho(true); mImage.setImageBitmap(loadBitmapFromView(mImage));
the mImage object is a class extending ImageViewTouch.
On setDesenhaCaminho() I call invalidate() and set a flag to draw something in onDraw() method. Basically, this:
public void setDesenhaCaminho(boolean allow) { invalidate(); desenhaCaminho = allow; }
protected void onDraw(Canvas canvas) { if (desenhaCaminho) { // draw something. After this call I have the drawn view loaded on mImage instance } }
Finally my loadBitmapFromView() is called with the mImage instance updated with the desired draw:
private static Bitmap loadBitmapFromView(View v) { Bitmap b = Bitmap.createBitmap( v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.layout(0, 0, v.getWidth(), v.getHeight()); v.draw(c); return b; }
Load everything everything (the image and the draw) on loadBitmapFromView, and reset the imageBitmap from mImage
@femosso Thank you for your answer, however I tried this out and find it not working... It's too slow and draws in a wrong way.
I'm thinking about drawing the lines directly on the original bitmap, then use setImageBitmap(bitmap, matrix, ..., ...) to put it into the ImageViewZoom with the current matrix to keep it correctly transformed.
Do you think it is feasible? And do you have any idea how to draw lines directly on a bitmap?
Thank you!
Well, I solved it myself! You can view it on http://stackoverflow.com/questions/28830372/how-to-draw-lines-on-the-bitmap-used-in-imageviewzoom/28892388#28892388
In short, creating a Canvas using the bitmap, and then drawing lines on it, and apply it to the ImageViewZoom, that's all.
Thank for your answer anyway!
Glad you could solve it! :)