I have been musing over this one for a while, as I need to display the
transparency of Targa files. A picturebox in VB.net will render a
32-bit PNG correctly with transparency. But they won't display tgas at
all.
In the end, I have opened a Targa with AIL and saved a temporary PNG
file as Application.StartupPath & "\_AlphaCache.PNG"
Public Function AlphaImage() As String
Dim AlphaCachePath As New String(Application.StartupPath &
"\_AlphaCache.PNG")
Dim objAIL As cAdvancedImagery
Dim hIMG As Int32
objAIL = New cAdvancedImagery
If objAIL.IO_LoadImage(Me.CurrentItem, hIMG) = True Then
If objAIL.IO_SaveImage(hIMG, AlphaCachePath,
cAdvancedImagery.IMAGE_FORMAT.IF_PNG,
cAdvancedImagery.IMAGE_FLAGS.PNG_DEFAULT, True) = True Then
Call objAIL.IO_DestroyImage(hIMG)
objAIL = Nothing
Return AlphaCachePath
Else
MsgBox("Error - " & objAIL.Error_GetLast)
Return Nothing
End If
Call objAIL.IO_DestroyImage(hIMG)
objAIL = Nothing
End If
Return Nothing
objAIL = Nothing
End Function
when it is done, it returns the string of the saved PNG, (which is
saved over each time)
so the whole operation is called with this method -
PictureBox1.ImageLocation = HitchHiker.AlphaImage()
and it's pretty fast too, far quicker than using render_transparent.
I've also put a checkermap in the backgroundimage so you can see which
bits are transparent.