Home > Enterprise >  How to change cannot convert from 'System.Drawing.Image' to 'System.Drawing.Image[]?
How to change cannot convert from 'System.Drawing.Image' to 'System.Drawing.Image[]?

Time:12-23

Hi everyone I'm trying to change 'System.Drawing.Image' to 'System.Drawing.Image[] to use at my code so How To make it works as I need to merge tiff image to exist Multi Tif image thanks. and If I need to add pages to exist Multi tif image after select page how to do that? and if there another way to do that please help me?

    Image img2 = Image.FromFile(imagename1);
    Image img = Image.FromFile(imagename2);
    Tiff.TiffUtil.saveImageExistingMultiplePage(img2, img, 2, 
    imagename2);



public static void saveImageExistingMultiplePage(Image[] bmp, Image origionalFile, int PageNumber, string location)
            {
                try
                {
                    //Now load the Codecs
                    ImageCodecInfo codecInfo = getCodec();

                    System.Drawing.Imaging.Encoder saveEncoder;
                    System.Drawing.Imaging.Encoder compressionEncoder;
                    EncoderParameter saveEncodeParam;
                    EncoderParameter compressionEncodeParam;
                    EncoderParameters encoderParams = new EncoderParameters(2);
                    Bitmap pages;
                    Bitmap nextPage;

                    saveEncoder = System.Drawing.Imaging.Encoder.SaveFlag;
                    compressionEncoder = System.Drawing.Imaging.Encoder.Compression;

                    origionalFile.SelectActiveFrame(FrameDimension.Page, 0);
                    pages = new Bitmap(origionalFile);
                    pages = ConvertToBitonal(pages);

                    // Save the first page (frame).
                    saveEncodeParam = new EncoderParameter(saveEncoder, (long)EncoderValue.MultiFrame);
                    compressionEncodeParam = new EncoderParameter(compressionEncoder, (long)EncoderValue.CompressionCCITT4);
                    encoderParams.Param[0] = compressionEncodeParam;
                    encoderParams.Param[1] = saveEncodeParam;

                    pages.Save(location, codecInfo, encoderParams);

                    for (int i = 1; i < PageNumber; i  )
                    {
                        saveEncodeParam = new EncoderParameter(saveEncoder, (long)EncoderValue.FrameDimensionPage);
                        compressionEncodeParam = new EncoderParameter(compressionEncoder, (long)EncoderValue.CompressionCCITT4);
                        encoderParams.Param[0] = compressionEncodeParam;
                        encoderParams.Param[1] = saveEncodeParam;

                        origionalFile.SelectActiveFrame(FrameDimension.Page, i);
                        nextPage = new Bitmap(origionalFile);
                        nextPage = ConvertToBitonal(nextPage);
                        pages.SaveAdd(nextPage, encoderParams);
                    }

                    for (int i = 0; i < bmp.Length; i  )
                    {
                        saveEncodeParam = new EncoderParameter(saveEncoder, (long)EncoderValue.FrameDimensionPage);
                        compressionEncodeParam = new EncoderParameter(compressionEncoder, (long)EncoderValue.CompressionCCITT4);
                        encoderParams.Param[0] = compressionEncodeParam;
                        encoderParams.Param[1] = saveEncodeParam;
                        bmp[i] = (Bitmap)ConvertToBitonal((Bitmap)bmp[i]);
                        pages.SaveAdd(bmp[i], encoderParams);
                    }

                    saveEncodeParam = new EncoderParameter(saveEncoder, (long)EncoderValue.Flush);
                    encoderParams.Param[0] = saveEncodeParam;
                    pages.SaveAdd(encoderParams);
                }
                catch (System.Exception ee)
                {
                    throw ee;
                }
            }

CodePudding user response:

// initialize an image array and add your image to it
Image[] img2 = new Image[] { Image.FromFile(imagename1) };

// the rest of your code stays the same but 'img2' is now an array of images
// so the call to 'saveImageExistingMultiplePage' will accept it.
// ...

Tiff.TiffUtil.saveImageExistingMultiplePage(img2, img, 2, imagename2);

// ... continue your code
  •  Tags:  
  • c#
  • Related