Solved

Convert Base64 string to jpeg

Posted on 2014-10-31
12
691 Views
Last Modified: 2014-11-03
I recently accepted an answer to a question I submitted on converting a base64 string to a jpeg.  The answer was correct when using the supplied base64 that the question participant used, he did suggest that I supply my base64 string.  Anyhow when I have attempted to use the code on my string and I get the same black square that I have always returned.

The original question is here.
http://www.experts-exchange.com/Programming/Microsoft_Development/Q_28546044.html

The answer accepted is here.
Imports System.IO

Public Class Form1
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Try
            Dim txt As String = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" ' red dot from wikipedia
            If txt.StartsWith("data:") Then
                Dim poscomma As Integer = txt.IndexOf(",") + 1
                txt = txt.Substring(poscomma, txt.Length - poscomma)
            End If

            Dim ms As New MemoryStream(Convert.FromBase64String(txt))

            Dim bm As Bitmap = Bitmap.FromStream(ms) '<---load bitmap from memory stream

            'create new memory stream
            Dim jpgms As New MemoryStream()
            jpgms.Position = 0
            bm.Save(jpgms, System.Drawing.Imaging.ImageFormat.Jpeg) '<---convert to jpeg

            PictureBox1.Image = Image.FromStream(jpgms)

            'jpgms.toArray() '<--used as data source for sql 2008 image
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

Open in new window

Are you able to do this with my base64 string. which is below?
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAi4AAADcCAYAAABXjyrkAAAABHNCSVQICAgIfAhkiAAAGgRJREFUeJzt3WuoPOddwPFvpLZeCtmiSL1mCl5KvXQr6BspGV/4phZ7RGyVItmCKIrYUxChL2w2+sKCSP6BgMUL2b6oCm3NiTRY2hfZ0CARtTmxWhOoZv8Ve9HYnGNqlET798WzD/PM7Ow5e/bMbXe/HxjO7s7uzHPO2Zn5ze+5gSRJkiRJkiRJkiRJkiRJkiRJkiRJ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ZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSdoj/w+6ATbNfqIQ7QAAAABJRU5ErkJggg==

Open in new window

0
Comment
Question by:JoeBo747
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
12 Comments
 
LVL 34

Expert Comment

by:it_saige
ID: 40416050
I get a black box when I use your base64 string:Capture.JPG
And a red dot when I use his:Capture.JPG
-saige-
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40416068
And when I added
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize

Open in new window


The picture box change size to what looks like a banner size and still displayed an all black box:Capture.JPG
-saige-
0
 
LVL 1

Author Comment

by:JoeBo747
ID: 40416233
Yes that's my point,  If you do not change the format of the image you get back form the base64 string you get an image containing a signature.test-png.png
I need to change the image to a jpeg,  when I do I get the black box!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:it_saige
ID: 40416459
Ah.  I understand now.  I got your answer.  Had to do a little experimenting.  It comes down to the fact that the original base64 string is a transparency image and bitmap does not support transparency, so the bitmap draws it as all black.  

Revised code using extension methods:
Imports System.Drawing.Imaging
Imports System.Linq
Imports System.IO

Module Extensions
	Private encoders() As ImageCodecInfo = ImageCodecInfo.GetImageEncoders()

	<System.Runtime.CompilerServices.Extension()> _
	Public Function ToJpeg(ByVal ImageIn As Image, Optional ByVal Quality As Integer = 100) As Image
		Dim encoder As ImageCodecInfo = (From item As ImageCodecInfo In encoders Where item.MimeType.Equals("image/jpeg") Select item).FirstOrDefault
		If Not encoder Is Nothing Then
			Dim parameters As EncoderParameters = New EncoderParameters(1)
			'Set Quality Parameter
			parameters.Param(0) = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Quality)
			'Save to a Memory Stream
			Dim ms As New MemoryStream
			ImageIn.Save(ms, encoder, parameters)
			Return Image.FromStream(ms)
		Else
			Return Nothing
		End If
	End Function

	<System.Runtime.CompilerServices.Extension()> _
	Public Function ToImage(ByVal BitMapIn As Bitmap, ByVal Quality As Integer) As Image
		Return Image.FromStream(ToJpegToStream(BitMapIn, Quality))
	End Function

	<System.Runtime.CompilerServices.Extension()> _
	Public Function ToJpegToStream(ByVal BitMapIn As Bitmap, ByVal Quality As Integer, Optional ByVal CompressPct As Integer = -1) As MemoryStream
		Dim encoder As ImageCodecInfo = (From item As ImageCodecInfo In encoders Where item.MimeType.Equals("image/jpeg") Select item).FirstOrDefault
		If Not encoder Is Nothing Then
			Dim parameters As EncoderParameters = New EncoderParameters(1)
			'Set Quality Parameter
			parameters.Param(0) = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Quality)
			'Save to a Memory Stream
			Dim ms As New MemoryStream
			BitMapIn.Save(ms, encoder, parameters)
			Return ms
		Else
			Return Nothing
		End If
	End Function

	<System.Runtime.CompilerServices.Extension()> _
	Public Function ToBitmap(ByVal StreamIn As MemoryStream) As Bitmap
		Dim image As Image = image.FromStream(StreamIn)
		Dim bmp As New Bitmap(image, image.Width, image.Height)
		Dim graphics As Graphics = graphics.FromImage(bmp)
		graphics.FillRectangle(New SolidBrush(Color.White), New Rectangle(0, 0, image.Width, image.Height))
		graphics.DrawImage(image, New Rectangle(0, 0, image.Width, image.Height))
		Return bmp
	End Function
