I wanna do this coz I make programm a game. And I need a very fast drawing without blinking (with PixtureBoxes it blinks). I need also to aplly Particle Engine, Gradient Filling and it have to be really fast. Can I use the folowing code for this:
Function CreateBitmap(Buffer As ScreenBuffer, DC As Long, ByRef Picture As Bitmap)
ReDim Picture.Data(0 To Picture.BitInfo.bmiHeader.biWidth * Picture.BitInfo.bmiHeader.biHeight * 3 - 1) As Byte
ReDim Picture.BackData(0 To Picture.BitInfo.bmiHeader.biWidth * Picture.BitInfo.bmiHeader.biHeight * 3 - 1) As Byte
GetPictureFromBuffer 0, 0, Picture.BitInfo.bmiHeader.biWidth, _
Picture.BitInfo.bmiHeader.biHeight, Buffer, Picture.BackData
Picture.hBitmap = CreateDIBSection(DC, Picture.BitInfo, DIB_RGB_COLORS, ByVal 0&, ByVal 0&, ByVal 0&)
End Function
Function LoadBitmap(DC As Long, FileName As String, ByRef Picture As Bitmap)
Picture.hBitmap = LoadImage(App.hInstance, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
GetDIBits DC, Picture.hBitmap, 0, Picture.BitInfo.bmiHeader.biHeight, Picture.Data(0), Picture.BitInfo, DIB_RGB_COLORS
End Function
Function DrawPictureToBuffer(X As Long, Y As Long, Buffer As ScreenBuffer, Picture As Bitmap)
Dim Width As Long, Height As Long, BuffWidth As Long, BuffHeight As Long, Pixel As Long, picWidth As Long, picHeight As Long
Dim tempData() As Byte
picWidth = Picture.BitInfo.bmiHeader.biWidth
picHeight = Picture.BitInfo.bmiHeader.biHeight
BuffWidth = Buffer.BitInfo.bmiHeader.biWidth
BuffHeight = Buffer.BitInfo.bmiHeader.biHeight
OutputToBuffer Picture.X, Picture.Y, Buffer, Picture.BackData, picWidth, picHeight
ReDim tempData(0 To UBound(Picture.Data) - 1)
tempData = Picture.Data
Height = Picture.BitInfo.bmiHeader.biHeight
Width = Picture.BitInfo.bmiHeader.biWidth
For k = 0 To picHeight - 1
For i = 0 To picWidth - 1
If tempData((k * picWidth + i) * 3) = 40 And _
tempData((k * picWidth + i) * 3 + 1) = 235 And _
tempData((k * picWidth + i) * 3 + 2) = 200 Then
'if the color is green then change it
Pixel = GetPixel(Buffer.DC, X + i, Y + picHeight - 1 - k)
tempData((k * picWidth + i) * 3) = GetBlue(Pixel)
tempData((k * picWidth + i) * 3 + 1) = GetGreen(Pixel)
tempData((k * picWidth + i) * 3 + 2) = GetRed(Pixel)
End If
Next i
Next k
GetPictureFromBuffer X, Y, picWidth, picHeight, Buffer, Picture.BackData
Call OutputToBuffer(X, Y, Buffer, tempData, picWidth, picHeight)
Picture.X = X
Picture.Y = Y
End Function
Function OutputToBuffer(X As Long, Y As Long, Buffer As ScreenBuffer, Picture() As Byte, picWidth As Long, picHeight As Long)
BuffWidth = Buffer.BitInfo.bmiHeader.biWidth
BuffHeight = Buffer.BitInfo.bmiHeader.biHeight
For k = 0 To picHeight - 1
For i = 0 To picWidth - 1
Buffer.Data(((Y + k) * BuffWidth + X + i) * 3) = _
Picture((k * picWidth + i) * 3)
Buffer.Data(((Y + k) * BuffWidth + X + i) * 3 + 1) = _
Picture((k * picWidth + i) * 3 + 1)
Buffer.Data(((Y + k) * BuffWidth + X + i) * 3 + 2) = _
Picture((k * picWidth + i) * 3 + 2)
Next i
Next k
End Function
Thanks!