Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Invalid Argument exception?

Invalid Argument exception?

Scheduled Pinned Locked Moved C#
helpgraphicsquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    uresh hanmugam
    wrote on last edited by
    #1

    Hi all, I have try to convert a pdf to tiff file.My below the code snippet is working fine when i open a tiff file and convert some other format..But it didn't work when i open the pdf file,it will be thrown error like "Parameter is not valid" from below the code at bold line "Image image = Image.FromStream(fromImageStream, false,true);" please help me what i did wrong. private void button4_Click(object sender, System.EventArgs e) { FileStream fstPersons = new FileStream(@"c:\\toto.tiff", FileMode.Create,FileAccess.Write); BinaryWriter wrtPersons = new BinaryWriter(fstPersons); FileStream fStream = new FileStream(@"c:\\Sample.pdf", FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(fStream); FileInfo info = new FileInfo(@"c:\\sample.pdf"); byte[] fromImage = null; fromImage = reader.ReadBytes((int)info.Length); reader.Close(); fStream.Close(); // Read the image from the byte variable into a bitmap variable MemoryStream fromImageStream = new MemoryStream(); fromImageStream.Write(fromImage, 0, fromImage.Length); **Image image = Image.FromStream(fromImageStream, false,true);** Bitmap bitmap = (Bitmap)image; // Instantiate the encoder EncoderParameters encoderParams = new EncoderParameters(); encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 50L); ImageCodecInfo codecInfo = GetEncoderInfo("image/tiff"); MemoryStream newImage = new MemoryStream(); // Convert the image to the new format bitmap.Save(newImage, codecInfo, encoderParams); // Read the new image into a byte variable byte[] data = newImage.ToArray(); wrtPersons.Write(data); fstPersons.Close(); wrtPersons.Close(); } private static ImageCodecInfo GetEncoderInfo(String mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); for(j = 0; j < encoders.Length; ++j) { if(encoders[j].MimeType == mimeType) return encoders[j]; } return nul

    L 1 Reply Last reply
    0
    • U uresh hanmugam

      Hi all, I have try to convert a pdf to tiff file.My below the code snippet is working fine when i open a tiff file and convert some other format..But it didn't work when i open the pdf file,it will be thrown error like "Parameter is not valid" from below the code at bold line "Image image = Image.FromStream(fromImageStream, false,true);" please help me what i did wrong. private void button4_Click(object sender, System.EventArgs e) { FileStream fstPersons = new FileStream(@"c:\\toto.tiff", FileMode.Create,FileAccess.Write); BinaryWriter wrtPersons = new BinaryWriter(fstPersons); FileStream fStream = new FileStream(@"c:\\Sample.pdf", FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(fStream); FileInfo info = new FileInfo(@"c:\\sample.pdf"); byte[] fromImage = null; fromImage = reader.ReadBytes((int)info.Length); reader.Close(); fStream.Close(); // Read the image from the byte variable into a bitmap variable MemoryStream fromImageStream = new MemoryStream(); fromImageStream.Write(fromImage, 0, fromImage.Length); **Image image = Image.FromStream(fromImageStream, false,true);** Bitmap bitmap = (Bitmap)image; // Instantiate the encoder EncoderParameters encoderParams = new EncoderParameters(); encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 50L); ImageCodecInfo codecInfo = GetEncoderInfo("image/tiff"); MemoryStream newImage = new MemoryStream(); // Convert the image to the new format bitmap.Save(newImage, codecInfo, encoderParams); // Read the new image into a byte variable byte[] data = newImage.ToArray(); wrtPersons.Write(data); fstPersons.Close(); wrtPersons.Close(); } private static ImageCodecInfo GetEncoderInfo(String mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); for(j = 0; j < encoders.Length; ++j) { if(encoders[j].MimeType == mimeType) return encoders[j]; } return nul

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Stream operations are very much like good old file operations: if you write a file, then want to read what has been written, you must either close and reopen, OR somehow "rewind" the file. Look for an appropriate stream method (or property) to do this... :)

      Luc Pattyn [My Articles] [Forum Guidelines]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups