Graphics.DrawImage upside down? (rotate 180 degrees)

G

Gina_Marano

Hey All,

Is it possible to draw an image upside down?

I am using Microsofts example of "Printing a local report without
preview".

The only trick is that I want to flip the image upside down.

Reason: I need to guarantee that I print a barcode in the exact same
location (lower right side) no matter the paper size. So if I flip the
image upside down (rotate 180) then the upper left corner will be my
fixed point.

Thoughts?

~Gina_M~
 
P

Peter Duniho

Hey All,

Is it possible to draw an image upside down?

You may want to look at the Graphics.Transform property. You could create
a transformation matrix that supplies the appropriate rotation, as well as
moving the origin to the opposite corner of the page. Then everything you
draw would as if you had just rotated the whole page 180 degrees.

Of course, do this only with those things you want to be rotated.
Otherwise, you might as well just physically rotate the paper when it's
finished printing. :)

All that said:
[...]
The only trick is that I want to flip the image upside down.

Reason: I need to guarantee that I print a barcode in the exact same
location (lower right side) no matter the paper size. So if I flip the
image upside down (rotate 180) then the upper left corner will be my
fixed point.

IMHO, if all you care about is the _position_ of the barcode, then
flipping it upside down is way more effort than you need to make. It's
trivial to find the lower right corner, and then create your drawing
rectangle based on that and the actual size of your bitmap, and doesn't
require any fiddling around with the transformation for the Graphics
instance.

Pete
 
D

David Pendrey

Gina_Marano said:
Hey All,

Is it possible to draw an image upside down?

I am using Microsofts example of "Printing a local report without
preview".

The only trick is that I want to flip the image upside down.

Reason: I need to guarantee that I print a barcode in the exact same
location (lower right side) no matter the paper size. So if I flip the
image upside down (rotate 180) then the upper left corner will be my
fixed point.

Thoughts?

~Gina_M~

FYI: A flip will not produce the same results as a 180 degree rotation.
It sounds like you want to make sure the bar code can be scanned from
the top left no matter which way up the paper is. If so then a 180
degree rotation will be the way to go as a flip will have the bar code
back to front.

It's a small difference but will make a large difference to your bar
code scanner.
 
G

Gina_Marano

FYI: A flip will not produce the same results as a 180 degree rotation.
It sounds like you want to make sure the bar code can be scanned from
the top left no matter which way up the paper is. If so then a 180
degree rotation will be the way to go as a flip will have the bar code
back to front.

It's a small difference but will make a large difference to your bar
code scanner.- Hide quoted text -

- Show quoted text -

Yes, rotating 180 degrees is what I meant. How would one do this?

Pete, the reason for the rotate is so I don't have to care about the
page length and width. I probably don't want to have to query the
printer to try and find out what size of paper is in tray 1... All I
care about is that the position of the barcode is in the same position
lower right hand corner of the paper regardless of papersize. Note: if
it where just the length that varies then I would just have to use a
report footer but after getting that working I realized that the width
could vary also.

Any ideas how one would rotate the image 180 degrees?

~Gina_M~
 
P

Peter Duniho

Pete, the reason for the rotate is so I don't have to care about the
page length and width. I probably don't want to have to query the
printer to try and find out what size of paper is in tray 1

You get the page size in the PrintPageEventArgs. There's no need to
"query the printer".
... All I
care about is that the position of the barcode is in the same position
lower right hand corner of the paper regardless of papersize.

Then look at the paper size in the PrintPageEventArgs and position the
barcode according to the paper size. It's no different than, for example,
drawing a footer on a printed page or anchoring a user-interface element
to the right and/or bottom of a window.
Note: if
it where just the length that varies then I would just have to use a
report footer but after getting that working I realized that the width
could vary also.

I don't know what a "report footer" is, but if you have that as an option,
why doesn't the "report footer" offer support for specifying alignment?
As in, make the element you want to include in the footer right-aligned,
so that it always winds up flush against the right side of the footer?
Any ideas how one would rotate the image 180 degrees?

Yes. I posted that information in my first reply. There are other ways,
but what I already wrote is the most straightforward, IMHO.

Pete
 
G

Gina_Marano

You get the page size in the PrintPageEventArgs. There's no need to
"query the printer".

Ahh, this is great!
Then look at the paper size in the PrintPageEventArgs and position the
barcode according to the paper size. It's no different than, for example,
drawing a footer on a printed page or anchoring a user-interface element
to the right and/or bottom of a window.
Great!

I don't know what a "report footer" is, but if you have that as an option,
why doesn't the "report footer" offer support for specifying alignment?
As in, make the element you want to include in the footer right-aligned,
so that it always winds up flush against the right side of the footer?

That would be nice but I have used many report builders and none that
I know of allow that. :(
Yes. I posted that information in my first reply. There are other ways,
but what I already wrote is the most straightforward, IMHO.

Yes, I figured it out. I was rendering to EMF then trying to rotate.
WRONG!! Much easier to render to BMP then simple rotate. :) As I have
said often, I make things too hard sometimes.

Thanks for your help! I will go through it and probably post a follow
up. I am having problems just printing a normal report as landscape.
More details soon.

~Gina_M~
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top