[Mono-list] Question about encoding and tricky stuff.
Rampage
atomikramp at email.it
Mon Aug 23 20:25:03 EDT 2010
Ian Norton-Badrul-2 wrote:
>
> On Mon, 2010-08-23 at 14:14 +0100, Rampage wrote:
>> -----------------------------------------------------------------------------
>> string sOutput = StartProcess("cat", picture.png");
>> byte[] imagebytes = System.Text.Encoding.Default.GetBytes(sOutput);
>>
>> Gdk.Pixbuf pb = new Gdk.PixBuf(imagebytes);
>>
>> Image img = new Image(pb);
>> --------------------------------------------------------------------------------
>>
>> the program returns me with an exception saying that the file format for
>> the
>> pixbuf is not valid.
>
> Perhaps this?
>
> Process prc = new Process();
> prc.StartInfo.UseShellExecute = false;
> prc.StartInfo.FileName = sProgram;
> prc.StartInfo.Arguments = sArguments;
> prc.StartInfo.RedirectStandardOutput = true;
> prc.Start();
>
> bytes[] stdout = new byte[8192*1024];
>
> int len = prc.StandardOutput.BaseStream.Read( stdout, 0, 8192*1024 );
> Image img = new Image(stdout);
>
> Ian
>
>
> _______________________________________________
> Mono-list maillist - Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
>
Hi again,
i've tried the way you suggested me and the output is rendered properly.
but i didn't notice that the md5 of the computed byte array doesn't match
with the one of the source file.
this is going to be a problem couse it means something is wrong in there.
i've tried returning the stream like this:
-------------------------------------------
Process prc = new Process();
prc.StartInfo.UseShellExecute = false;
prc.StartInfo.FileName = sProgram;
prc.StartInfo.Arguments = sArguments;
prc.StartInfo.RedirectStandardOutput = true;
prc.Start();
return prc.StandardOutput.BaseStream;
-------------------------------------------
this way the hash matches perfectly but obviously once the stream is read
it's gone, and since i need both to render the image and calculate the md5
it's going to be an issue.
do you have anything to suggest me?
--
View this message in context: http://mono.1490590.n4.nabble.com/Question-about-encoding-and-tricky-stuff-tp2335084p2336001.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list