⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgmdecoder.cs

📁 人脸检测示例程序(需要OpenCV.Net)
💻 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 + -