JoeBo747
asked on
Convert Base64 string to jpeg
How would I convert a base64 png encoded string to a jpeg image and then save the jpeg to sql 2008 image field? The code below
results in a black square!
my code:
dim txt as string ="data:image/png;base64,iV BORw0KGgoA A etc......" ' <---this is a shortened version of a true base64 string
Dim ms As New MemoryStream(Convert.FromB ase64Strin g(txt))
Dim bmp 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.Ima geFormat.J peg) <---convert to jpeg
jpgms.toArray() <--used as data source for sql 2008 image
results in a black square!
my code:
dim txt as string ="data:image/png;base64,iV
Dim ms As New MemoryStream(Convert.FromB
Dim bmp 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.Ima
jpgms.toArray() <--used as data source for sql 2008 image
ASKER
Hi Robert,
Thanks for your reply, the code supplied was copied accross from a trial app which does remove the header, sorry for the confusion.
Thanks for your reply, the code supplied was copied accross from a trial app which does remove the header, sorry for the confusion.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Robert,
Thanks for your assistance,
Thanks for your assistance,
Open in new window