Results 1 to 27 of 27

Thread: VB6: GDIPLUS - how change pixels colors on a faster way

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    VB6: GDIPLUS - how change pixels colors on a faster way

    using GDIPLUS, how can i change the pixel colors(or swap colors) on a faster way?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Well, one obvious way is to use GdipSetImageAttributesRemapTable():

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim ColorMap(5) As Long
    
        ScaleMode = vbPixels
        AutoRedraw = True
    
        With New AlphaPic
            .LoadBitmap "sample.png"
            .Render Me, 20, 20
            ColorMap(0) = &HFFFF0000
            ColorMap(1) = &HFFFFFF00
            ColorMap(2) = &HFF008000
            ColorMap(3) = &HFFFF8000
            ColorMap(4) = &HFF00FFFF
            ColorMap(5) = &HFFFFE000
            .SetColorMap ColorMap
            .RotateFlip RotateNoneFlipX
            .Render Me, ScaleWidth - .Width - 20, 20
        End With
    
        AutoRedraw = False
    End Sub
    Name:  sshot.png
Views: 925
Size:  3.9 KB

    But I'm just a plinker when it comes to graphics. Maybe somebody else can suggest another option?
    Attached Files Attached Files

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    how works 'ColorMap'(i don't know that hexadecimal values)?
    ok.. the AlphaPic is a class(not tested the project)...
    i need ask more 1 thing: the GdipBitmapGetPixel() and GdipBitmapSetPixel(), must use GdipBitmapUnlockBits() GdipBitmapLockBits for work?
    i need create a function, too, for rotate pixel a pixel.. but i need to understand the speed for i use more than 10 images rotation without problems
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Between “I don’t know these hex values” and “Need to rotate an image fast” there is a chasm of hard mental work unfortunately.

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    ColorMap() is an array of pairs of ARGB colors, each pair being "old color" and "new color" to substitute.

    Not sure why you want to pixel-fiddle. I thought you wanted fast.

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    "ColorMap() is an array of pairs of ARGB colors, each pair being "old color" and "new color" to substitute."
    but i don't know how works
    "Not sure why you want to pixel-fiddle. I thought you wanted fast."
    is there a way for i rotate it using X,Y and Z rotation?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Image recognition, color replacement is more difficult

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Again, I'm just winging it here, but rotation seems simple enough.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim ColorMap(5) As Long
    
        ScaleMode = vbPixels
        AutoRedraw = True
    
        With New AlphaPic
            .LoadBitmap "sample.png"
            .Render Me, 40, 20
            ColorMap(0) = &HFFFF0000
            ColorMap(1) = &HFFFFFF00
            ColorMap(2) = &HFF008000
            ColorMap(3) = &HFFFF8000
            ColorMap(4) = &HFF00FFFF
            ColorMap(5) = &HFFFFE000
            .SetColorMap ColorMap
            .RenderRotated Me, _
                           230, _
                           ScaleWidth - .Width - 40, _
                           20 + (.Height - .Height * 3 \ 4) \ 2, _
                           .Width * 3 \ 4, _
                           .Height * 3 \ 4
        End With
    
        AutoRedraw = False
    End Sub
    Name:  sshot.png
Views: 888
Size:  6.9 KB

    Rotated 230 degrees, offset so it all fits in the Form, scaled to 3/4 size.


    As far as I know there is no 3D support in GDI+ so it can only rotate around the Z axis, not the X or Y axes. Maybe someone else can correct me.
    Attached Files Attached Files

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Quote Originally Posted by joaquim View Post
    how works 'ColorMap'(i don't know that hexadecimal values)?
    ok.. the AlphaPic is a class(not tested the project)...
    Valuable reference for GDI+ functions: http://www.jose.it-berater.org/gdiplus/iframe/index.htm
    Looking at GdipSetImageAttributesRemapTable the last parameter is an array of COLORMAP structures.
    Code:
    TYPE ColorMap
        oldColor AS Long
        newColor AS Long
    END TYPE
    That structure is simply 2 color values (including the alpha byte) as dilettante described earlier. You can substitute a 1D array of longs or a 2D array of longs, etc. Depends on what you prefer and how you define the parameter in the API declaration.

    i need ask more 1 thing: the GdipBitmapGetPixel() and GdipBitmapSetPixel(), must use GdipBitmapUnlockBits() GdipBitmapLockBits for work?
    If using that site I linked to above, you'll see that Get/Set pixel GDI+ functions want the GDI+ image handle. Therefore, GdipBitmapLockBits isn't needed. If a GDI+ function needs GdipBitmapLockBits to be called, you'll see a parameter described as a pointer to an array of bytes/data. Take care to look at the descriptions of parameters, not just their variable types.

    i need create a function, too, for rotate pixel a pixel.. but i need to understand the speed for i use more than 10 images rotation without problems
    Speed will be likely dependent on available memory, size of images, alpha blending, and any other attributes rendered with the image as it is rotated. Since the calls are synchronous, image 2 waits for image 1 to be done rotating and so on. The pixel format of the images may also determine overall speed. If images are already in pre-multiplied format, you may get faster overall results.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Yeah, here is a test with multiple images drawn rotating in an animated fashion. There is clearly some flicker, so optimization might be needed for a real program. For example a single canvas Graphics object could be created then everything drawn rotated, better double-buffering used, etc.

    Code:
    Option Explicit
    
    Private AlphaPic(1) As AlphaPic
    Private Rotation As Single
    
    Private Sub Form_Load()
        Dim ColorMap(3) As Long
    
        AutoRedraw = True
        Set AlphaPic(0) = New AlphaPic
        With AlphaPic(0)
            .LoadBitmap "sample.png"
            Set AlphaPic(1) = New AlphaPic
            With AlphaPic(1)
                .CloneBitmap AlphaPic(0)
                ColorMap(0) = &HFFFF0000
                ColorMap(1) = &HFFFFFF00
                ColorMap(2) = &HFFFFC080
                ColorMap(3) = &HFFC0FF00
                .SetColorMap ColorMap
                .StretchBitmap .Width / 2, .Height / 2
            End With
            .StretchBitmap .Width / 2, .Height / 2
        End With
        With Timer1
            .Interval = 40
            .Enabled = True
        End With
    End Sub
    
    Private Sub Timer1_Timer()
        Rotation = (Rotation + 1) Mod 360
        Cls
        AlphaPic(0).RenderRotated Me, Rotation, 20, 20
        AlphaPic(1).RenderRotated Me, -Rotation, 120, 20
        AlphaPic(0).RenderRotated Me, Rotation, 220, 20
        AlphaPic(1).RenderRotated Me, -Rotation, 20, 120
        AlphaPic(0).RenderRotated Me, Rotation, 120, 120
        AlphaPic(1).RenderRotated Me, -Rotation, 220, 120
        AlphaPic(0).RenderRotated Me, Rotation, 20, 220
        AlphaPic(1).RenderRotated Me, -Rotation, 120, 220
        AlphaPic(0).RenderRotated Me, Rotation, 220, 220
    End Sub
    Name:  sshot.png
Views: 917
Size:  7.4 KB
    Attached Files Attached Files

  11. #11

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    dilettante: correct me 1 thing: the GDIPLUS rotation can use Z and Y?
    LaVolpe: thank you.. now i get it.. thank you
    VB6 2D Sprite control

    To live is difficult, but we do it.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    No. It rotates around the Z axis in the XY plane only. At least as far as I can tell.


  13. #13
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Since this is an ongoing long term project, people responding need to understand that when joaquim is referring to Rotation, he is not talking about a 2D rotation.
    He is talking about a 3D rotation, and not only a 3D rotation, but then a projection of the 3D coordinates into 2D with perspective.
    The desire has been to have for instance a wall with a texture on it, and then to rotate and project the view of the wall from different positions and angles.

    Currently he can rotate four points of a rectangle in 3D and project the rectangle to a trapezoid, with the narrow end of the trapezoid being further away along the Z-Axis.
    Not having found a way to fill that trapezoid with depth correlated texture mapping (in a way that he can understand), it sounds like now he is thinking about 3D rotating every point that makes up the plane, i.e. loop through every X and Y coordinate of the image along with the Z depth of the image, apply a 3D rotation of the point and project it to an 2D image coordinate, then color the resulting 2D image coordinate addressed pixel with the color of the original texture pixel color that was the source of the point.

    So, the question is how to quickly copy a pixel from one image to another, or in other words change the color of a pixel to match the color of a pixel in another bitmap. The use of the word "swap" is likely a language misleading translation of what he want.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  14. #14
    Fanatic Member
    Join Date
    Nov 2018
    Posts
    602

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Just throwing some ideas out there (not even sure this would work)

    Use paths to define his textures for floors, walls, etc

    Then create a "perspective" of these textured paths using GdipWarpPath
    http://www.jose.it-berater.org/smffo...p?topic=1787.0

    Then rotate the textured path using GdipTransformPath (or any of the other of myriad of path functions)

  15. #15
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    You can use GdipWarpPath to warp the path with perspective, but as far as I know (boops boops played around with this a bit on the .Net side), you can't get the image to warp with perspective, i.e. if you filled the path with a texture, the texture itself wouldn't be warped, it would just fill the warped path.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  16. #16
    Fanatic Member
    Join Date
    Nov 2018
    Posts
    602

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    I was thinking the texture, would also be rendered via paths (and then colored).
    ie a path for an individual "brick" say on a floor tile, and these paths would be replicated to completely fill a floor tile (or the whole floor).

    I'm just thinking out load, not ever having done this.

  17. #17
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Well, I guess that could be interesting to play with. It would be convenient if the various shapes added to a path could be individually colored, so you draw your texture as one path.
    It sounds like your suggestion is to say the brick isn't a single path created using multiple shapes, but would be multiple paths, with multiple shapes, so each path could be colored independently.

    An issue, I think, might be that if a Brick was constructed from 20 paths, so you can have a mix of 20 colors within the brick for texturing, you would have to warp the 20 paths individually for each brick when rendering. If you used 200 bricks to create a section of wall, then you're warping 4000 paths for one wall.

    Like I said, could be interesting to play around with, just to see what it looks like, but likely to be slow in the long run.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  18. #18
    Fanatic Member
    Join Date
    Nov 2018
    Posts
    602

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    I was thinking only one call to WarpPath

    Something like:
    GdipCreatePath FLOOR
    GdipAddPathPath BRICK1 to FLOOR
    GdipAddPathPath BRICK2 to FLOOR
    GdipAddPathPath BRICK3 to FLOOR
    etc
    GdipWarpPath FLOOR

    I should perhaps test first, because this might not even work,
    or might work, but be useless for what joaquim is trying to accomplish.

    As I said, I was just throwing out ideas

  19. #19
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    I once thought about warping images via GDI+ paths. As we know, we can't do it directly because a path can't be created from an image like a brush can. However, we could dissolve the image into 1-pixel path line segments and then warp that? I just never got motivated enough to try it. If it does work, not sure how efficient it would be for rendering/animating.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  20. #20
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    I figured even if you didn't go down to 1-pixel path segments, is that the path has to be rendered in one color, so it doesn't matter if the path is one line segment or a thousand, it is one path and one color. Not useful for mapping a bitmap into runs of color.

    I haven't played with paths much, so wasn't aware of adding a path to a path. If I wasn't so busy with other things, I guess I would take the time to play with it now, but I can't afford it at the moment.
    I guess if adding a path to a path, accumlates into in a really large path, then you still have the coloring issue, i.e. one path, one color.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  21. #21
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    @passel. The issue isn't necessarily colors as much as efficiency I would think.

    We can iterate the segments of a path, in order added to the path. We can use GdipDrawLine to render the individual segments -- but need a way to map or cross-reference colors per segment. Maybe a map is simply the path segment ordinal, i.e., 1st segment is 1st pixel of bitmap, last segment is last pixel of bitmap.

    Just thinking out loud. As noted before, personally not that motivated to play with warping an image via paths.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  22. #22

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    my best thot was rotation the image using DIB's(or the GDIPLUS) on a pixel way.. they are faster...
    the image have Z=0... so from here i can rotate the image... but i can't get the angle by a point... because i don't know calculate it
    i think i can change, and i'm on free time, change the TrapezoidBlt() to:
    Code:
    Private Sub TrapezoidBltUpdate(DestinationPoints() As Position3D, ByVal DestinationHDC As Long, ByVal TranspColor As Long, ByVal OriginHDC As Long, ByVal OriginWidth As Long, ByVal OriginHeight As Long, Optional ByVal Tilled As Boolean = False)
        Dim ScanLines As Long
        Dim FullWidth As Long
        Dim ScanWidth As Single
        Dim ScanLeft As Single
        Dim Delta As Single
        Dim sbmOrig As StretchBltModes
        Dim ScanLine As Long
        Dim ScanZ As Single
        Dim ScanZDec As Single
        
        'DestinationPoints(0) is UpperLeft
        'DestinationPoints(1) is UpperRight
        'DestinationPoints(2) is LowRight
        'DestinationPoints(3) is LowLeft
        
       
            ScanLines = ScaleY(OriginHeight, .ScaleMode, vbPixels)
            Debug.Print ScanLines
            FullWidth = ScaleX(OriginWidth, ScaleMode, vbPixels)
            ScanWidth = OriginWidth * PctTop / 100
            ScanLeft = (OriginWidth - ScanWidth) / 2
            Delta = ScanLeft / ScanLines
            'Picture2.BackColor = TranspColor
            sbmOrig = SetStretchBltMode(DestinationHDC, HALFTONE)
            ScanZ = 1 + (PctTop / 100)
            ScanZDec = ((PctTop / 100)) / ScanLines
            
            For ScanLine = 0 To ScanLines - 1
                StretchBlt DestinationHDC, _
                           ScaleX(ScanLeft, .ScaleMode, vbPixels), _
                           ScanLine, _
                           ScaleX(ScanWidth, .ScaleMode, vbPixels), _
                           1, _
                           .hdc, _
                           0, _
                           ScanLine * ScanZ, _
                           FullWidth, _
                           1
                ScanLeft = ScanLeft - Delta
                ScanWidth = ScanWidth + 2 * Delta
                ScanZ = ScanZ - ScanZDec
            Next
        End With
        SetStretchBltMode DestinationHDC, sbmOrig
        If (Tilled = False) Then
            TransparentBlt DestinationHDC, _
                           0, _
                           0, _
                           ScaleX(ScaleWidth, ScaleMode, vbPixels), _
                           ScaleY(ScaleHeight, ScaleMode, vbPixels), _
                           Picture2.hdc, _
                           0, _
                           0, _
                           FullWidth, _
                           ScanLines, _
                           TranspColor
        End If
    End Sub
    is getting the 'PctTop' by points and the:
    Code:
    ScanZ = 1 + (PctTop / 100)
            ScanZDec = ((PctTop / 100)) / ScanLines
    'ScanZ' from points too.
    but after i update the function for the points i will ask what i need
    because i need 2 'graphics': one for the original image and other for the result('StretchBlt()') and then draw it('TransparentBlt()')
    VB6 2D Sprite control

    To live is difficult, but we do it.

  23. #23
    Fanatic Member
    Join Date
    Nov 2018
    Posts
    602

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    LaVolpe
    Did you find a way to color each individual path segment a different color?
    As I sit down now to play with this, I cannot find a way to render each segment a different color.

  24. #24

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    mms_: using Matrix can we rotate an image?
    the GDIPLUS only rotate the Y or X or both?
    the Z angle can be converted or added to X and Y angle?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  25. #25
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    Quote Originally Posted by mms_ View Post
    LaVolpe
    Did you find a way to color each individual path segment a different color?
    As I sit down now to play with this, I cannot find a way to render each segment a different color.
    That was what I was saying. If you draw the path, the path has to be one color.
    But it looks like what LaVolpe was saying was not to use DrawPath, but to iterate through the points in the path and draw the line seqments using drawline, so you use warp path to warp the points, but then manually loop through the points to draw each line segment manually, which you can color as you see fit.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  26. #26

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    i can't control the draw position
    Code:
    Private Sub TrapezoidBltUpdate(ByVal PctTop As Long, ByRef pos As POINTAPI, ByVal zpos As Long, ByVal DestinationHDC As Long, ByVal TranspColor As Long)
        Dim ScanLines As Long
        Dim FullWidth As Long
        Dim ScanWidth As Single
        Dim ScanLeft As Single
        Dim Delta As Single
        Dim sbmOrig As StretchBltModes
        Dim ScanLine As Long
        Dim ScanZ As Single
        Dim ScanZDec As Single
        
        With Picture1
            'Me.Width = .Width
            'Me.Height = .Height
            ScanLines = ScaleY(.ScaleHeight, .ScaleMode, vbPixels)
            Debug.Print ScanLines
            FullWidth = ScaleX(.Width, ScaleMode, vbPixels)
            ScanWidth = .ScaleWidth * PctTop / 100
            ScanLeft = (.ScaleWidth - ScanWidth) / 2
            Delta = ScanLeft / ScanLines
            'Picture2.BackColor = TranspColor
            sbmOrig = SetStretchBltMode(DestinationHDC, HALFTONE)
            ScanZ = zpos + 1 + (PctTop / 100)
            ScanZDec = ((PctTop / 100)) / ScanLines
            
            For ScanLine = 0 To ScanLines - 1
                StretchBlt DestinationHDC, _
                           ScaleX(ScanLeft, .ScaleMode, vbPixels), _
                           ScanLine, _
                           ScaleX(ScanWidth, .ScaleMode, vbPixels), _
                           1, _
                           .hdc, _
                           0, _
                           ScanLine * ScanZ, _
                           FullWidth, _
                           1
                ScanLeft = ScanLeft - Delta
                ScanWidth = ScanWidth + 2 * Delta
                ScanZ = ScanZ - ScanZDec
            Next
        End With
        SetStretchBltMode DestinationHDC, sbmOrig
        TransparentBlt DestinationHDC, _
                       pos.X, _
                       pos.Y, _
                       ScaleX(ScaleWidth, ScaleMode, vbPixels), _
                       ScaleY(ScaleHeight, ScaleMode, vbPixels), _
                       Picture2.hdc, _
                       0, _
                       0, _
                       FullWidth, _
                       ScanLines, _
                       TranspColor
    End Sub
    when i use it:
    Code:
    ...
    s(0).X = Points(0).X
        s(0).Y = Points(0).Y
        s(1).X = Points(1).X
        s(1).Y = Points(1).Y
        s(2).X = Points(3).X
        s(2).Y = Points(3).Y
        Dim pictop As Long
        Dim zpos As Long
        Dim pos As POINTAPI
        pos.X = 10
        pos.Y = 1000
        pictop = s(2).X - s(3).X
        zpos = Position.Z
        TrapezoidBltUpdate pictop, pos, zpos, Me.hdc, &H10101
        'Me.Refresh
    End Sub
    i changed the pos.x and pos.y... but it's drawed on same position
    Code:
    TransparentBlt DestinationHDC, _
                       pos.X, _
                       pos.Y, _
                       ScaleX(ScaleWidth, ScaleMode, vbPixels), _
                       ScaleY(ScaleHeight, ScaleMode, vbPixels), _
                       Picture2.hdc, _
                       0, _
                       0, _
                       FullWidth, _
                       ScanLines, _
                       TranspColor
    VB6 2D Sprite control

    To live is difficult, but we do it.

  27. #27

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: VB6: GDIPLUS - how change pixels colors on a faster way

    now i can control it:
    Code:
    Private Sub TrapezoidBlt(ByVal PctTop As Long, ScanZ As Single, ByVal DestinationHDC As Long, PosX As Long, PosY As Long, ByVal TranspColor As Long)
        Dim ScanLines As Long
        Dim FullWidth As Long
        Dim ScanWidth As Single
        Dim ScanLeft As Single
        Dim Delta As Single
        Dim sbmOrig As StretchBltModes
        Dim ScanLine As Long
        Dim ScanZDec As Single
        'PctTop = PctTop / 100
        'ScanZ = ScanZ / 100
        With Picture1
            'Me.Width = .Width
            'Me.Height = .Height
            ScanLines = ScaleY(.ScaleHeight, .ScaleMode, vbPixels)
            Debug.Print ScanLines
            FullWidth = ScaleX(.Width, ScaleMode, vbPixels)
            ScanWidth = .ScaleWidth * PctTop / 100
            ScanLeft = (.ScaleWidth - ScanWidth) / 2
            Delta = ScanLeft / ScanLines
            'Picture2.BackColor = TranspColor
            sbmOrig = SetStretchBltMode(DestinationHDC, HALFTONE)
            ScanZ = ScanZ + (PctTop / 100)
            ScanZDec = ((PctTop / 100)) / ScanLines
            
            For ScanLine = 0 To ScanLines - 1
                StretchBlt DestinationHDC, _
                           ScaleX(ScanLeft - 595 + PosX, .ScaleMode, vbPixels), _
                           ScanLine + PosY, _
                           ScaleX(ScanWidth, .ScaleMode, vbPixels), _
                           1, _
                           .hdc, _
                           0, _
                           ScanLine * ScanZ, _
                           FullWidth, _
                           1
                ScanLeft = ScanLeft - Delta
                ScanWidth = ScanWidth + 2 * Delta
                ScanZ = ScanZ - ScanZDec
            Next
        End With
        SetStretchBltMode DestinationHDC, sbmOrig
        
    End Sub
    but i found limitations if the standard shape is rotated
    so the GDIPLUS texture functions can fill any shape with an image?
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width