I\'m trying to draw on an ImageViewTouch, a library which enables pinch zooming. I\'m able to draw over the image using Canvas, but when I zoom the image, the drawing disapp
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
loadBitmapFromView(mImage);
}
}, 1000);
In my case, I forgot to set orientation
to vertical
for parent LinearLayout
and the default value of horizontal
has been set, so I set it and my problem gone...
android:orientation="vertical"
If everything else is correct you are executing your code too early.
The view's layout has not yet been measured by Android. Try executing in OnResume just to see if this is your problem.
Cheers!
I finally figured out a solution for my problem.
I'm using the post
method of the View, which will be executed only after the view measuring and layouting, this way getWidth()
and getHeight()
returns the actual width and height.
Here's the code sample:
mImage.post(new Runnable() {
@Override
public void run() {
mImage.setImageBitmap(loadBitmapFromView(mImage));
}
});
Hope it also helps someone else :)
java.lang.IllegalArgumentException: width and height must be > 0
is because in your Bitmap.createBitmap()
call v.getLayoutParams().width
or v.getLayoutParams().height
is 0. Probably the LayoutParams
are wrongly set in mImage
.
Update: setLayoutParams()
for the mImage
before using createBitmap()
. Something like this:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);
mImage.setLayoutParams(layoutParams);