【发布时间】:2014-10-07 15:16:10
【问题描述】:
我正在尝试检测图片中的一些绿色文本,然后对文本下的像素进行操作。
为此,我加载了地图图片(不含文字)和经过处理的图片。在矩阵中移动检查 RGB 值,工作完成后,我再次将位图 sn 保存为 .jpg(使用新名称)。
问题是:加载的图片存储大小约为3mb。新保存的图片有 30mb。
相同的宽度/高度和 DPI。只是颜色深度高 1 个字节(24 位 -> 32 位)。 无论如何,这不可能是 10 倍的因素。
有人知道会发生什么吗?
或者更有趣的事情:我怎样才能用 3mb 保存新的位图?
感谢您的回答, -LD-
代码:
// no text, picture shows a map
Bitmap MapBitmap = new Bitmap("C:\\Users\\LD\\Desktop\\Karte\\Map.jpg");
// with green text
Bitmap OriginalBitmap = new Bitmap("C:\\Users\\LD\\Desktop\\Karte\\Original.jpg");
// manipulated text
Bitmap NeueBitmap = new Bitmap(OriginalBitmap.Width,OriginalBitmap.Height);
// move throug matix
for (int x = 0; x < OriginalBitmap.Width; x++)
{
for (int y = 0; y < OriginalBitmap.Height; y++)
{
progressBar1.Value = x * 10000 / OriginalBitmap.Width; // show progress
Color OriginalColor = OriginalBitmap.GetPixel(x, y);
int r = OriginalColor.R; // for later use
int g = OriginalColor.G;
int b = OriginalColor.B;
Color MapColor = MapBitmap.GetPixel(x, y);
int R = MapColor.R; // for later use
int G = MapColor.G;
int B = MapColor.B;
if ((g/1.5) > r && (g/1.5) > b)
{ // check the green-value compared to the others
Color NeueColor = Color.FromArgb((R + 20), (G + 20), (B + 20));
NeueBitmap.SetPixel(x, y, NeueColor);
}
else
{
Color NeueColor = Color.FromArgb(R, G, B);
NeueBitmap.SetPixel(x, y, NeueColor);
}
}
}
NeueBitmap.Save("C:\\Users\\LD\\Desktop\\Karte\\Neu2.jpg");
【问题讨论】: