kalit sikka

kalit sikka

  • NA
  • 219
  • 0

How to convert word file into Tif

Jun 26 2007 1:09 AM
Dear All, I want to convert word file into tif format image. I have use memorystream to do so. But Im unable to convert byte[] of text into image format. public static byte[] ConvertImage(byte[] fromImage, string mimeType) { // 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, true ) ; // ERROR: Parameter invalid is coming on this line............................. Bitmap bitmap = (Bitmap) image; // Instantiate the encoder EncoderParameters encoderParams = new EncoderParameters(); encoderParams.Param[0] = new EncoderParameter( Encoder.Quality, 50L ); ImageCodecInfo codecInfo = GetEncoderInfo( mimeType ); 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(); if (Logger.LogSwitch.LogInfo) { Logger.Write("ImageUtility", "EXITING ConvertImage method"); } return data; } 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 null; } Can any body rectify above code or suggest any other way-out for this Thanks in Advance

Answers (1)