我有两个尺寸不同的图像,我想创建另一个垂直包含它们的大图像。
private Image<Gray, Byte> newImage(Image<Gray, Byte> image1, Image<Gray, Byte> image2)
{
int ImageWidth = 0;
int ImageHeight = 0;
//get max width
if (image1.Width > image2.Width)
ImageWidth = image1.Width;
else
ImageWidth = image2.Width;
//calculate new height
ImageHeight = image1.Height + image2.Height;
//declare new image (large image).
Image<Gray, Byte> imageResult = new Image<Gray, Byte>(ImageWidth, ImageHeight);
imageResult.ROI = new Rectangle(0, 0, image1.Width, image1.Height);
image1.CopyTo(imageResult);
imageResult.ROI = new Rectangle(0, image1.Height, image2.Width, image2.Height);
image2.CopyTo(imageResult);
return imageResult;
}
Run Code Online (Sandbox Code Playgroud)
返回的图像是黑色图像并且不包含这两个图像,请帮我看看问题出在哪里?
谢谢。
小智 5
你的做法是正确的。您只需删除投资回报率即可。只需在最后添加:
imageResult.ROI = Rectangle.Empty;
Run Code Online (Sandbox Code Playgroud)
最终结果应如下所示:
imageResult.ROI = new Rectangle(0, 0, image1.Width, image1.Height);
image1.CopyTo(imageResult);
imageResult.ROI = new Rectangle(0, image1.Height, image2.Width, image2.Height);
image2.CopyTo(imageResult);
imageResult.ROI = Rectangle.Empty;
Run Code Online (Sandbox Code Playgroud)