📄 pgmdecoder.cs
字号:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
namespace openCV.NetTest
{
class PGMDecoder
{
const string magic = "P5";
public unsafe static Bitmap Parse(string fileName)
{
int width, height;
string[] pgmLines = File.ReadAllLines(fileName);
string[] dimensions = pgmLines[2].Split(' ');
int.TryParse(dimensions[0], out width);
int.TryParse(dimensions[1], out height);
Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read))
{
try
{
fs.Seek(-(width * height), SeekOrigin.End);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
byte b = (byte)fs.ReadByte();
bmp.SetPixel(x, y, Color.FromArgb(b, b, b));
}
}
}
catch { }
}
return bmp;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -