For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > March 2005 > PictureBox rotation / XOR drawing









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PictureBox rotation / XOR drawing
Danny

2005-02-25, 4:03 pm


Is there a way to rotate an image in a PictureBox in 90 degree
increments or do I have to do it manually?

And while I'm at it, I need to XOR various guide lines and markers on
top of the image (and remove them easily, hence XOR) so I'd appreciate
any ideas on that as well.

Thanks!

Danny

(You guessed it! Remove NOSPAMFOR before emailing.)
Mike D Sutton

2005-02-25, 4:03 pm

> Is there a way to rotate an image in a PictureBox in 90 degree
> increments or do I have to do it manually?
>
> And while I'm at it, I need to XOR various guide lines and markers on
> top of the image (and remove them easily, hence XOR) so I'd appreciate
> any ideas on that as well.


You'll need to do this manually, I'm afraid. Rotating 180° or horizontal/vertical flips can be accomplished using
StretchBlt() with negative parameters however 90° rotation requires a more complex transformation. The "Image
translation class" demo on page has a somewhat slow implementation of this, or alternatively if you only need to support
Win2K/XP then have a look at the "Coordinate Spaces and Transformations" demo which offers a far more flexible
alternative.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/


Jeff Johnson [MVP: VB]

2005-02-25, 4:03 pm


"Danny" <NOSPAMFORdaniel_ahorn@yahoo.com> wrote in message
news:rgau115cc5bqetjno8v7nmiqdaldglf31c@
4ax.com...

> Is there a way to rotate an image in a PictureBox in 90 degree
> increments or do I have to do it manually?


There's no built-in method or property for this, no.

> And while I'm at it, I need to XOR various guide lines and markers on
> top of the image (and remove them easily, hence XOR) so I'd appreciate
> any ideas on that as well.


I recommend asking these questions in microsoft.public.vb.winapi.graphics


Mike D Sutton

2005-02-25, 4:03 pm

Erm.. And now, part two.. (hit send too soon and didn't respond to the second half ;)

> And while I'm at it, I need to XOR various guide lines and markers on
> top of the image (and remove them easily, hence XOR) so I'd appreciate
> any ideas on that as well.


If you're doing this in VB then set the DrawMode of the object you're working with to vbXorPen and draw your lines in
white, then when you're done set it back to vbCopyMode so as to not interfere with anything else you're drawing to it.
If you're using the API then have a look at the SetROP2() API call to change the draw mode, sending it R2_XORPEN will
put the DC into XOR drawing mode then R2_COPYPEN resets it back to the default.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/


Danny

2005-02-26, 4:00 pm

Date: Fri, 25 Feb 2005 15:46:51 -0000
Name: "Mike D Sutton" <EDais@mvps.org>

>
>You'll need to do this manually, I'm afraid. Rotating 180° or horizontal/vertical flips can be accomplished using
>StretchBlt() with negative parameters however 90° rotation requires a more complex transformation. The "Image
>translation class" demo on page has a somewhat slow implementation of this, or alternatively if you only need to support
>Win2K/XP then have a look at the "Coordinate Spaces and Transformations" demo which offers a far more flexible
>alternative.
>Hope this helps,


Thanks, Mike! I'm doing this on a W98. I've done this sort of rotation
before, so it's not such a big deal, but when a built-in feature is
available I prefer to use that in order to streamline the code.
Anyway, I'll have a look at your link.

Danny

(You guessed it! Remove NOSPAMFOR before emailing.)
Danny

2005-02-26, 4:00 pm

Date: Fri, 25 Feb 2005 10:48:30 -0500
Name: "Jeff Johnson [MVP: VB]" <i.get@enough.spam>

>
>"Danny" <NOSPAMFORdaniel_ahorn@yahoo.com> wrote in message
> news:rgau115cc5bqetjno8v7nmiqdaldglf31c@
4ax.com...
>
>
>There's no built-in method or property for this, no.


Time to put my thinking cap on! ;o)

But seriously, it's not that complicated.

>
>I recommend asking these questions in microsoft.public.vb.winapi.graphics


Right you are! There is a dedicated graphics group!

Anyway, loitering around help files I've since discovered that the
PaintPicture Method with vbSrcInvert opcode will essentially XOR.

Danny

(You guessed it! Remove NOSPAMFOR before emailing.)
Danny

2005-02-26, 4:00 pm

Date: Fri, 25 Feb 2005 15:53:16 -0000
Name: "Mike D Sutton" <EDais@mvps.org>

>Erm.. And now, part two.. (hit send too soon and didn't respond to the second half ;)
>
>
>If you're doing this in VB then set the DrawMode of the object you're working with to vbXorPen and draw your lines in
>white, then when you're done set it back to vbCopyMode so as to not interfere with anything else you're drawing to it.
>If you're using the API then have a look at the SetROP2() API call to change the draw mode, sending it R2_XORPEN will
>put the DC into XOR drawing mode then R2_COPYPEN resets it back to the default.
>Hope this helps,


Indeed it does! As I just mentioned to Jeff, in the meantime, I
discovered PaintPicture with vbSrcInvert but the above is much more
flexible.

Danny

(You guessed it! Remove NOSPAMFOR before emailing.)
Sam Hobbs

2005-03-01, 4:02 pm

"Danny" <NOSPAMFORdaniel_ahorn@yahoo.com> wrote in message
news:rgau115cc5bqetjno8v7nmiqdaldglf31c@
4ax.com...
>
> Is there a way to rotate an image in a PictureBox in 90 degree
> increments or do I have to do it manually?


Did you look in the KB? I don't know a lot about graphics, but KB article
"HOWTO: Rotate a Bitmap Image in 90-Degree Increments" sure sounds relevant.


Danny

2005-03-01, 4:02 pm

Date: Tue, 1 Mar 2005 05:18:50 -0800
Name: "Sam Hobbs" <samuel@social.rr.com_change_social_to_socal>

>"Danny" <NOSPAMFORdaniel_ahorn@yahoo.com> wrote in message
> news:rgau115cc5bqetjno8v7nmiqdaldglf31c@
4ax.com...
>
>Did you look in the KB? I don't know a lot about graphics, but KB article
>"HOWTO: Rotate a Bitmap Image in 90-Degree Increments" sure sounds relevant.


No, I didn't check the KB. I already implemented it but I'll have a
look anyway. Thanks as always!

Danny

(You guessed it! Remove NOSPAMFOR before emailing.)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com