Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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.

Posted on 2016-10-27
Medium Priority
Last Modified: 2016-10-28
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

Question by:zimmer9
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

dsuyemoto earned 2000 total points
ID: 41864715
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.

Author Closing Comment

ID: 41864794
The perfect answer for me. Priceless.  :)

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question