none
Stitching images together into one new image

    Question

  • I have several 400 dpi color raster images (TIFF files) the width is 5" and the height 36". I need to stitch those images together into one new image and save this image again as a TIFF file.

    What is the best way to do this?

    Thanks for your ideas!

    Best regards, Ben
    -Ben
    Monday, August 04, 2008 8:10 PM

Answers

  • Not sure what you expect me to say.  I came up with two solutions, you've immediately dismissed one.  That leaves only one.  Start calling around, make sure you mention your requirement.  It is not easily met.  Good luck!
    Hans Passant.
    Tuesday, August 05, 2008 11:16 PM

All replies

  • Create a Bitmap of the right size.  Use Graphics.FromImage() to get a graphics object for it.  Then call its DrawImage() method for each image, offsetting them so you stitch the bitmap together.
    Hans Passant.
    Monday, August 04, 2008 9:24 PM
  • Okay, that is working when i want a standard (96 dpi) output image. I need at lease 400 dpi but i prefer 600 dpi. Any help?
    -Ben
    Tuesday, August 05, 2008 12:55 PM
  • Dpi is not a factor, you are copying pixels.  Just make your target bitmap large enough.
    Hans Passant.
    Tuesday, August 05, 2008 1:05 PM
  •  I use this code:

    1 double inputwidth = (width / 72) * 600;  
    2 double inputheight = (height / 72) * 600;  
    3  
    4 Bitmap bmp = new Bitmap((int)inputwidth, (int)inputheight, PixelFormat.Format24bppRgb);  
    5 bmp.SetResolution(600, 600);  
    6 Graphics g = Graphics.FromImage(bmp);  
    7 int startpoint = 0;  
    8 for (int x = 0; x < bands.Count; x++)  
    9 {  
    10     string file = bands[x].ToString();  
    11     Bitmap tmp = new Bitmap(file);  
    12     g.DrawImage(tmp, startpoint, 0, tmp.Width, tmp.Height);  
    13     startpoint = startpoint + tmp.Width;  
    14 }  
    15 bmp.Save("c:\\bands\\bands.tif", ImageFormat.Tiff); 

    My outputfile is need is 35583 pixels wide and 19875 pixels high.

    I can't see any errors in it. I hope you can see what i'm doing wrong.

    Thanks, Ben
    -Ben
    • Edited by Ben van Erp Tuesday, August 05, 2008 2:08 PM add output size
    Tuesday, August 05, 2008 2:01 PM
  • It is a common mistake.  Dpi is just a reference number, available to the device or application that displays the image to display the image in its original intended size.  The only thing that counts when you work with the image in code is the number of pixels in the image.  The Image.Width and Height properties tell you that.  For example, if you need to stitch two images side by side, each 100 x 100 pixels, you need to create a bitmap that is 200 x 100 pixels.  Whatever the Dpi value.

    Another thing to keep in mind is that changing the Dpi value is meaningless.  You cannot create pixels that were not originally there in the source image.  If you try, you'll just get a blurry image.  The GDI+ pixel interpolator works pretty well but it is constrained by the laws of physics and human perception.  FWIW, the "enhance image" machine in the Law and Order crime labs is a figment of the imagination.

    Hans Passant.
    Tuesday, August 05, 2008 4:17 PM
  • What is the maximum size (in pixels) a bitmap can be? For example when i try to create a bitmap with the following code

    Bitmap bmp = new Bitmap(16762,23258, PixelFormat.Format24bppRgb);  
     

    I get the Parameter is not valid error. The error is given on this line.


    -Ben
    • Edited by Ben van Erp Tuesday, August 05, 2008 6:19 PM delete some lines
    Tuesday, August 05, 2008 6:18 PM
  • 16762 x 23258 x 3 = 1.17 Gigabytes.  32-bit Windows doesn't usually give you much more than 500 MB of contiguous virtual memory.  You'll need a 64-bit operating system or a much smarter graphics library.
    Hans Passant.
    Tuesday, August 05, 2008 6:27 PM
  • It has to run on a 32 bits OS. Switching to a 64 bits OS no option. What do you suggest to do? And do you know a "smarter" graphics library i can use?

    Thanks, Ben
    -Ben
    Tuesday, August 05, 2008 6:32 PM
  • Not sure what you expect me to say.  I came up with two solutions, you've immediately dismissed one.  That leaves only one.  Start calling around, make sure you mention your requirement.  It is not easily met.  Good luck!
    Hans Passant.
    Tuesday, August 05, 2008 11:16 PM