Reputation: 380
I am trying to create an android application (min SDK 14, target SDK 18) that works with images (move, scale, rotate). I have done the move part. But I can't make scale and rotate to work using Matrix.
According to what I have read, here is the code I am using for constructing an image view and do scale and rotate with Matrix.
public MyImage(Context context) {
super(context);
init();
}
public MyImage(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyImage(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
setScaleType(ScaleType.MATRIX);
}
public void rotate(float angle) {
Matrix m = new Matrix();
m.postRotate(angle);
setImageMatrix(m);
invalidate();
}
public void scale(float scaleFactor) {
Matrix m = new Matrix();
m.postScale(scaleFactor, scaleFactor);
setImageMatrix(m);
invalidate();
}
I have tried to use the set* functions of Matrix but that didn't work. I have tried to set the scale type every time in rotate and scale functions instead of in init, but that didn't work. I have tried to getImageMatrix instead of creating a new Matrix every time (i.e. creating an identity Matrix), but that didn't work.
I know that rotate and scale functions are getting called through debugger.
Obviously I am missing something. I'm trying to understand what I am missing.
Should the above code work? Have I misunderstood how Matrix works?
Upvotes: 1
Views: 2158
Reputation: 24730
see my anseer for that question How to maintain multi layers of ImageViews and keep their aspect ratio based on the largest one?, that code uses layers that can ne transformed by any Matrix you want
Upvotes: 1