473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Bitmap to Bytes and Back

Hi,

I'm interested in the process of taking a live bitmap oject with an image
already loaded in it, and representing it as a string such that a whole
bitmap carrying the same image can be constructed using only that string. It
doesn't HAVE to be a string, it could be an array of bytes or whatever, as
long as I can write code that converts it to a string carrying hex code
someting like "FF00FF" etc.

I know we're not in C++, but ... Any pointers ;-)

Thanks
-Ron
Jun 16 '06 #1
2 1871
"Ron M. Newman" <co**********@confideltial.com> wrote:
I'm interested in the process of taking a live bitmap oject with an image
already loaded in it, and representing it as a string such that a whole
bitmap carrying the same image can be constructed using only that string. It
doesn't HAVE to be a string, it could be an array of bytes or whatever, as
long as I can write code that converts it to a string carrying hex code
someting like "FF00FF" etc.


---8<---
using System;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Windows.Forms;

class App
{
static void Main(string[] args)
{
MemoryStream temp = new MemoryStream();
using (Image image = Image.FromFile(args[0]))
image.Save(temp, ImageFormat.Jpeg);
temp.Position = 0;

string asString = Convert.ToBase64String(temp.ToArray());
Console.WriteLine(asString);

MemoryStream loaded = new
MemoryStream(Convert.FromBase64String(asString));
using (Image image = Image.FromStream(loaded))
{
Form form = new Form();
form.Paint += delegate(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(image, Point.Empty);
};
form.ClientSize = image.Size;
Application.Run(form);
}
}
}
--->8---

-- Barry

--
http://barrkel.blogspot.com/
Jun 16 '06 #2
wow, cool. thanks!

"Barry Kelly" <ba***********@gmail.com> wrote in message
news:os********************************@4ax.com...
"Ron M. Newman" <co**********@confideltial.com> wrote:
I'm interested in the process of taking a live bitmap oject with an image
already loaded in it, and representing it as a string such that a whole
bitmap carrying the same image can be constructed using only that string.
It
doesn't HAVE to be a string, it could be an array of bytes or whatever,
as
long as I can write code that converts it to a string carrying hex code
someting like "FF00FF" etc.


---8<---
using System;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Windows.Forms;

class App
{
static void Main(string[] args)
{
MemoryStream temp = new MemoryStream();
using (Image image = Image.FromFile(args[0]))
image.Save(temp, ImageFormat.Jpeg);
temp.Position = 0;

string asString = Convert.ToBase64String(temp.ToArray());
Console.WriteLine(asString);

MemoryStream loaded = new
MemoryStream(Convert.FromBase64String(asString));
using (Image image = Image.FromStream(loaded))
{
Form form = new Form();
form.Paint += delegate(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(image, Point.Empty);
};
form.ClientSize = image.Size;
Application.Run(form);
}
}
}
--->8---

-- Barry

--
http://barrkel.blogspot.com/

Jun 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: James Dean | last post by:
I have 1 bit per pixel information and i have the width and height of this data.Each bit corresponds to a 24 bit colour value. I want to convert this to 24bit per pixel bitmap. Do i need to...
0
by: James Dean | last post by:
I have trouble displaying a bitmap. I have 1bpp information. I also have a command telling me what color i need to set the bytes to when the colour is switched on. The trouble is i do all this but...
2
by: James Dean | last post by:
I create a bitmap like this. The width and height are got from the compressed file i am reading. The width and height are in pixels.....1bpp bitmap = new...
2
by: Raed Sawalha | last post by:
I have a Bitmap Object and I need to return it as array of bytes is it possible
9
by: SStory | last post by:
I use a bitmap class new bitmap(filepath) this should and does load my jpg into memory. I then want to use mybitmap.save(filepath,imaging.imageformat.jpeg) to save it; overwriting the...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
12
by: active | last post by:
I've been looking on the Internet for a way to convert a DIB to a Bitmap without success. Now I'm wondering if that is the approach I should be taking. All I want to do is display the DIB or...
7
by: RB0135 | last post by:
Hi All, I have some Windows BMP, 1BPP, monochrome files that I need to get the raw data from to load a graphics buffer on a Roll Printer (which I know can be done). Lets forget about the Roll...
20
by: Joe Duchtel | last post by:
Hello - I have the following code to get a bitmap from the clipboard and to save it to a *.png file ... Dim lData As IDataObject = Clipboard.GetDataObject() If...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.