Mayayana
10/5/2010 2:08:00 AM
I'm not sure whether this will work for all PNGs...
as I said before, there are some glitches in the
class that I linked to. But so far I have this:
Running the sample program, I changed
Command2 sub to this:
Private Sub Command2_Click()
Dim Test() As Byte
Dim filename As String
CommonDialog1.ShowOpen
filename = CommonDialog1.filename
pngClass.PicBox = Form1 'or Picturebox
pngClass.SetToBkgrnd True, 0, 300 '100, 50 'set to Background (True or
false), x and y
pngClass.BackgroundPicture = Form1 'same Backgroundpicture
pngClass.SetAlpha = True 'when Alpha then alpha
pngClass.SetTrans = True 'when transparent Color then transparent Color
pngClass.OpenPNG filename
That draws the sample picture at 0 left, 300 px from
top. I set a background picture on the form. My sample
PNG happens to be like so:
bitdepth: 4
colortype: 3
I then made 2 changes to the MakeAlpha sub in
the LoadPNG class:
ReDim DestData(bytesperrow * Me.Height - 1)
ReDim SrcData(bytesperrow * Me.Height - 1) '(UBound(Buffer))
'--*****changed
DestHdr.BitCount = 24
DestHdr.Height = Me.Height
DestHdr.Width = Me.Width
DestHdr.Planes = 1
DestHdr.Size = 40
MemDC = CreateCompatibleDC(hdc)
hBmp = CreateCompatibleBitmap(hdc, Me.Width, Me.Height)
hOldBmp = SelectObject(MemDC, hBmp)
BitBlt MemDC, 0, 0, Me.Width, Me.Height, hdc, x, y, vbSrcCopy
GetDIBits MemDC, hBmp, 0, Me.Height, SrcData(0), DestHdr, 0
MirrorData SrcData, bytesperrow '-- *******added
SelectObject hOldBmp, MemDC
With those 2 line changes, my sample PNG draws onto
the form, with the transparent areas showing through
properly.
HOWEVER, in order to make the same thing work with
the test.png image (the jelly button), which is bitdepth 8,
colortype 6, I had to change the function back to it's original
format.