Hai bob thanks for reply.....
I made the above change in my code but still the same result....And my
image get distorted it's edges while rotation......
On Wednesday, 12 September 2012 20:04:12 UTC+5:30, bob wrote:
>
> Well, for one thing, this is not right:
>
> canvas.rotate(angle, X + getWidth() >> 1, Y + getHeight() >> 1);
>
> You should be calling getWidth and getHeight on the bitmap.
>
> Something like this:
>
> canvas.rotate(angle, X + resizedBitmap.getWidth()/2, Y +
> resizedBitmap.getHeight()/2);
>
>
>
> On Tuesday, September 11, 2012 12:54:59 AM UTC-5, HPP wrote:
>>
>> Hai thanks for the replys........
>>
>> I changed my code like
>>
>> matrix.postScale(scaleWidth, scaleHeight);
>> matrix.postRotate(angle, X+centrex , Y+centrey );
>> canvas.setMatrix(matrix);
>>
>> Bitmap resizedBitmap = Bitmap.createBitmap(arrow, 0, 0,
>> arrow.getWidth(), arrow.getHeight(), matrix, true);
>> canvas.save(Canvas.MATRIX_SAVE_FLAG);
>> canvas.rotate(angle, *X + *getWidth() >> 1, *Y +* getHeight() >>
>> 1);
>> super.dispatchDraw(canvas);
>> canvas.drawBitmap(resizedBitmap, X, Y, null); //Draw the arrow on
>> the rotated canvas.
>> canvas.restore();
>>
>> But still it's not rotating about the centre.......
>>
>>
>>
>> On Tuesday, 11 September 2012 01:49:30 UTC+5:30, bob wrote:
>>>
>>> canvas.save(Canvas.MATRIX_SAVE_FLAG);
>>> canvas.rotate(angle, *X + *getWidth() >> 1, *Y +* getHeight() >> 1);
>>> super.dispatchDraw(canvas);
>>> canvas.restore();
>>>
>>> On Monday, September 10, 2012 2:22:15 PM UTC-5, lbendlin wrote:
>>>>
>>>> canvas.save(Canvas.MATRIX_SAVE_FLAG);
>>>> canvas.rotate(angle, getWidth() >> 1, getHeight() >> 1);
>>>> super.dispatchDraw(canvas);
>>>> canvas.restore();
>>>>
>>>> On Monday, September 10, 2012 9:18:32 AM UTC-4, Haris wrote:
>>>>>
>>>>> Hai all
>>>>>
>>>>> I am trying an application like rotating image with motion
>>>>> sensor....My problem is that the image does not rotate about centre
>>>>> properly....And my angle range is 0 to 90 and 0 to -90..
>>>>> And below is my code.....
>>>>>
>>>>> public void onDraw(Canvas canvas) {
>>>>> super.onDraw(canvas);
>>>>> Bitmap arrow =
>>>>> BitmapFactory.decodeResource(getResources(),R.drawable.arrow);
>>>>> int arrowW = arrow.getWidth();
>>>>> int arrowH = arrow.getHeight();
>>>>> float scaleWidth = 1;
>>>>> float scaleHeight = 1;
>>>>> int centrex = arrowW/2;
>>>>> int centrey = arrowH/2;
>>>>> int X=108;
>>>>> int Y=100;
>>>>> int angle=0;
>>>>>
>>>>> Matrix matrix = new Matrix();
>>>>> matrix.postScale(scaleWidth, scaleHeight);
>>>>>
>>>>> matrix.postRotate(angle, X+centrex , Y+centrey );
>>>>> Bitmap resizedBitmap = Bitmap.createBitmap(arrow, 0, 0,
>>>>> arrow.getWidth(), arrow.getHeight(), matrix, true);
>>>>> canvas.save();
>>>>> canvas.drawBitmap(resizedBitmap, X, Y, null);
>>>>> invalidate();
>>>>> }
>>>>>
>>>>> I am getting the angle values from onCreate method.....Using
>>>>> orientation sensor(roll values)..
>>>>> But When I rotate the screen my image is rotating but not exactly
>>>>> around the image centre.....
>>>>>
>>>>> Thanks......
>>>>>
>>>>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en