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;
}
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;
}