Click here to Skip to main content
15,940,246 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein4-Jul-07 21:57
TomWolfstein4-Jul-07 21:57 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn5-Jul-07 0:17
sitebuilderLuc Pattyn5-Jul-07 0:17 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn1-Jul-07 9:14
sitebuilderLuc Pattyn1-Jul-07 9:14 
Questionvalidating a formula Pin
Bojja Lakshmi30-Jun-07 2:50
Bojja Lakshmi30-Jun-07 2:50 
AnswerRe: validating a formula Pin
User 665830-Jun-07 3:32
User 665830-Jun-07 3:32 
QuestionDataGrid with checkbox Pin
-spy-30-Jun-07 2:40
-spy-30-Jun-07 2:40 
AnswerRe: DataGrid with checkbox Pin
DanB198330-Jun-07 8:24
DanB198330-Jun-07 8:24 
QuestionInvalid Argument exception? Pin
$uresh $hanmugam30-Jun-07 1:58
$uresh $hanmugam30-Jun-07 1:58 
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)<br />
        {<br />
           <br />
            FileStream fstPersons = new FileStream(@"c:\\toto.tiff",<br />
                  FileMode.Create,FileAccess.Write);<br />
            BinaryWriter wrtPersons = new BinaryWriter(fstPersons);<br />
<br />
            FileStream fStream = new FileStream(@"c:\\Sample.pdf", FileMode.Open,<br />
             FileAccess.Read);<br />
            BinaryReader reader = new BinaryReader(fStream);<br />
<br />
            FileInfo info = new FileInfo(@"c:\\sample.pdf");<br />
<br />
            byte[] fromImage = null;<br />
          <br />
                fromImage = reader.ReadBytes((int)info.Length);<br />
<br />
                reader.Close();<br />
                fStream.Close();<br />
<br />
                // Read the image from the byte variable into a bitmap variable<br />
                MemoryStream fromImageStream = new MemoryStream();<br />
                fromImageStream.Write(fromImage, 0, fromImage.Length);<br />
                Image image = Image.FromStream(fromImageStream, false,true);<br />
                Bitmap bitmap = (Bitmap)image;<br />
                // Instantiate the encoder<br />
                EncoderParameters encoderParams = new EncoderParameters();<br />
                encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 50L);<br />
                ImageCodecInfo codecInfo = GetEncoderInfo("image/tiff");<br />
                MemoryStream newImage = new MemoryStream();<br />
                // Convert the image to the new format<br />
                bitmap.Save(newImage, codecInfo, encoderParams);<br />
                // Read the new image into a byte variable<br />
                byte[] data = newImage.ToArray();<br />
<br />
                wrtPersons.Write(data);<br />
<br />
                fstPersons.Close();<br />
                wrtPersons.Close();<br />
     <br />
        }<br />
<br />
 <br />
<br />
       private static ImageCodecInfo GetEncoderInfo(String mimeType)<br />
        {<br />
           int j;<br />
           ImageCodecInfo[] encoders;<br />
           encoders = ImageCodecInfo.GetImageEncoders();<br />
           for(j = 0; j < encoders.Length; ++j)<br />
           {<br />
            if(encoders[j].MimeType == mimeType)<br />
             return encoders[j];<br />
           }<br />
           return null;<br />
        }<br />



thanks in advance
AnswerRe: Invalid Argument exception? [modified] Pin
Luc Pattyn30-Jun-07 3:07
sitebuilderLuc Pattyn30-Jun-07 3:07 
Questionreading file error Pin
tauras8130-Jun-07 1:41
tauras8130-Jun-07 1:41 
AnswerRe: reading file error Pin
Luc Pattyn30-Jun-07 1:58
sitebuilderLuc Pattyn30-Jun-07 1:58 
Questionarray of type label Pin
Glen Harvy29-Jun-07 23:47
Glen Harvy29-Jun-07 23:47 
AnswerRe: array of type label Pin
Sathesh Sakthivel29-Jun-07 23:53
Sathesh Sakthivel29-Jun-07 23:53 
GeneralRe: array of type label Pin
Glen Harvy30-Jun-07 0:09
Glen Harvy30-Jun-07 0:09 
AnswerRe: array of type label Pin
Luc Pattyn29-Jun-07 23:57
sitebuilderLuc Pattyn29-Jun-07 23:57 
GeneralRe: array of type label Pin
Glen Harvy30-Jun-07 0:11
Glen Harvy30-Jun-07 0:11 
GeneralRe: no Replace !! Pin
Luc Pattyn30-Jun-07 1:14
sitebuilderLuc Pattyn30-Jun-07 1:14 
AnswerRe: array of type label Pin
Guffa30-Jun-07 0:08
Guffa30-Jun-07 0:08 
Questionconsole application creation Pin
DKalepu29-Jun-07 22:52
DKalepu29-Jun-07 22:52 
AnswerRe: console application creation Pin
Christian Graus29-Jun-07 23:01
protectorChristian Graus29-Jun-07 23:01 
GeneralRe: console application creation Pin
DKalepu30-Jun-07 0:13
DKalepu30-Jun-07 0:13 
GeneralRe: console application creation Pin
Luc Pattyn30-Jun-07 0:55
sitebuilderLuc Pattyn30-Jun-07 0:55 
Questionhow to create mdi? Pin
help as an alias29-Jun-07 22:49
help as an alias29-Jun-07 22:49 
AnswerRe: how to create mdi? Pin
Sathesh Sakthivel29-Jun-07 23:55
Sathesh Sakthivel29-Jun-07 23:55 
GeneralRe: how to create mdi? Pin
Christian Graus30-Jun-07 0:07
protectorChristian Graus30-Jun-07 0:07 

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.