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
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?
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"
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
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
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
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.
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
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"
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
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"
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
'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()')
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.
Re: VB6: GDIPLUS - how change pixels colors on a faster way
Originally Posted by mms_
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
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?