Hello,
I recently changed my code that used wxMemoryDC to use wxGraphicsContext and get anti-aliasing support.
It works great and the change from wxMemoryDC to wxGraphicsContext is quite simple since the methods
are rather similar.
Everything was fine until I made the changes on text drawing:
My problem is that I don't find any SelectoObject method to use
the same approach than with wxMemoryDC.
Any idea?
Many thanks for your help.
Pascal
From wxMemoryDC to wxGraphicsContext with a small issue
Re: From wxMemoryDC to wxGraphicsContext with a small issue
I don't understand what you're looking for. wxGraphicsContext does have a DrawText method, but that's easy to find, so that's probably not what you mean.
Use the source, Luke!
Re: From wxMemoryDC to wxGraphicsContext with a small issue
Sorry, I was not clear.
I want to draw some text over an image, so I use a bitmap for it.
With the wxMemoryDC dc, I used to attach the dc to the bitmap:
Everything seems the same with wxGraphicsContext but there is not SelectObjet method.
So I'm a bit lost. I guess it's not the same principle.
I hope I was more clear. Thank you Doublemax for your time.
Pascal
I want to draw some text over an image, so I use a bitmap for it.
With the wxMemoryDC dc, I used to attach the dc to the bitmap:
Code: Select all
wxBitmap myBitmap = wxBitmap(myWxImage, -1) ;
wxMemoryDC dc ;
dc.SelectObject(myBitmap) ;
...
dc.DrawText(...) ;
...
myWxImage = myBitmap.ConvertToImage() ;
So I'm a bit lost. I guess it's not the same principle.
I hope I was more clear. Thank you Doublemax for your time.
Pascal
Re: From wxMemoryDC to wxGraphicsContext with a small issue
There are several ways you can create a wxGraphicsContext.
In your case there are two versions you can use:
Create wxGraphicsContext to draw into a wxMemoryDC:
http://docs.wxwidgets.org/trunk/classwx ... 2dc0686e2e
Create wxGraphicsContext to draw into a wxImage:
http://docs.wxwidgets.org/trunk/classwx ... 2e8cda964c
In your case there are two versions you can use:
Create wxGraphicsContext to draw into a wxMemoryDC:
http://docs.wxwidgets.org/trunk/classwx ... 2dc0686e2e
Create wxGraphicsContext to draw into a wxImage:
http://docs.wxwidgets.org/trunk/classwx ... 2e8cda964c
Use the source, Luke!
Re: From wxMemoryDC to wxGraphicsContext with a small issue
OOps, I have understood my error:
I must keep on using wxMemoryDC::SelectObject
and do all the rest with the wxGraphicsContext.
It works well like this.
Thanks,
Pascal
I must keep on using wxMemoryDC::SelectObject
and do all the rest with the wxGraphicsContext.
It works well like this.
Thanks,
Pascal
Re: From wxMemoryDC to wxGraphicsContext with a small issue
Our posts crossed.
Thanks Doublemax for your help.
Regards,
Pascal
Thanks Doublemax for your help.
Regards,
Pascal
Re: From wxMemoryDC to wxGraphicsContext with a small issue
Your code looks like you want to draw into a wxImage. In that case the second version might be better, because it saves you the conversion from wxImage to wxBitmap and back.
Use the source, Luke!
Re: From wxMemoryDC to wxGraphicsContext with a small issue
You're right, it will be more simple and faster!
I'm going to try (tomorrow morning) and will let you know.
Many thanks for your advice and your very fast availability!
Pascal
I'm going to try (tomorrow morning) and will let you know.
Many thanks for your advice and your very fast availability!
Pascal
Re: From wxMemoryDC to wxGraphicsContext with a small issue
Hi Doublemax,
So, as you proposed, I created my graphics context from the image and of course it works pretty well:
My comments about this version:
- The process is not faster (I'm on Windows)
- The code is more readable / lighter
- Don't forget to gc->Flush() when you have finished to use the gc in order to update the image.
Good day!
Pascal
So, as you proposed, I created my graphics context from the image and of course it works pretty well:
Code: Select all
wxGraphicsContext *gc = wxGraphicsContext::Create(myWxImage) ;
- The process is not faster (I'm on Windows)
- The code is more readable / lighter
- Don't forget to gc->Flush() when you have finished to use the gc in order to update the image.
Good day!
Pascal