Click here to Skip to main content
15,041,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am creating an image file using the code below
C#
Bitmap newImage = new Bitmap(Convert.ToInt32(dtDevice.Rows[0]["LogoWidth"]), Convert.ToInt32(dtDevice.Rows[0]["LogoHeight"]));

                                       using (Graphics gr = Graphics.FromImage(newImage))
                                       {
                                           gr.SmoothingMode = SmoothingMode.AntiAlias;
                                           gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                           gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
                                           gr.DrawImage(SourceLogo, new Rectangle(0, 0, Convert.ToInt32(dtDevice.Rows[0]["LogoWidth"].ToString()), Convert.ToInt32(dtDevice.Rows[0]["LogoHeight"].ToString())));
                                       }

                                       fileName = dr["DeviceID"].ToString() + "_" + objBusiness.ID + "_" + objBusiness.ResellerId + imgExtension;

                                       //Save the resized image
                                       newImage.Save(filePath + fileName);


The save method saves the file in the specified folder. But before saving i want to get the raw data of the image . Currently am doing this

C#
FileInfo fileInfo = new FileInfo(tempFilePath + fileName);
                                       byte[] fileData = new byte[fileInfo.Length];
                                       DataTable dtBusiness = new Businesses().GetBusiness(objBusiness.ID);
                                       if (dtBusiness != null && dtBusiness.Rows.Count > 0)
                                       {
                                           httpUserName = dtBusiness.Rows[0]["httpUserName"].ToString();
                                           httpPassword = dtBusiness.Rows[0]["httpPassword"].ToString();
                                       }
                                       fileData = File.ReadAllBytes(filePath + fileName);

                                       using (FileStream fs = new FileStream(filePath + fileName, FileMode.Open, FileAccess.Read))
                                       {
                                           fileData = new byte[fs.Length];
                                           fs.Read(fileData, 0, Convert.ToInt32(fs.Length));
                                           fs.Close();
                                       }
                                       imageContent = Convert.ToBase64String(fileData);



so that image content will be a base64String.But the problem is that to read the file bytes i have to save it which i want to skip.

Is it possible to get it before saving in the folder?Thanks in advance
Posted
Updated 20-Nov-13 0:07am
v2

What do you mean by raw data?

You could start from here:
Bitmap Class[^]

and see which properties/methods could give you what you want.
   
Well, you can have a try with this one:
Convert Image to "Raw Binary Data"[^]
   
Comments
Arjun Menon U.K 20-Nov-13 6:15am
   
Hi Ridoy ,

Thanks for the quick reply. Let me check whether i get the desired result. I hope it does..... Thanks anyways :)
Arjun Menon U.K 20-Nov-13 6:24am
   
Hi Ridoy,
But can i ask you a doubt , in the example shown Save event is called i.e of object Image rt? What am i looking for is to avoid that save and read the contents
agent_kruger 20-Nov-13 6:48am
   
does somebody has a fine code in my case it treats "m" as "rn" and "i" as "l"?
Arjun Menon U.K 20-Nov-13 6:58am
   
what?
agent_kruger 20-Nov-13 7:00am
   
means in my case it just takes the number correct and mistakes in letters such as "m" as "rn" and "i" as "l"?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900