Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rotate bitmap 5

Status
Not open for further replies.

ADoozer

Programmer
Dec 15, 2002
3,487
AU
ok, another simple one for someone,

im trying to rotate an image (selected with bitblt from a larger image) through 90° and 270° (and eventually 45°,135°,225°,315°)

can i do it with one of the raster ops (bitblt) or do i need a seperate API?

any input appreciated!

ps: i hate bitmaps!!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
hmmm... ok ive just come across something called PlgBlt, which
"copies a bitmap, transforming it into a parallelogram. This allows you to rotate a bitmap"
however thats all it says, and i cant see anything in the call that would cause a rotation?!?

any help still appreciated!!


If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
a----b
| |
| |
d----c

If a,b,c and d are the points representing the vertices of your source rectangle plgblt should allow you to move them like this (where a, b and c are the coordinates you need to pass in the lpPoint buffer of the function call:

a
/ d b
\ /
c
 
hmmm... it didnt rotate the bitmap, it just squashed it into a new shape!!

mypoints(0).x = 10
mypoints(0).y = 200

mypoints(1).x = 110
mypoints(1).y = 200

mypoints(2).x = 10
mypoints(2).y = 272

myresult = PlgBlt(frmPokerTable.hDC, mypoints(0), frmDeck.Picture1.hDC, MyCard.TLX, MyCard.TLY, CardWidth, CardHeight, 0, 0, 0)

cardwidth=72pixels
cardheight=100pixels
mycard.tlx=74
mycard.tly=102

any more pointers greatly appreciated!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
no worry... my coordinates are wrong (got my ABC wrong)

thnx strongm, a star for your efforts!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Oh, I guess it should be pointed out that PlgBlt is not supported under W95/98/Me
 
yeah.. i read that, its ok, its just a network game im knocking up, all my PCs are running 2k or XP!

thanks (on behalf of any readers, and myself i guess LOL) for the info!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Moving forward (to all those aditional rotations you want to do) you may find plgblt a little limiting. Another area you may therefore discover is the wondrous seeming SetWorldTransform. If you get it working properly from VB, do let us know, as I've never managed it...

DirectDraw is another area you could have a look at.
 
LOL if you cant get it workin i got no chance LOL

thanks for the extra reading material though [cry]

yeah directdraw, hmmm ill give that a miss for now, ive played around with it before in VB in the past to no suitable avail!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
damn you and your SetWorldTransform!!! [cry]

like i fool i decided to give it a try (see code below) however the code is supposed to rotate the picture 30° but instead it just translates it a few twips!!!!!

ARGGGGGHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!

Code:
Private Declare Function SetGraphicsMode Lib "gdi32" ( _
    ByVal hdc As Long, _
    ByVal iMode As Long _
) As Long

Private Declare Function SetWorldTransform Lib "gdi32" ( _
    ByVal hdc As Long, _
    lpXform As XFORM _
) As Long

Private Type XFORM
        eM11 As Double
        eM12 As Double
        eM21 As Double
        eM22 As Double
        eDx As Double
        eDy As Double
End Type

Private Const GM_ADVANCED = 2

Private Sub Command1_Click()
    Dim myXFORM As XFORM
    
    returned = SetGraphicsMode(Picture1.hdc, GM_ADVANCED)
    
    myXFORM.eM11 = 0.866   'cosine of rotation
    myXFORM.eM12 = 0.5     'sine of rotation
    myXFORM.eM21 = -0.5    'neg cosine of rotation
    myXFORM.eM22 = 0.866   'cosine of rotation
    myXFORM.eDx = 0
    myXFORM.eDy = 0
    
    returned = SetWorldTransform(Picture1.hdc, myXFORM)
    Picture1.Refresh
    
End Sub

im hoping its not a stupid picture box property incorrectly set...

any comments appreciated!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
i got it workin in C+, maybe its time to consider a change of language LOL

VB5: checked out the code, liked the code, probably going to use the code (not keen on the visible while drawing thing though) a star for you too! (wow, im on a star frenzy this week)

thanks both!

however if someone out there has a working example of setworldtransform (in VB) i/we would love to see it!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Yeah, as you've discovered it works fine in C++ or C. The exact same code, however, does not appear to work in VB...
 
Boy, this thread prompted me to revisit my SetWorldTransform code. And guess what? After months of banging my head against a brick wall I've got it to work properly...
 
Woohoo! I'm very happy! No more particularly nasty calculations or speed hits for rotating, shearing, mirroring bitmaps or GDI drawing operations!
 
do tell!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
It's a secret...

And, more to the point, I can't understand why I didn't try the necessary minor modification a long time ago.
 

Ah, was that before or after the pint?

It rotates fine for me and is fast, after a few mentioned modifications.
Actually it seems to spin somewhat...
Maybe things like this shouldn't be done after work hours....
 
Interestingly (well...maybe) I went out for a pint at lunch time, and figured out the change when I came back...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top