vitaloverdose
Programmer
Hi there , a while ago i wrote some image manipulation functions using microsofts WIA mainly because it allows you to easily load png images and modify them on a perpixel basis. So i then wrote a GUI (the program was a button editor) but when ive come to use the functions in the main program im now having problems with transparent pixels being saved as black. Ive gone back and checked all the old test bits of code i made when i first made the functions and they are giving me the same results.
Hers an example of the code ive been using
Its simply loads in a png (with some transparent pixels) and puts it into an array, i then make a blank image(of transparent pixels) of the same size and put that into another array. Then copy from one array to the other and save. Normal this mixes the 2 images fine but now the transparent pixels are being saved as black for some reason ?
Thanks
Hers an example of the code ive been using
Code:
Private Sub Modify()
Dim Img As ImageFile
Dim ImgB As ImageFile
Dim IP As ImageProcess
Dim vA As Vector
Dim vB As Vector
Dim i As Long
Set ImgB = CreateObject("WIA.ImageFile")
Set Img = CreateObject("WIA.ImageFile")
Set IP = CreateObject("WIA.ImageProcess")
MakePic ImgB, 40, 40
Img.LoadFile "C:\Test.png"
Set vA = Img.ARGBData
Set vB = ImgB.ARGBData
For i = 1 To vA.Count
vB(i) = vA(i)
Next
IP.Filters.Add IP.FilterInfos("ARGB").FilterID
Set IP.Filters(1).Properties("ARGBData") = vB
Set ImgB = IP.Apply(ImgB)
ImgB.SaveFile "C:\done.png"
End Sub
Public Function MakePic(ImgBlank As ImageFile, W As Long, H As Long)
Dim WiaImgProcessRes As ImageProcess
Dim nVec As Vector
Dim nCol As Long
nCol = -1
'=============== Create 2x2 blank pic
Set nVec = CreateObject("WIA.Vector")
nVec.Add nCol: nVec.Add nCol: nVec.Add nCol: nVec.Add nCol
Set ImgBlank = nVec.ImageFile(2, 2)
'=============== resize blank pic
Set WiaImgProcessRes = CreateObject("WIA.ImageProcess")
WiaImgProcessRes.Filters.Add WiaImgProcessRes.FilterInfos("Scale").FilterID
WiaImgProcessRes.Filters(1).Properties!PreserveAspectRatio = False
WiaImgProcessRes.Filters(1).Properties("MaximumWidth") = W
WiaImgProcessRes.Filters(1).Properties("MaximumHeight") = H
Set ImgBlank = WiaImgProcessRes.Apply(ImgBlank)
End Function
Its simply loads in a png (with some transparent pixels) and puts it into an array, i then make a blank image(of transparent pixels) of the same size and put that into another array. Then copy from one array to the other and save. Normal this mixes the 2 images fine but now the transparent pixels are being saved as black for some reason ?
Thanks