End Module

Public Class Form1

	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Try
			Dim txt As String = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAi4AAADcCAYAAABXjyrkAAAABHNCSVQICAgIfAhkiAAAGgRJREFUeJzt3WuoPOddwPFvpLZeCtmiSL1mCl5KvXQr6BspGV/4phZ7RGyVItmCKIrYUxChL2w2+sKCSP6BgMUL2b6oCm3NiTRY2hfZ0CARtTmxWhOoZv8Ve9HYnGNqlET798WzD/PM7Ow5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SZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSdoj/w+6ATbNfqIQ7QAAAABJRU5ErkJggg=="	' red dot from wikipedia
			If txt.StartsWith("data:") Then
				Dim poscomma As Integer = txt.IndexOf(",") + 1
				txt = txt.Substring(poscomma, txt.Length - poscomma)
			End If

			Dim ms As New MemoryStream(Convert.FromBase64String(txt))
			Dim bmp As Bitmap = ms.ToBitmap()

			'create new jpg from bitmap
			Dim jpg As Image = bmp.ToImage(100)

			PictureBox1.Image = jpg
			PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize

			'jpgms.toArray() '<--used as data source for sql 2008 image
		Catch ex As Exception
			MsgBox(ex.ToString)
		End Try
	End Sub
End Class

Open in new window


Produces the following output:Capture.JPG
-saige-
0
 
LVL 1

Author Comment

by:JoeBo747
ID: 40416911
Thanks for your work,  but unfortunately the code doesn't work for me!  I have copied your module into my test project and implemented the code exactly as you have shown,  the result is a broken picture box as shown in the image below,  am I missing something?

broken-image.png
0
 
LVL 34

Assisted Solution

by:it_saige
it_saige earned 250 total points
ID: 40417110
Copying the above code into a new project on a different computer produces the expected results.  I have attached the project.

-saige-
VBFormsExample.zip
0
 
LVL 28

Accepted Solution

by:
Ark earned 250 total points
ID: 40417938
For transparent png's you need specify background color to replace alpha chanel:
    Private Function Base64ToBitmap(ByVal b64 As String, ByVal transparentColor As Color) As Bitmap
        If b64.StartsWith("data:") Then
            Dim poscomma As Integer = b64.IndexOf(",") + 1
            b64 = b64.Substring(poscomma, b64.Length - poscomma)
        End If

        Using ms As New IO.MemoryStream(Convert.FromBase64String(b64))
            Using bm = Bitmap.FromStream(ms)
                Dim bmOut As New Bitmap(bm.Width, bm.Height)
                Using g As Graphics = Graphics.FromImage(bmOut)
                    g.Clear(transparentColor)
                    g.DrawImage(bm, 0, 0)
                End Using
                Return bmOut
            End Using
        End Using
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim txt As String = "Your string here"
            Dim bm = Base64ToBitmap(txt, Color.White)
            'create new memory stream
            Dim jpgms As New IO.MemoryStream()
            jpgms.Position = 0
            bm.Save(jpgms, System.Drawing.Imaging.ImageFormat.Jpeg) '<---convert to jpeg
            PictureBox1.Image = Image.FromStream(jpgms)

            'jpgms.toArray() '<--used as data source for sql 2008 image
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

Open in new window

0
 
LVL 1

Author Comment

by:JoeBo747
ID: 40418558
Now I have a dilemma! The code from it sage doe's exactly what I asked for in my  question,  it  fixes  my bitmap and answers the question thank you.  The later arrival of Ark also supplies the answer and I favour this as the fix mainly because of the more lightweight approach.  The question is now how to distribute the points it sage has stuck with this but Ark is the one I will implement in my app. Is 50/50 fair? Its my choice but I wish to be fair,
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40418572
50/50 works for me.  Just glad you got your answer...

-saige-
0
 
LVL 28

Expert Comment

by:Ark
ID: 40418830
50/50 is Ok :)
BTW, why do you need png->jpeg conversion? If resulting array size is a goal, gif is much better(smaller) for signatures.
0
 
LVL 1

Author Comment

by:JoeBo747
ID: 40418916
Thanks to both of you for your contribution s,  I am glad you agree and I will award the points.   The page is being supplied via a third party and I have no control over this
 I also have to write the stream to the database in a format again dictated by a third party. I am very pleased by the outcome thank you both once again.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Nested forach loop to linq 3 42
Best book for Internet security 4 52
wrapping text in datagridview header columns 1 28
Difference between Highcharts and Mapbox 10 44
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question