1

I am trying to create a copy of an image in memory and to use this as STDIN for a console process.

Create the InMemoryCopy:

using (FileStream fs = File.OpenRead(image))
{
   fs.CopyTo(inMemoryCopy);
}

Start process and input STDIN:

p.StartInfo.Arguments = " jpg:fd:0" +
   " -resize 500" +
   " \"" + tmpFile + "\"";

p.Start();
//Reads in pbm file.
using (var streamReader = new StreamReader(inMemoryCopy))
{
  p.StandardInput.Write(streamReader.ReadToEnd());
  p.StandardInput.Flush();
  p.StandardInput.Close();
}

Issue I encounter is that imagemagick noww does not recognise the file as image anymore? The file used is a .jpg but from the streamReader it seems not to be written into STDIN as valid Image file?

As I am a very much newbie, I googled and searched here to find an answer but could not figure this out.

How would I read an image file into memory and use this as STDIN in the console app (e.g. imagemagick).

Many thanks for any help!

  • Why are you trying to subvert imagemagick's ability to read files??? – Michael Bray Jul 05 '13 at 00:28
  • @Michael Bray - I want to have one tmp copy of the file in memory and any changes from my different effects will only be applied to this copy. Once I am happy with the changes, I save the final file. this should avoid excessive writing/reading to the harddisk and improve performance. I am completely new to C#, so I am very happy about further comments. – user2551898 Jul 05 '13 at 22:55

1 Answers1

2

StreamReader is a text reader. You probably want to write binary data to the stdin basestream. According to this: Can i put binary in stdin? C#.

You can do:

fs.CopyTo(p.StandardInput.BaseStream)
Community
  • 1
  • 1
fcuesta
  • 4,429
  • 1
  • 18
  • 13