在我的场景中,我在不同位置有两个tiff图像说
c:/temp/img1.tiff
和x:/temp/img2.tiff
。
我需要以编程方式将这些图像合并为单个图像
提出一些想法/代码。
谢谢,
开发
答案 0 :(得分:3)
要仅使用Framework类执行此操作,基本上可以执行此操作:
Image.FromFile
。Encoder.SaveFlag
= EncoderValue.MultiFrame
Encoder.SaveFlag
()EncoderValue.FrameDimensionPage
= Bitmap.SaveAdd
的同一文件中
醇>
它看起来像这样:
ImageCodecInfo tiff = null;
foreach ( ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders() )
{
if ( codec.MimeType == "image/tiff" )
{
tiff = codec;
break;
}
}
Encoder encoder = Encoder.SaveFlag;
EncoderParameters parameters = new EncoderParamters(1);
parameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.MultiFrame);
bitmap1.Save(newFileName, tiff, parameters);
parameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.FrameDimensionPage);
bitmap2.SaveAdd(newFileName, tiff, paramters);
parameters.Param[0] = new EncoderParameter(encoder, (long)EncoderValue.Flush);
bitmap2.SaveAdd(parameters);
答案 1 :(得分:0)
可能有几种方法可以“合并”图像。这是一对伪代码:
var NewImage = new Image();
ForEach (curPixel in img1)
{
var newColor = new Color();
newColor.RGB = (Pixel.Color.RGB + img2.PixelAt(curPixel.Location).Color.RGB) / 2
NewImage.PixelAt(curPixel.Location) = new Pixel(newColor);
}
///OR
int objCounter = 0;
ForEach (curPixel in Image)
{
if(objCounter % 2 == 0){
NewImage.PixelAt(curPixel.Location) = img1.PixelAt(curPixel.Location);
} else {
NewImage.PixelAt(curPixel.Location) = img2.PixelAt(curPixel.Location);
}
}