Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I append multipage TIFF images to 1 file using C#?

Status
Not open for further replies.

jzim9

Programmer
Sep 1, 2015
2
US
I use the following code to create a multipage TIFF image.

It works fine for the creation of 1 multipage TIFF image.

Could you show me how I can modify this code so that everytime I call the MergeTwoImages function and pass it a new set of 2 more images (firstimage and secondimage), that they are appended to the outputImage?

I would like to create many multipage TIFF images into 1 file.

---------------

Byte[] img = bytes.Skip(irecpositionrevised + irectypelength).Take(intpos1revised).ToArray();

Byte[] img1 = bytes.Skip(irecpositionrevised + irectypelength + intpos1revised).Take(intpos2revised).ToArray();

System.Drawing.Bitmap newImage = MergeTwoImages(ConvertFromByteArray(img), ConvertFromByteArray(img1));

newImage.Save("L:\\F\\S\C\\S\\test.tiff");

private static Image ConvertFromByteArray(byte[] input)
{
using (var ms = new MemoryStream(input))
{
return Image.FromStream(ms);
}
}

public static Bitmap MergeTwoImages(Image firstImage, Image secondImage)
{
if (firstImage == null)
{
throw new ArgumentNullException("firstImage");
}

if (secondImage == null)
{
throw new ArgumentNullException("secondImage");
}

int outputImageWidth = firstImage.Width > secondImage.Width ? firstImage.Width : secondImage.Width;

int outputImageHeight = firstImage.Height + secondImage.Height + 1;

Bitmap outputImage = new Bitmap(outputImageWidth, outputImageHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

using (Graphics graphics = Graphics.FromImage(outputImage))
{
graphics.DrawImage(firstImage, new Rectangle(new Point(), firstImage.Size),
new Rectangle(new Point(), firstImage.Size), GraphicsUnit.Pixel);
graphics.DrawImage(secondImage, new Rectangle(new Point(0, firstImage.Height + 1), secondImage.Size),
new Rectangle(new Point(), secondImage.Size), GraphicsUnit.Pixel);
}

return outputImage;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top