显示图片

本文关键字:显示图 | 更新日期: 2023-09-27 17:49:56

大家好我正在尝试获取BMP文件,然后显示它,我应该通过获取BMP的头部信息并将其逐像素加载到数组中,然后设置像素来显示BMP图片,而不使用位图类。

enter code here
enter code here  public void display(String filename)
    {

        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fs);
        string headerCode = br.ReadChar().ToString() + br.ReadChar().ToString();
        MessageBox.Show(headerCode);
        if (headerCode == "BM")
        {
            int bfSize = br.ReadInt32();
            int bfReserved1 = br.ReadInt16();
            int bfReserved2 = br.ReadInt16();
            int bfoffbits = br.ReadInt32();
            int biSize = br.ReadInt32();
            int biWidth = br.ReadInt32();
            int biHeight = br.ReadInt32();
            int biPlanes = br.ReadInt16();
            int biBitCount = br.ReadInt16();
            int biCompression = br.ReadInt32();
            int biSizeImage = br.ReadInt32();
            int biXPelsPerMeter = br.ReadInt32();
            int biYPelsPerMeter = br.ReadInt32();
            int biClrUsed = br.ReadInt32();
            int biClrImportant = br.ReadInt32();
            int rgbRed = 0;
            int rgbGreen = 0;
            int rgbBlue = 0;
            Bitmap bmp = new Bitmap(biWidth, biHeight);
             PictureBox1.Size = new System.Drawing.Size(biWidth, biHeight);
            try
            {
                PictureBox1.Image = bmp; 

我应该这样做,但没有位图类和缓冲区,应该得到BMP文件的头文件,并加载到数组中,然后读取文件,以获得高度和宽度等信息,需要显示BMP像素按像素,但不使用位图类

显示图片

我会将位图加载到c#中,然后将其转换为jpg/png等格式。Bmp不适合网页,因为它们太大了。