Problems with Blit

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
rsb
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri May 29, 2015 7:26 pm

Problems with Blit

Post by rsb » Fri Jan 03, 2020 9:02 pm

Hello,

I'm using the wxPdfDC Blit method to print an arc outline. It works perfectly when I print to the screen using wxDC but when
I print to a PDF using the wxPdfDC , it displays a black rectangle with the arc inside.

How do I blit to pdf so the bitmap rectangle background is transparent. I'm using the Alpha channel to make the
pixels inside the arc and outside the arc outline transparent.

See attached images.

Thank you.
RSB
Attachments
ArcPDF.PNG
ArcPDF.PNG (12.29 KiB) Viewed 871 times
ArcScreen.PNG
ArcScreen.PNG (5.77 KiB) Viewed 871 times

utelle
Moderator
Moderator
Posts: 927
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Problems with Blit

Post by utelle » Sat Jan 04, 2020 8:41 am

rsb wrote:
Fri Jan 03, 2020 9:02 pm
I'm using the wxPdfDC Blit method to print an arc outline. It works perfectly when I print to the screen using wxDC but when
I print to a PDF using the wxPdfDC , it displays a black rectangle with the arc inside.
Please keep in mind that PDF is a vector graphics format, while on screen you have a pixel graphics format. Blit only works on pixel graphics. That is, you may Blit from a screen wxDC to wxPdfDC, but Blit from wxPdfDC to wxPdfDC is not supported, because PDF does not have a pixel graphic from which you could Blit.
rsb wrote:
Fri Jan 03, 2020 9:02 pm
How do I blit to pdf so the bitmap rectangle background is transparent. I'm using the Alpha channel to make the
pixels inside the arc and outside the arc outline transparent.
Why don't you draw the arc outline directly? I really don't understand why you need a Blit operation for this purpose.

rsb
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri May 29, 2015 7:26 pm

Re: Problems with Blit

Post by rsb » Mon Jan 06, 2020 5:41 pm

Thanks Utelle,
Utelle wrote: |
Please keep in mind that PDF is a vector graphics format, while on screen you have a pixel graphics format.
Okay.
Utelle wrote: |
Why don't you draw the arc outline directly?
We're trying to draw the outline of the arc only as in the second picture with the internal pixels transparent.
Is there an easy way to do this?

Thanks.

utelle
Moderator
Moderator
Posts: 927
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Problems with Blit

Post by utelle » Mon Jan 06, 2020 6:30 pm

rsb wrote:
Mon Jan 06, 2020 5:41 pm
We're trying to draw the outline of the arc only as in the second picture with the internal pixels transparent.
Is there an easy way to do this?
In principle it should be possible to achieve this by using the wxDC::DrawArc method.
Could you please provide some code how you currently produce the intended graphic? Then I might be able to show a way how to accomplish the same result with wxPdfDC.

rsb
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri May 29, 2015 7:26 pm

Re: Problems with Blit

Post by rsb » Mon Jan 06, 2020 8:04 pm

See attached file. Basically it draws a filled arc, then sets all pixels inside the arc
outline to transparent.

I was able to get this to work by using DrawBitmap instead of Blit but it's very slow.

Thanks very much.
Attachments
draw_arc_outline.txt
(4.95 KiB) Downloaded 18 times

utelle
Moderator
Moderator
Posts: 927
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Problems with Blit

Post by utelle » Mon Jan 06, 2020 8:50 pm

rsb wrote:
Mon Jan 06, 2020 8:04 pm
See attached file. Basically it draws a filled arc, then sets all pixels inside the arc
outline to transparent.
As said pixel operations won't work for wxPdfDC.
rsb wrote:
Mon Jan 06, 2020 8:04 pm
I was able to get this to work by using DrawBitmap instead of Blit but it's very slow.
I'll take a look. If I can come up with a feasible approach I'll let you know. Please allow some time for further inspection.

utelle
Moderator
Moderator
Posts: 927
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Problems with Blit

Post by utelle » Tue Jan 07, 2020 6:34 pm

I would recommend that you explicitly draw the outline of the requested arc. For this you will have to determine the start and end points for the inner and outer outline of the arc (depending on the path width of the arc) using an appropriate line width.

Code: Select all

DrawArc(startXouter, startYouter, endXouter, endYouter, centerX, centerY);
DrawArc(startXinner, startYinner, endXinner, endYinner, centerX, centerY);
Additionally, for connecting the end points of the inner and outer arc you need to determine the cap style, that is, you connect the points either with straight lines or half circles.

This approach allows you to get rid of bitmap operations which are not supported for wxPdfDC.

rsb
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri May 29, 2015 7:26 pm

Re: Problems with Blit

Post by rsb » Fri Jan 10, 2020 3:15 pm

Thanks Utelle,

The approach you recommended is what we were doing, it looks good in PDF but not good
when drawing to the screen using a wxDC which is why we were looking for a new solution.
It's really hard to get the end caps (half circles) to line up with the arc endpoints.

So we will just use one method (your method) for PDF and another method (Bitmap/Image) for
drawing to the screen.

Thanks for looking at this!

RSB

utelle
Moderator
Moderator
Posts: 927
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Problems with Blit

Post by utelle » Fri Jan 10, 2020 4:53 pm

rsb wrote:
Fri Jan 10, 2020 3:15 pm
The approach you recommended is what we were doing, it looks good in PDF but not good
when drawing to the screen using a wxDC which is why we were looking for a new solution.
It's really hard to get the end caps (half circles) to line up with the arc endpoints.
Yes, due to the integer coordinate system of wxDC such operations can get very difficult.

Most likely using wxGraphicsContext would be easier. However, up to now wxPdfDocument does not yet offer support for wxGraphicsContext, although this task has been on my to-do list for quite a long time.
rsb wrote:
Fri Jan 10, 2020 3:15 pm
So we will just use one method (your method) for PDF and another method (Bitmap/Image) for
drawing to the screen.
That's probably the best possible approach for now.
rsb wrote:
Fri Jan 10, 2020 3:15 pm
Thanks for looking at this!
You are welcome.

Post Reply