Click here to Skip to main content
15,909,747 members
Home / Discussions / C#
   

C#

 
GeneralRe: Referencing a .NET 2 assembly in a .NET1.1 Application Pin
MrEyes3-Jan-07 5:31
MrEyes3-Jan-07 5:31 
GeneralRe: Referencing a .NET 2 assembly in a .NET1.1 Application Pin
Judah Gabriel Himango3-Jan-07 5:53
sponsorJudah Gabriel Himango3-Jan-07 5:53 
QuestionWMI unable to connect to some machines Pin
Muhammad Nauman Yousuf3-Jan-07 4:42
Muhammad Nauman Yousuf3-Jan-07 4:42 
AnswerRe: WMI unable to connect to some machines Pin
Dave Kreskowiak3-Jan-07 5:33
mveDave Kreskowiak3-Jan-07 5:33 
QuestionRe: WMI unable to connect to some machines Pin
Muhammad Nauman Yousuf3-Jan-07 20:32
Muhammad Nauman Yousuf3-Jan-07 20:32 
AnswerRe: WMI unable to connect to some machines Pin
Dave Kreskowiak4-Jan-07 2:58
mveDave Kreskowiak4-Jan-07 2:58 
QuestionContextMenu in ShockWaveFlash Pin
morteza573-Jan-07 3:50
morteza573-Jan-07 3:50 
QuestionConverting an Image to a Byte[] and visa versa Pin
Gareth H3-Jan-07 3:38
Gareth H3-Jan-07 3:38 
What im trying to do is convert an image to a byte[], then write that byte array to an XML file as a string. I then want to be able to read back that file and convert the string to a btye array and then back to the image.

//convert image to byte and then a string<br />
ASCIIEncoding encoding = new ASCIIEncoding();<br />
byte[] imageArray = ImageToByteConvert(style.Image);<br />
string imageString = encoding.GetString(imageArray);<br />
<br />
//write string to file<br />
writer.WriteAttribute("Image", imageString);<br />
<br />
public byte[] ImageToByteConvert(Image imageIn)<br />
{<br />
  MemoryStream ms = new MemoryStream();<br />
  imageIn.Save(ms, ImageFormat.Gif);<br />
  return ms.ToArray();<br />
}<br />
<br />
----<br />
<br />
//read attribute "Image"<br />
attribute = domNode.Attributes["Image"];<br />
if (attribute != null)<br />
{<br />
  //convert to byte and set image<br />
  byte[] imageByte = encoding.GetBytes(attribute.Value);<br />
  retval.Image = ByteToImageConvert(imageByte);<br />
}<br />
<br />
public Image ByteToImageConvert(byte[] byteArrayIn)<br />
{<br />
  MemoryStream ms = new MemoryStream(byteArrayIn);<br />
  Image returnImage = Image.FromStream(ms);<br />
  return returnImage;<br />
}


The problem is im getting an error saying:

03/01/2007 14:31:31 XmlModelSerializer.SerializeContent; Exception: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.<br />
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)<br />
at System.Drawing.Image.Save(Stream stream, ImageFormat format)<br />
at XmlModelSerializer.ImageToByteConvert(Image imageIn) in line 61<br />
at XmlModelSerializer.SerializeContent(IWriteContext context, SeverityNodeStyle style, IXmlWriter writer) in line 33


Line 61 is: imageIn.Save(ms, ImageFormat.Gif);

Any ideas?

Regards,
Gareth.
AnswerRe: Converting an Image to a Byte[] and visa versa Pin
Luc Pattyn3-Jan-07 4:32
sitebuilderLuc Pattyn3-Jan-07 4:32 
GeneralRe: Converting an Image to a Byte[] and visa versa Pin
Gareth H3-Jan-07 5:30
Gareth H3-Jan-07 5:30 
GeneralRe: Converting an Image to a Byte[] and visa versa Pin
Luc Pattyn3-Jan-07 9:37
sitebuilderLuc Pattyn3-Jan-07 9:37 
GeneralRe: Converting an Image to a Byte[] and visa versa Pin
Gareth H3-Jan-07 22:38
Gareth H3-Jan-07 22:38 
GeneralRe: Converting an Image to a Byte[] and visa versa [modified] Pin
Gareth H5-Jan-07 0:57
Gareth H5-Jan-07 0:57 
GeneralRe: Converting an Image to a Byte[] and visa versa Pin
Luc Pattyn5-Jan-07 2:40
sitebuilderLuc Pattyn5-Jan-07 2:40 
GeneralRe: Converting an Image to a Byte[] and visa versa Pin
Gareth H5-Jan-07 3:27
Gareth H5-Jan-07 3:27 
AnswerRe: Converting an Image to a Byte[] and visa versa Pin
maysam gamini5-Nov-09 12:49
maysam gamini5-Nov-09 12:49 
QuestionHow to trigger event when user press Enter key in textbox? Pin
TrooperIronMan3-Jan-07 3:24
TrooperIronMan3-Jan-07 3:24 
AnswerRe: How to trigger event when user press Enter key in textbox? Pin
Martin#3-Jan-07 3:31
Martin#3-Jan-07 3:31 
AnswerRe: How to trigger event when user press Enter key in textbox? Pin
Vertyg03-Jan-07 3:34
Vertyg03-Jan-07 3:34 
GeneralRe: How to trigger event when user press Enter key in textbox? Pin
Martin#3-Jan-07 3:35
Martin#3-Jan-07 3:35 
GeneralRe: How to trigger event when user press Enter key in textbox? Pin
Vertyg03-Jan-07 4:48
Vertyg03-Jan-07 4:48 
GeneralRe: How to trigger event when user press Enter key in textbox? Pin
Martin#3-Jan-07 4:54
Martin#3-Jan-07 4:54 
AnswerRe: How to trigger event when user press Enter key in textbox? Pin
V.3-Jan-07 4:34
professionalV.3-Jan-07 4:34 
GeneralRe: How to trigger event when user press Enter key in textbox? Pin
TrooperIronMan3-Jan-07 6:43
TrooperIronMan3-Jan-07 6:43 
AnswerRe: Strange string.Format() error Pin
Dominik Reichl3-Jan-07 2:13
Dominik Reichl3-Jan-07 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.