PC Review


Reply
Thread Tools Rate Thread

Bitmap to Bytes and Back

 
 
Ron M. Newman
Guest
Posts: n/a
 
      16th Jun 2006
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


 
Reply With Quote
 
 
 
 
Barry Kelly
Guest
Posts: n/a
 
      16th Jun 2006
"Ron M. Newman" <(E-Mail Removed)> 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/
 
Reply With Quote
 
Ron M. Newman
Guest
Posts: n/a
 
      16th Jun 2006
wow, cool. thanks!

"Barry Kelly" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> "Ron M. Newman" <(E-Mail Removed)> 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/



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a 2-dimensional array to bytes, and then back Cross Microsoft VB .NET 2 8th Jan 2008 05:27 AM
Get Bytes from Bitmap Object =?Utf-8?B?UmFlZCBTYXdhbGhh?= Microsoft C# .NET 2 24th May 2005 06:09 PM
memorystream bytes to bitmap =?Utf-8?B?dmJkb3RuZXRtYW5pYQ==?= Microsoft VB .NET 3 25th Aug 2004 12:29 PM
How to convert a bitmap to a array of Bytes News VS.NET \( MS ILM \) Microsoft C# .NET 1 14th Jan 2004 07:39 AM
HOWTO: convert string to 8-bit bytes and back dermot Microsoft VB .NET 4 7th Oct 2003 04:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:14 AM.