How to rotate an bitmap / image

107 views
Skip to first unread message

Phil

unread,
Jul 5, 2021, 12:40:51 AM7/5/21
to wxpython-users
Thank you for reading this.

I have a jpeg image that I'd like to rotate about it's bottom centre
point. It would also be helpful if I could set it's initial position on
the panel at the same point rather that it's default upper left point.

Also, would it better to work with an image or a bitmap?

This what I've been experimenting with:

class ImageFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Bitmap test")

        #img = wx.Image("test.jpg", wx.BITMAP_TYPE_JPEG)

        # if an image is the best option, how do I display it on the panel?

        # "test.jpg", wx.BITMAP_TYPE_JPEG), ConvertToBitmap() ?

        # if I do that then I'm still working with a bitmap, aren't I?

        bmp = wx.Bitmap('test.jpg')
        wx.StaticBitmap(self, -1, bmp, (20, 100))

        # position the bitmap by it upper left corner at 20, 100

    def rotate(angle):
        # pivot the bitmap on it's bottom centre point

Any code snippets or advice will be greatly appreciated.

--
Regards,
Phil

niki

unread,
Jul 5, 2021, 4:48:42 AM7/5/21
to wxpytho...@googlegroups.com
you can try:

bmp.GetImage().Rotate90(0)

HTH
Niki

Phil

unread,
Jul 5, 2021, 8:01:59 PM7/5/21
to wxpytho...@googlegroups.com
On 5/7/21 6:48 pm, niki wrote:
> you can try:
>
> bmp.GetImage().Rotate90(0)

Thank you Niki, unfortunately this generates the following error:

AttributeError: 'Bitmap' object has no attribute 'GetImage'

--

Regards,
Phil

Tim Roberts

unread,
Jul 5, 2021, 11:25:42 PM7/5/21
to wxpytho...@googlegroups.com, Phil
On 7/4/21 9:40 PM, Phil wrote:

>
> I have a jpeg image that I'd like to rotate about it's bottom centre
> point.

I'm going to focus on this for a moment, rather than the more important
questions you asked.

If you rotate an image 90 degrees around it's bottom center point, 3/4
of the image will be outside the bounding box.  In ASCII art:

+---+---+
| A | B |
+---+---+
| C | D |
+---+---+

Now, let's rotate 90 degrees clockwise about the bottom center (pretend
the letters are rotated, too):

+---+---+
|       |
+   +---+
|   | C | A
+---+---+
      D   B

See what I mean?  Are you sure you don't want to rotate around the center?

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Phil

unread,
Jul 6, 2021, 1:46:37 AM7/6/21
to Tim Roberts, wxpytho...@googlegroups.com
On 6/7/21 1:25 pm, Tim Roberts wrote:
> On 7/4/21 9:40 PM, Phil wrote:
>
>>
>> I have a jpeg image that I'd like to rotate about it's bottom centre
>> point.
>
> I'm going to focus on this for a moment, rather than the more
> important questions you asked.

Thank Tim for your explanation, however the pivot point is the bottom
centre of the bitmap rather than the centre of the bitmap. For example,
say I wanted to rotate a vertical line|

                           |

                         x

with x being the pivot point like this.   \        /

                  \    /

                x

That might be 10 degrees either side of 90 degrees.

If it's possible I'd like the pivot point (x) to be the x, y coordinates
where the bitmap is placed on the frame rather that it's default upper
left hand corner.

I hope my explanation and poor graphics are understandable.

--

Regards,
Phil

Reply all
Reply to author
Forward
0 new messages