Click here to Skip to main content
15,888,170 members
Home / Discussions / C#
   

C#

 
QuestionProblem with Visual Studio 2005 Pin
sharpiesharpie9-Aug-07 5:11
sharpiesharpie9-Aug-07 5:11 
AnswerRe: Problem with Visual Studio 2005 Pin
Judah Gabriel Himango9-Aug-07 5:37
sponsorJudah Gabriel Himango9-Aug-07 5:37 
GeneralRe: Problem with Visual Studio 2005 Pin
sharpiesharpie9-Aug-07 6:53
sharpiesharpie9-Aug-07 6:53 
GeneralRe: Problem with Visual Studio 2005 Pin
Judah Gabriel Himango9-Aug-07 7:21
sponsorJudah Gabriel Himango9-Aug-07 7:21 
GeneralRe: Problem with Visual Studio 2005 Pin
sharpiesharpie9-Aug-07 9:16
sharpiesharpie9-Aug-07 9:16 
GeneralRe: Problem with Visual Studio 2005 Pin
Luc Pattyn9-Aug-07 9:30
sitebuilderLuc Pattyn9-Aug-07 9:30 
GeneralRe: Problem with Visual Studio 2005 Pin
sharpiesharpie9-Aug-07 9:39
sharpiesharpie9-Aug-07 9:39 
Questionhelp converting an image to a string. Pin
snorkie9-Aug-07 4:59
professionalsnorkie9-Aug-07 4:59 
I don't know why I'm having some many issues with this, but some help would be appreciated. I'm working on a unit test. I need to get my image saved to a string and placed in my XML document. Below is the code that almost works... The part that doesn't work is when I write the byte array of the image contents to the String Builder. Only part of it comes out, then the StringBuilder object just quits working and doesn't write any more after.

StringBuilder xmlString = new StringBuilder();
xmlString.AppendLine("<TranslationRoot>");
//other xml ommited.
//Create an image.
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(25, 25);
for (int i = 0; i < 25; i++)
{
    for (int j = 0; j < 25; j++)
    {
        Color pixelColor = bitmap.GetPixel(i, j);
        int r = pixelColor.R; // the Red component
        int b = pixelColor.B; // the Blue component
        Color newColor = Color.FromArgb(r, 0, b);
        bitmap.SetPixel(i, j, newColor);
    }
}

MemoryStream gifStream = new MemoryStream();
bitmap.Save(gifStream, System.Drawing.Imaging.ImageFormat.Gif);
System.Text.UnicodeEncoding encoding = new UnicodeEncoding();
//Create a byte array to assign the image to.
byte[] gifByte = new byte[gifStream.Length];
//Reset the stream position to the start. Otherwise nothing is read.
gifStream.Position = 0;
//copy the image from the stream to the byte array.
gifStream.Read(gifByte, 0, gifByte.Length);

//Place the image in the XML.
xmlString.Append("      <Value><![CDATA[" + encoding.GetString(gifByte) + "]]></Value>");


The last line of the XML looks like:
<Value><![CDATA[䥇㡆愹÷}


So after that last append, any additional appends just don't work. No error is thrown. So any help is appreciated.

Thanks!

Hogan
AnswerRe: help converting an image to a string. Pin
Luc Pattyn9-Aug-07 5:20
sitebuilderLuc Pattyn9-Aug-07 5:20 
GeneralRe: help converting an image to a string. Pin
snorkie9-Aug-07 5:33
professionalsnorkie9-Aug-07 5:33 
GeneralRe: help converting an image to a string. Pin
Luc Pattyn9-Aug-07 5:47
sitebuilderLuc Pattyn9-Aug-07 5:47 
QuestionInactivity Timer Pin
Stathread9-Aug-07 4:17
Stathread9-Aug-07 4:17 
AnswerRe: Inactivity Timer Pin
originSH9-Aug-07 4:26
originSH9-Aug-07 4:26 
AnswerRe: Inactivity Timer Pin
Dinobot_Slag9-Aug-07 4:28
Dinobot_Slag9-Aug-07 4:28 
GeneralRe: Inactivity Timer Pin
Stathread9-Aug-07 4:42
Stathread9-Aug-07 4:42 
QuestionAcces Database: Password Protected Pin
Ken Mazaika9-Aug-07 3:22
Ken Mazaika9-Aug-07 3:22 
AnswerRe: Acces Database: Password Protected Pin
Colin Angus Mackay9-Aug-07 3:28
Colin Angus Mackay9-Aug-07 3:28 
GeneralRe: Acces Database: Password Protected Pin
Ken Mazaika9-Aug-07 3:32
Ken Mazaika9-Aug-07 3:32 
AnswerRe: Acces Database: Password Protected Pin
Michael Potter9-Aug-07 3:34
Michael Potter9-Aug-07 3:34 
GeneralRe: Acces Database: Password Protected Pin
Ken Mazaika9-Aug-07 3:39
Ken Mazaika9-Aug-07 3:39 
AnswerRe: Acces Database: Password Protected Pin
Ken Mazaika9-Aug-07 7:12
Ken Mazaika9-Aug-07 7:12 
QuestionChange Windows Time Pin
The Brazilian One9-Aug-07 3:19
The Brazilian One9-Aug-07 3:19 
AnswerRe: Change Windows Time Pin
Martin#9-Aug-07 3:27
Martin#9-Aug-07 3:27 
JokeRe: Change Windows Time Pin
Luc Pattyn9-Aug-07 3:35
sitebuilderLuc Pattyn9-Aug-07 3:35 
GeneralRe: Change Windows Time Pin
Martin#9-Aug-07 3:36
Martin#9-Aug-07 3:36 

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.