From: Bee on 11 Dec 2009 20:27 I am still working the first post using regions. The second post is under study. Marching ants are nice but i have no idea how to flip them when I flip the image. The only problem with the first post is in regards to flipping the sprite hoz or vert. I am using StretchBlt to do this but here is what is happening. Maybe this will trigger an oh yeah and have a simple answer. When i flip the mask it looks correct. When i flip the sprite the image flips but the image does not copy from an image area into a black area so the black area remains and the image is "clipped". So there must be a simple fix that I cannot figure out.
From: Mike Williams on 12 Dec 2009 09:19 "Bee" <Bee(a)discussions.microsoft.com> wrote in message news:6B144B30-2E74-4762-B572-E8E3B3144CF4(a)microsoft.com... > I am still working the first post using regions. The second post > is under study. Marching ants are nice but i have no idea > how to flip them when I flip the image. Actually flipping an irregular shaped sprite and mask image is fairly easy but flipping the marching ants surrounding it requires a bit more thought, because they are drawn using the Polygon API. One way is to add code to effectively "flip" the POINTAPI data (apart from the original starting position data item) so that the Polygon API draws a flipped copy of the original polygon. This of course will cause the flipped polygon to be drawn at the correct flipped shape but at the wrong position, so you also need to offset the viewport origin just before your call to Polygon by a calculated amount which is a function of the width of the sprite and the relative position of the first data item in the POINTAPI array. You only need to flip the polygon once of course, at the time that you flip the sprite and mask, and thereafter you can use the "sprite and marching ants" animation (mouse dragging) as normal. It's easy to get wrong though and it requires a bit of thought, and often a bit of trial and error as well ;-) I'll post an example for you when you are ready, but since you have said you are working on the original PolyRegion code example (in which as far as I recall I did not include a sprite flipping facility) and since the flipping of the sprite and mask data appears to be currently the part of your question that you most want answering, I'll concentrate on that first . . . > The only problem with the first post is in regards to flipping > the sprite hoz or vert. I am using StretchBlt to do this but here > is what is happening. Maybe this will trigger an oh yeah and > have a simple answer. When i flip the mask it looks correct. > When i flip the sprite the image flips but the image does not > copy from an image area into a black area so the black area > remains and the image is "clipped". So there must be a simple > fix that I cannot figure out. I'm not really sure what you mean by that. If you posted your code, and perhaps a screen dump of the sprite and mask both before and after flipping, then I would be more easily able to see what you mean. If you're talking about just a pixel or two then it might be that you are using slightly incorrect parameters in the call to StretchBlt (in fact as I recall one of the examples I posted had a "one pixel" problem, although I haven't checked back through the group looking for it so I may not have done so). Also, of course, it is far simpler if both the Sprite and Mask DCs are borderless, otherwise you will have to mess about taking the borders into account. Here is the code I am currently using myself for an X flip, which you can compare to your own: If flipX = True Then StretchBlt picMask.hdc, spriteWide - 1, 0, -spriteWide, _ spriteHigh, picMask.hdc, _ 0, 0, spriteWide, spriteHigh, vbSrcCopy StretchBlt picSprite.hdc, spriteWide - 1, 0, -spriteWide, _ spriteHigh, picSprite.hdc, _ 0, 0, spriteWide, spriteHigh, vbSrcCopy End If The only problem with the above code, which I intend to change, is that in each case it flips the bitmap "in situ". In other words, in the call to StretchBlt the destination DC and the source DC are the same. It does actually work on both of the systems I am currently using, but personally I've never been happy with using the same DC for both source and destination in an operation which involves changing the entire contents of the bitmap (as does a flip) because it relies too heavily on the details of underlying StretchBlt algorithm and there is a chance that it might work on some systems and fail on others (unless anybody knows if there is any MS documentation to the contrary?). It is therefore probably better to use StretchBlt to flip the bitmap into another similarly sized temporary bitmap and then use a simple BitBlt to transfer the result from the temporary DC back into the original DC, so (where picTemp is another PictureBox of the same szie as the sprite and mask) you would have something like (air code!): If flipX = True Then StretchBlt picTemp.hdc, spriteWide - 1, 0, -spriteWide, _ spriteHigh, picMask.hdc, _ 0, 0, spriteWide, spriteHigh, vbSrcCopy BitBlt picMask.hdc, 0, 0, spriteWide, spriteHigh, _ picTemp.hdc, 0, 0, vbSrcCopy StretchBlt picTemp.hdc, spriteWide - 1, 0, -spriteWide, _ spriteHigh, picSprite.hdc, _ 0, 0, spriteWide, spriteHigh, vbSrcCopy BitBlt picSprite.hdc, 0, 0, spriteWide, spriteHigh, _ picTemp.hdc, 0, 0, vbSrcCopy End If Anyway, post again if you are still having problems. Mike
From: Bee on 12 Dec 2009 12:49 pardon my ignorance. how do I post the images? I hate to impose and email directly to you so I have avoided that thinking that is not good form. the code I have is dispersed through out my app so i am not sure how to do that without introducing confusion to both of us. as far as the image mask goes, it seems to flip OK. the sprite image seems to fold itself over in the middle such that the black area on the right is now overlayed on the left. so an irregular shaped mask now become symmetrical about the center (based on a horz flip). Same kind of thing happens on a vert flip.
From: Mike Williams on 12 Dec 2009 15:34 "Bee" <Bee(a)discussions.microsoft.com> wrote in message news:2C6B4DE2-75C2-4E8C-A83B-3F33397E798A(a)microsoft.com... > pardon my ignorance. how do I post the images? > I hate to impose and email directly to you so I have > avoided that thinking that is not good form Ideally of course they should be hosted on the web somewhere and a link to the file posted on the newsgroup, so that anyone else following the thread can also see them (posting attachments to the newsgroup itself is frowned upon, and doesn't always work anyway). If you have your own web page, or if perhaps your ISP gives you a free web page facility, then you can host the images on the page and post a link to it. In fact I think there some sites out there that allow you to upload images or other files to their own servers for free and they'll host them for you, although I've never used any of them myself so I don't know how useful they are. Otherwise, if you can't do any of those things then you can always email me. If you post your real email address then I'll let you know mine, and then you can mail me the images. > the code I have is dispersed through out my app so > i am not sure how to do that without introducing > confusion to both of us. You only need to post the relevant parts of the code, specifically just the part that contains your two StretchBlt functions which flip the images (mask and sprite) together with the declarations for any variables they use and details of the values that are assigned to them, and of course details of the size of the PictureBoxes involved. > the sprite image seems to fold itself over in the middle such > that the black area on the right is now overlayed on the left. > so an irregular shaped mask now become symmetrical about > the center (based on a horz flip). Did you try my previous suggestion when I said that instead of using the same hDC for both the source and destination DC in your call to StretchBlt you should instead flip the sprite into an otherwise unused Autoredraw PictureBox (picTemp) of the same size, and then blit the contents of picTemp to the sprite picture box? Have you tried that? Also, have you properly checked the values you are using in the StretchBlt call? Post the relevant code sample. Mike
From: Bee on 12 Dec 2009 19:01 Here is the flip routine. It works fine for all other image flip operations. I am in the process of coding the last suggestion. Public Function PictureBoxFlip(PicBox As PictureBox, ByVal eFlip As eFlipEnum) As Boolean ' flip horz and/or flip vert On Error GoTo PictureBoxFlipErr Dim lW As Long Dim lH As Long Dim lRet As Long Dim lX As Long Dim lY As Long Dim lWA As Long ' width adjust Dim lHA As Long ' height adjjust ' make sure PicBox.ScaleMode = vbPixels ' pixels lW = IIf((eFlip And eFlipHorizontal) = eFlipHorizontal, -1, 1) lH = IIf((eFlip And eFlipVertical) = eFlipVertical, -1, 1) ' lRet = SetStretchBltMode(PicBox.hdc, STRETCH_DELETESCANS) ' STRETCHMODE) ' If lW < 0 Then lX = PicBox.ScaleWidth lWA = 1 Else lX = 0 End If If lH < 0 Then lY = PicBox.ScaleHeight lHA = 1 Else lY = 0 End If PictureBoxFlip = (StretchBlt(PicBox.hdc, (lX - lWA), (lY - lHA), (lW * PicBox.ScaleWidth), (lH * PicBox.ScaleHeight), PicBox.hdc, 0, 0, PicBox.ScaleWidth, PicBox.ScaleHeight, vbSrcCopy) = 1) PicBox.AutoRedraw = False PicBox.AutoRedraw = True PicBox.Refresh PictureBoxFlipExit: Exit Function PictureBoxFlipErr: Resume PictureBoxFlipExit End Function 'PictureBoxFlip "Mike Williams" wrote: > "Bee" <Bee(a)discussions.microsoft.com> wrote in message > news:2C6B4DE2-75C2-4E8C-A83B-3F33397E798A(a)microsoft.com... > > > pardon my ignorance. how do I post the images? > > I hate to impose and email directly to you so I have > > avoided that thinking that is not good form > > Ideally of course they should be hosted on the web somewhere and a link to > the file posted on the newsgroup, so that anyone else following the thread > can also see them (posting attachments to the newsgroup itself is frowned > upon, and doesn't always work anyway). If you have your own web page, or if > perhaps your ISP gives you a free web page facility, then you can host the > images on the page and post a link to it. In fact I think there some sites > out there that allow you to upload images or other files to their own > servers for free and they'll host them for you, although I've never used any > of them myself so I don't know how useful they are. Otherwise, if you can't > do any of those things then you can always email me. If you post your real > email address then I'll let you know mine, and then you can mail me the > images. > > > the code I have is dispersed through out my app so > > i am not sure how to do that without introducing > > confusion to both of us. > > You only need to post the relevant parts of the code, specifically just the > part that contains your two StretchBlt functions which flip the images (mask > and sprite) together with the declarations for any variables they use and > details of the values that are assigned to them, and of course details of > the size of the PictureBoxes involved. > > > the sprite image seems to fold itself over in the middle such > > that the black area on the right is now overlayed on the left. > > so an irregular shaped mask now become symmetrical about > > the center (based on a horz flip). > > Did you try my previous suggestion when I said that instead of using the > same hDC for both the source and destination DC in your call to StretchBlt > you should instead flip the sprite into an otherwise unused Autoredraw > PictureBox (picTemp) of the same size, and then blit the contents of picTemp > to the sprite picture box? Have you tried that? Also, have you properly > checked the values you are using in the StretchBlt call? Post the relevant > code sample. > > Mike > > > . >
|
Next
|
Last
Pages: 1 2 3 Prev: New problem installing VB6 on Win7 64 bit Next: converting doubles to string |