|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Blend multiple picturesHello,
Is it possible to blend more than two pictures into each other? Im using Alphablend to blend two pictures, but i dont get it working with more than two pictures! Can someone help me with this?? Thx Dennis > Is it possible to blend more than two pictures into each other? Im using How is this 'not working', and what code are you using to draw them? Is it that you're just not seeing the third image,> Alphablend to blend two pictures, but i dont get it working with more than > two pictures! Can someone help me with this?? or the output is garbage? Remember that if you're drawing three images on-top of one another each at 50% opacity then the bottom image will not be particularly visible, perhaps this is the cause of the problem? Draw image 1: Background: 50% Image 1: 50% Draw image 2: Background: 25% Image 1: 25% Image 2: 50% Draw image 3: Background: 12.5% Image 1: 12.5% Image 2: 25% Image 3: 50% To rectify this simply draw the first image at 100% opacity, the next at 50% and the third at 25% - you may want to play around with these values to get the desired result. The other option is to perform the blending yourself which would give you a perfect ratio between the three images. Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ I tried blending first two images in each other, and afterwards i blended
another picture to the two blended images. This resulted in a weird blueisch screen!? Can you perhaps give me an example, because im struggling with this problem for days, argh Thx in advance Dennis Show quoteHide quote "Mike D Sutton" wrote: > > Is it possible to blend more than two pictures into each other? Im using > > Alphablend to blend two pictures, but i dont get it working with more than > > two pictures! Can someone help me with this?? > > How is this 'not working', and what code are you using to draw them? Is it that you're just not seeing the third image, > or the output is garbage? Remember that if you're drawing three images on-top of one another each at 50% opacity then > the bottom image will not be particularly visible, perhaps this is the cause of the problem? > > Draw image 1: > Background: 50% > Image 1: 50% > > Draw image 2: > Background: 25% > Image 1: 25% > Image 2: 50% > > Draw image 3: > Background: 12.5% > Image 1: 12.5% > Image 2: 25% > Image 3: 50% > > To rectify this simply draw the first image at 100% opacity, the next at 50% and the third at 25% - you may want to play > around with these values to get the desired result. The other option is to perform the blending yourself which would > give you a perfect ratio between the three images. > Hope this helps, > > Mike > > > - Microsoft Visual Basic MVP - > E-Mail: ED***@mvps.org > WWW: Http://EDais.mvps.org/ > > > Im using the following code for blending 2 pictures:
################################################## Const AC_SRC_OVER = &H0 Private Type BLENDFUNCTION BlendOp As Byte BlendFlags As Byte SourceConstantAlpha As Byte AlphaFormat As Byte End Type Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long) Sub overlay () Picture1.Picture = LoadPicture(App.Path & "\" & "framevideo1_1.jpg") Picture2.Picture = LoadPicture(App.Path & "\" & "framevideo1_2.jpg") Picture1.Visible = False Dim BF As BLENDFUNCTION, lBF As Long 'Set the graphics mode to persistent Picture1.AutoRedraw = True Picture2.AutoRedraw = True 'API uses pixels Picture1.ScaleMode = vbPixels Picture2.ScaleMode = vbPixels 'set the parameters With BF .BlendOp = AC_SRC_OVER .BlendFlags = 0 .SourceConstantAlpha = 150 .AlphaFormat = 0 End With 'copy the BLENDFUNCTION-structure to a Long RtlMoveMemory lBF, BF, 4 'AlphaBlend the picture from Picture1 over the picture of Picture2 AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lBF End sub ##################################################### Which line do i have to adjust to mix more than two pictures?? Thx Dennis Show quoteHide quote "Dennis" wrote: > I tried blending first two images in each other, and afterwards i blended > another picture to the two blended images. This resulted in a weird blueisch > screen!? > Can you perhaps give me an example, because im struggling with this problem > for days, argh > > Thx in advance > Dennis > > > "Mike D Sutton" wrote: > > > > Is it possible to blend more than two pictures into each other? Im using > > > Alphablend to blend two pictures, but i dont get it working with more than > > > two pictures! Can someone help me with this?? > > > > How is this 'not working', and what code are you using to draw them? Is it that you're just not seeing the third image, > > or the output is garbage? Remember that if you're drawing three images on-top of one another each at 50% opacity then > > the bottom image will not be particularly visible, perhaps this is the cause of the problem? > > > > Draw image 1: > > Background: 50% > > Image 1: 50% > > > > Draw image 2: > > Background: 25% > > Image 1: 25% > > Image 2: 50% > > > > Draw image 3: > > Background: 12.5% > > Image 1: 12.5% > > Image 2: 25% > > Image 3: 50% > > > > To rectify this simply draw the first image at 100% opacity, the next at 50% and the third at 25% - you may want to play > > around with these values to get the desired result. The other option is to perform the blending yourself which would > > give you a perfect ratio between the three images. > > Hope this helps, > > > > Mike > > > > > > - Microsoft Visual Basic MVP - > > E-Mail: ED***@mvps.org > > WWW: Http://EDais.mvps.org/ > > > > > > > Im using the following code for blending 2 pictures: <code snipped>> Which line do i have to adjust to mix more than two pictures?? Without knowing what your source images look like, I can't solve the 'blueisch screen' problem, however if you blend two inverted images together you're more than likely going to get a greyish splodge so this could be the cause. Basically you just adjust your blend function for each image, here's a slightly easier function for creating the blend function DWord without requiring the UDT declaration or memory copy API: '*** Private Function CreateBlendOp(ByVal inSourceConstantAlpha As Byte, _ Optional ByVal inPerPixel As Boolean = False) As Long If (inPerPixel) Then CreateBlendOp = &H1000000 CreateBlendOp = CreateBlendOp Or (inSourceConstantAlpha * &H10000) End Function '*** The first picture should be rendered with 50% opacity (255/100)*50 = 128 and the next should be rendered with 25% opacity (255/100)*25 = 64. Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ Hello,
I solved the problem, i didnt declared that the Picture was working in pixels (vbPixels). At the moment im blending 10 pictures in each other. Im doing this by calling 10 functions with the different pictures. Is there a way to mix the pictures in one function (at once). So that i dont have to load every picture separate?? Thx Dennis Show quoteHide quote "Mike D Sutton" wrote: > > Im using the following code for blending 2 pictures: > <code snipped> > > Which line do i have to adjust to mix more than two pictures?? > > Without knowing what your source images look like, I can't solve the > 'blueisch screen' problem, however if you blend two inverted images together > you're more than likely going to get a greyish splodge so this could be the > cause. Basically you just adjust your blend function for each image, here's > a slightly easier function for creating the blend function DWord without > requiring the UDT declaration or memory copy API: > > '*** > Private Function CreateBlendOp(ByVal inSourceConstantAlpha As Byte, _ > Optional ByVal inPerPixel As Boolean = False) As Long > If (inPerPixel) Then CreateBlendOp = &H1000000 > CreateBlendOp = CreateBlendOp Or (inSourceConstantAlpha * &H10000) > End Function > '*** > > The first picture should be rendered with 50% opacity (255/100)*50 = 128 and > the next should be rendered with 25% opacity (255/100)*25 = 64. > Hope this helps, > > Mike > > > - Microsoft Visual Basic MVP - > E-Mail: ED***@mvps.org > WWW: Http://EDais.mvps.org/ > > > > I solved the problem, i didnt declared that the Picture was working in You could write your own blend function which takes the average of all the > pixels (vbPixels). > At the moment im blending 10 pictures in each other. Im doing this by > calling 10 functions with the different pictures. Is there a way to mix > the > pictures in one function (at once). So that i dont have to load every > picture > separate?? pixels at that position on each image, not sure if this is what you're after though. If you wanting a solution that blends 10 images in the same way as AlphaBlend() works between 2 then there is no such thing. Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ |
|||||||||||||||||||||||