获取矩阵中BMP图像的RGB值 [英] get RGB value of BMP image in matrix

查看:199
本文介绍了获取矩阵中BMP图像的RGB值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要.bmp图像的RGB值,并且这些值以矩阵形式存储。我尝试了一些,但没有得到矩阵形式....请帮助我



I want RGB values of .bmp image and that values are store in matrix form. I have tried somewhat but didnt get in matrix form....please help me

void main()
{
 int i;
 int image[256][3];
 FILE *streamIn,*streamOut;
 streamIn = fopen("C:\G.bmp", "r");
 streamOut = fopen("C:\g.txt", "w");


 for(i=0;i<256;i++)
 {    // foreach pixel
    image[i][2] = getc(streamIn);
    image[i][1] = getc(streamIn);
    image[i][0] = getc(streamIn);
    printf("pixel %d : [%d,%d,%d]\n",i+1,image[i][1],image[i][2],image[i][0]);
    fprintf(streamOut,"pixel %d : [Red : %d Green :%d Blue : %d]\n",i+1,image[i] [1],image[i][2],image[i][0]);
 }


 fclose(streamIn);
 getch();
}

推荐答案

好吧,BITMAP文件格式比程序假设的要复杂一些。

看看,例如在位图教程:加载和保存位图 [ ^ ]
Well, the BITMAP file format is bit more complex than the one your program suppose.
Have a look, for instance at "Bitmap Tutorial: Loading and Saving Bitmaps"[^]


1。你在每个BMP文件的开头都忽略了BITMAPFILEHEADER和BITMAPINFOHEADER





2.你假设你有一个未压缩的24位BGR三元组档案

- >检查一下! (bmpinfo.biCompression和bmpinfo.biBitCount)



3.你真的想读(仅)前256个像素吗?



4.你必须计算数据的开始(bmpheader.bfOffBits)



5.你必须支持DWORD对齐扫描线



你可以在CPallini发布的解决方案中找到所有这些
1. You ignore the BITMAPFILEHEADER and BITMAPINFOHEADER at the beginning
of every BMP-File.

2. You assume you have an uncompressed 24bit BGR triplet File
-> check that! ( bmpinfo.biCompression and bmpinfo.biBitCount )

3. You really want to read (only) the first 256 Pixels ?

4. You have to calculate the start of data ( bmpheader.bfOffBits )

5. You have to support DWORD aligned scanline

You can find all this in the Solution CPallini posted


这篇关于获取矩阵中BMP图像的RGB值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