How to Convert BitMap to Base64 String

I have a class called Code39, it returns a BitMap object to me. Now I need to convert this BitMap into a base64 string. The following code I have doesnt seem to work and I can't figure out why. It keeps returning an empty string and I know the BitMap is there.

Bitmap oImage = // I receive a bitmap.
MemoryStream oMStream = new MemoryStream();
oImage.Save(oMStream,System.Drawing.Imaging.ImageFormat.Png);
System.IO.StreamReader oSReader = new System.IO.StreamReader(oMStream, Encoding.ASCII);
Response.Write(Convert.ToBase64String(Encoding.ASCII.GetBytes(or.ReadToEnd())));
  

 

 

0
triggered
10/19/2007 11:54:49 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

2 Replies
1472 Views

Similar Articles

[PageSpeed] 56

What you can do is save your bitmap image to a memory stream. Then get a byte array from the memory stream which you can then convert to a base64 string 

System.IO.MemorySteam ms = new System.IO.MemorySteam();
oImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] byteImage = ms.ToArray(); 
Convert.ToBase64String(byteImage); //here you should get a base64 string
 
0
jimmy
10/20/2007 2:25:57 AM

Thank you. whooops.

Do you know by chance, by using a StreamReader on a MemoryStream did not work? 

0
triggered
10/22/2007 6:05:21 PM
Reply:

Similar Artilces:

Convert base64 string to bitmap giving problem
Hi . Need to Convert base64 string representing header of the binary field with image data. //ds.Tables[6].Rows[1].ItemArray[2].ToString() contains base64string {Byte[] byt = Convert.FromBase64String(ds.Tables[6].Rows[1].ItemArray[2].ToString());SaveToOut("image/jpeg", byt, true);PerformScaleImage(contentType, content, Response, 150, 50);MemoryStream stream = new MemoryStream();stream.Write(buff, 0, buff.Length);using (Bitmap img = new Bitmap(stream))/*---Giving invalid parameter exception-------*/ {--------------------------}}Can you give details. Srinivas ...

