Is there a way to modify my C# code to make 2 check images larger? Presently there is a lot of space between the 2 check images when I merge them and they appear small & thus are hard to read.

I am in the process of creating a C# console application (using .Net Framework 4.0) in which I take the front image of a check stored in 1 TIF file and the back image of a check stored in another TIF file and merge the 2 files into 1 file which displays the front and back image of checks in 1 file. Is there a way to modify my following C# code to make the 2 check images larger because presently there is a lot of empty space between the 2 check images when I merge them and the images themselves are rather small in size in the merged file.

Here is my C# code that takes 2 TIF files and merges them into 1 file to which I assign the file name extension of "ard.out":
I have attached a snapshot of 1 of the "ard.out" files so that you can see what I'm looking to improve upon.
I renamed the file extension in the attachment as "*.tiff" so that it is readable to you.
The images appear with the front check image above the back check image.

 public static void CreateTifFile(string file_tif)
            Bitmap bmp = new Bitmap(1024, 512);
            using (Graphics graph = Graphics.FromImage(bmp))
                Rectangle ImageSize = new Rectangle(0, 0, 1024, 512);
                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment = StringAlignment.Center;

                graph.FillRectangle(Brushes.White, ImageSize);
                graph.DrawString("IMAGE NOT AVAILABLE", new Font("Tahoma", 50), Brushes.Black, ImageSize, sf);
            file_tif = file_tif.Replace(".TIF", ".TIF");
            bmp.Save(Globals.s_NoImage + file_tif);

        internal class ProcessImageThread
            private string _checkImgPrefix;
            private string _directory;

            public ProcessImageThread(string checkImgPrefix, string directory)
                _checkImgPrefix = checkImgPrefix;
                _directory = directory;

            public void ProcessImage(Object threadContext)
                    int threadIndex = (int)threadContext;

                    string tif1 = _directory + _checkImgPrefix + "_Front.tif";
                    string tif2 = _directory + _checkImgPrefix + "_Rear.tif";
                    string tif3 = _directory + _checkImgPrefix + ".ard.out";

                    Image img1 = Image.FromFile(tif1);
                    Image img2 = Image.FromFile(tif2);

                    int width = Math.Max(img1.Width, img2.Width);
                    int height = img1.Height + img2.Height;

                    Bitmap img3 = new Bitmap(width, height);
                    Graphics g = Graphics.FromImage(img3);

                    g.DrawImage(img1, new Point(0, 0));
                    g.DrawImage(img2, new Point(0, img1.Height));


                    img3.Save(tif3, System.Drawing.Imaging.ImageFormat.Tiff);

                    string fileName = Path.GetFileName(tif3);
                    byte[] imgBits = File.ReadAllBytes(tif3);

                    using (MemoryStream ms = new MemoryStream(imgBits))
                        using (Image i = Image.FromStream(ms))
                            EncoderParameters parms = new EncoderParameters(1);
                            ImageCodecInfo codec = ImageCodecInfo.GetImageDecoders()
                                                                 .FirstOrDefault(decoder => decoder.FormatID == ImageFormat.Tiff.Guid);

                            parms.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);

                            i.Save(tif3, codec, parms);

                    if (Interlocked.Decrement(ref _numerOfThreadsNotYetCompleted) == 0)

Open in new window

Who is Participating?
dsuyemotoConnect With a Mentor Commented:
The problem appears to be with:

g.DrawImage(img1, new Point(0, 0));
g.DrawImage(img2, new Point(0, img1.Height));

Which retains the original size and doesn't account for the dpi. if you change to the following:

g.DrawImage(img1, 0, 0, img1.Width, img1.Height);
g.DrawImage(img2, 0, img1.Height, img2.Width, img2.Height);

This should remove the "spacing" and alter the image to the size of the one that's created.
zimmer9Author Commented:
The perfect answer for me. Priceless.  :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.