1 Replies - 157 Views - Last Post: 18 January 2013 - 03:48 PM Rate Topic: -----

#1 kamikazehighland  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 13

Convert PNG to 32bpp Bitmap

Posted 17 January 2013 - 08:23 PM

I need to create a bitmap object that either preserves the alpha channel of a png or adds one if the png has no alpha channel. This:
Dim a = New Bitmap( _
    My.Application.Info.DirectoryPath & "\a.png")
            Dim b As New Bitmap(a)

Will alter the colors or alpha values. I use the Image.Save method described here to convert pngs to bmps:
http://msdn.microsof...y/ytz20d80.aspx
Now I just need to convert pngs to 32bppArgb bitmaps instead.

The msdn example saves to a file, but I save to a stream instead. There is only one ImageFormat.Bmp so what do I do?

This is the 'GetEncoderInfo' function from msdn:
Private Shared Function GetEncoderInfo(ByVal format As ImageFormat) As ImageCodecInfo
        Dim j As Integer 
        Dim encoders() As ImageCodecInfo
        encoders = ImageCodecInfo.GetImageEncoders()

        j = 0
        While j < encoders.Length
            If encoders(j).FormatID = format.Guid Then 
                Return encoders(j)
            End If
            j += 1
        End While 
        Return Nothing 

    End Function


Can I write that to convert to 32bppArgb bitmap instead?

Is This A Good Question/Topic? 0
  • +

Replies To: Convert PNG to 32bpp Bitmap

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 4965
  • View blog
  • Posts: 10,563
  • Joined: 02-June 10

Re: Convert PNG to 32bpp Bitmap

Posted 18 January 2013 - 03:48 PM

You should look at the various overrides for New Bitmap.
You'll see that one of them lets you specify the depth.

This article has a simple example just going the opposite direction from 32 to 24. But you can see how all you have to do it select the 32bpp enumeration.
http://stackoverflow...t-bmp-to-24-bit
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1