Convert Object/String to a Base64 String
The function below converts a normal string to a Base64 string. This can come in pretty handy ;) public static string getBase64Encoded(string inString) { byte[] inData; char[] charArr; //System.IO.StringReader sr = new System.IO.StringReader(inString); //sr.Read(inData, 0, inString.Length); charArr = inString.ToCharArray(); inData = new byte[charArr.Length]; for(int i = 0; i < charArr.Length; i++) { inData[i] = (byte)charArr[i]; } return System.Convert.ToBase64String(inData, 0 , inData.Length); } ...

Getting error while converting string to double: Input string was not in correct format
Select Case LocalMeasuringUnitText Case "Currency" 'do the conversion hereDim ConversionRate As Double = GetConversionRate(_LanguageID)   Dim UKValue As Double 'String.Format("{0:c}", SelectedRow(rowloop).Item("TransData").ToString()) Dim varValue As Object = NothingDim Stringvalue As Object = SelectedRow(rowloop).Item("TransData").ToString.Trim 'varValue = Double.TryParse(Stringvalue, varValue) 'CType(Stringvalue, System.Double) 'UKValue = Convert.ToDouble(Stringvalue) / GetConversionRate(ConfigurationManager.AppS...

Getting Start With .net
hi i'm intersted to learn asp.net (vb or delphi) . i programming with delphi6 but i'd like to tp know something about programming in internet specially with .net . i hear about microsoft.net with delphi 7 that i can programming with delphi in .net .... is it right ? what 's our opinian about it ? and better to learn Vb.Net or continu with delphi(or delphi.net) thanks. Ali Darabian I think there is some support for Delphi in .Net. However, you will find much more support from the user community if you choose a more popular language such as VB.Net or C#. Since your al...

used a c#.net to vb.net converter and am now getting a syntax error.
ok I used a cool utility at http://www.kamalpatel.net/ConvertCSharp2VB.aspx to convert some c#.net to vb.net and it spit out a bunch of code which almost works but I am getting a syntax error on this line Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) I tried it that way and also like Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) but either way gave the same error Compiler Error Message: BC30035: Syntax error. Source Error: Line 26: Line ...

Converting classic to .NET 2 code, and .NET gets an error back from ADS?
 For future-proofing, our Internal Phone Directory is being moved onto our AD servers, and obviously we're using LDAP for queries.To get the phoneboook queries working, I adapted the current classic ASP code to use LDAP, and that works fine. However, we're wanting to move these pages to .NET, and that's where the problem comes in. Using the same basic logic from the Classic code (90% of its unchanged) to produce an LDAP query, I get the error  155 Unknown error (0x80005000)This is using the same website, and so the same credentials  - unless aspx pages run und...

how to get start with .NET
the net help people installed  to my desktop 1-microsoft visual studio .NET enterprise developer 2003 2-microsoft .NET framework 1.1 what else do i need ...???  and how can i try with some simple code in VS.Net and run it to see wat happen...????? please help If you want to develope web applications, then you'll also need IIS on your PC.  That'll require XP-Professional or Windows 2000/2003, but XP-Home edition won't allow IIS installation. As for how to get started, you can search the web for some tutorials or buy a good book on VS.  The topic is way too vast to...

Where to start and how did you get started?
Hi, I have had a feeling for a long time to jump into the adds market for some time due to my low income (shooting for the stars) and I don't have anything better to do these days. But I find it really difficult not to give up due to lack of guides (what I can find atleast) and all the hard words which only makes me confused. But I won't give up. Never. Not sure if this is the right place to post this, but I deffinitly would be really greatfull for help getting started. How did you get started? +If there are any teacher that wanna show me the ropes private, I can give payment with ...

System.Net.Mail is giving error CS0029: Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
I'm getting an error while trying to use the wizard to create a form and than pass it the vaibles to Mail. Any help would be much appreciated. SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try {   message.From = txtEmail.Text; message.To.Add("admin1@yoursite.com"); message.Subject = "Feedback"; message.CC.Add("admin1@yoursite.com"); message.CC.Add("admin2@yoursite.com"); message.IsBodyHtml = false; message.Body = txtMessage.Text; smtpClient.Send(message); lblStatus.Text = "Email successfully sent."; } catch (Exception ex) { lbl...

Converting String to Minutes in .net
hi all, i have a string value(Ex:"915"),i need to convert in to minutes(EX:15:15) please provide me the code for that. Hi, As per my calculations 915 comes to 15:25 that is 15 hr 25 min and not 15:15. If you think I am correct, here is the code:Dim hr As Integer = CInt("915") / 60 Dim min As Integer = CInt("915") Mod 60 Regards...

convert image to base64 string?
Hi, how can I convert an image to a base64 string? Getting image from webserver for example.. Regards, NNMValidation Complete========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========I'll always mark your post(s) as answer when it is! Nvm! I did it!! lol Validation Complete========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========I'll always mark your post(s) as answer when it is!...

Getting Started with .net and a few questions
Hello I've done some asp and php programming along with various other languages in the past and slowing getting my head around .net.I have a small project of creating a Holiday Booking system on our Intranet and just trying to get the first part to work properly will hopefully get me sorted for the whole project. The Intranet is running on .net 2 and I prefer to use the VB code rather than C#. This is connecting to an SQL server.My initial page that I am trying to create is just for an admin user to view which dates in a table have been specified as Bank Holidays and be able to add ...

Getting started with JScript.NET
I'm a Javascript and Actionscript developer, and the thought of being able to do server-sides in something I know was too good to resist. Does anyone know some good tutorials for developing ASP.NET pages in JScript?  I can find lots of console code, but simple things are hard: like I can't even figure out how to print something out to the web page (just a string). What I'm really trying to do is access a database, verify a login, and print JSON out to the response.  What should I do to start?  Is there a better way to do this? (IE: using some JSON library already?). I'm commun...

Getting all text at start of a string
Hello,I have a string (from a weather feed) that looks like:Monday: Mainly Sunny, 25.5°C Is it possible to get everything before the :So I can just get the day, and not the conditionsThe idea is that the feed looks likeMonday: asdsfasfMonday Night: asdsfasfTuesday: AFASFetc,Thanks  Try this: string s = "Monday: Mainly Sunny, 25.5°C"; string d = s.Split(':')[0];Thanks, EdMicrosoft MVP - ASP/ASP.NET...

Web resources about - How to Convert BitMap to Base64 String - asp.net.getting-started

List of converts to Buddhism - Wikipedia, the free encyclopedia
Ajahn Brahm (born 1951), Religious teacher and student of the late Thai monk Ajahn Chah . Currently he is the abbot of the Bodhinyana Monastery, ...

Facebook Timeline For Pages: 8 Million Converts, 29 Million To Go
... reach to 98 percent of users who liked its page, as well as to double its engagement rate, during a 28-day period. Dr. Pepper hasn’t yet converted ...

Facebook stock roundup: Execs offload more stock, directors convert shares
... Bowles, the former co-chair of the now-defunct National Commission on Fiscal Responsibility and Reform, and Reed Hastings, Netflix CEO, converted ...

How to Convert Leads Into Buying Customers - The 9 Step Sales Process EVERYONE Should Use
... School of Business in Toronto on the topics of Sales and Entrepreneurship. I shared with them the sales process that I find How to Convert Leads ...

Bitcoin : Should I convert my savings to Bitcoin?
Answer (1 of 7): You should think of this question as "Should I invest all my savings in Bitcoin?", and not "Should I have my savings denominated ...

Coordinates - Calculate and Convert a Position on the App Store on iTunes
Get Coordinates - Calculate and Convert a Position on the App Store. See screenshots and ratings, and read customer reviews.

Catholics should not convert Jews, says Vatican, in push against anti-Semitism
... 50 years since the Vatican's repudiation of the concept of Jewish guilt for Jesus' death.  Vatican City: Catholics should not try to convert ...

Opinion: These 5 things made me a happy iPad Pro convert
... like I needed a bigger device. But after three weeks with my iPad Pro, several things have changed my mind, and I’m officially a happy convert ...

Today’s apps gone free: BlockBear, Stock Grader, PDF Smart Convert and more
Block ads and other annoying content, take the emotion out of investing, and convert almost anything into a PDF with todays collection of apps ...

$100 device converts all your film to digital photos
... still on film negatives. Today, we've got the perfect Amazon Cyber Week deal for you: A Wolverine F2D Mighty 20MP 7-in-1 Film to Digital Converter ...

Resources last updated: 12/22/2015 7:58:22 PM