通过C#,想拆分出一张图像的偶数行和奇数行,然后偶数行拼成一张图,奇数行拼成一张图 返回
C#论坛
老数据
3700
悬赏:5 飞吻
您可以使用 C# 和 .NET 中的图像处理库(如 System.Drawing)来实现该需求。
以下是一个示例代码:
using System;
using System.Drawing;
namespace ImageSplitExample
{
class Program
{
static void Main(string[] args)
{
// 读取图像
Image image = Image.FromFile("example.jpg");
// 获取图像的宽高
int width = image.Width;
int height = image.Height;
// 创建偶数行图像和奇数行图像
Bitmap evenRowsImage = new Bitmap(width, height / 2);
Bitmap oddRowsImage = new Bitmap(width, height / 2);
// 遍历每一行
for (int y = 0; y < height; y++)
{
// 遍历每一列
for (int x = 0; x < width; x++)
{
Color pixelColor = ((Bitmap)image).GetPixel(x, y);
if (y % 2 == 0)
{
// 偶数行
evenRowsImage.SetPixel(x, y / 2, pixelColor);
}
else
{
// 奇数行
oddRowsImage.SetPixel(x, y / 2, pixelColor);
}
}
}
// 保存图像
evenRowsImage.Save("evenRowsImage.jpg");
oddRowsImage.Save("oddRowsImage.jpg");
}
}
}代码会读取一张名为 example.jpg 的图像,然后逐行扫描该图像,并将偶数行存入一张新图像(evenRowsImage.jpg),将奇数行存入另一张新图像(oddRowsImage.jpg)中。