Tag: bmp

.BMP文件无法打开

我正在尝试创建一个bmp文件。 该文件已创建,我可以打开它,但它说,该文件已损坏,无法正常打开。 这是我如何保存文件: void createBMP(char* pixelData, long xRes, long yRes){ BITMAPFILEHEADER fheader; BITMAPINFOHEADER iheader; COLORREF_RGB rgb; //file header werte setzen fheader.bfType = 0x4D42; fheader.bfSize = sizeof(BITMAPFILEHEADER); fheader.bfReserved1 =0; fheader.bfReserved2=0; fheader.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); //info header werte setzen iheader.biSize = sizeof(BITMAPINFOHEADER); iheader.biWidth = xRes; iheader.biHeight = yRes; iheader.biPlanes = 1; //farbtiefe iheader.biBitCount = 24; iheader.biCompression = 0; […]

如何在不使用#pragma pack或__atribute __((packed))的情况下通过结构指针读取BMP文件并访问其标题信息?

这是我的代码。 我想知道如何“正确”读取BMP文件然后读取标头值而不强制结构被打包。 typedef struct __attribute__((packed)){ uint8_t magic[2]; /* the magic number used to identify the BMP file: 0x42 0x4D (Hex code points for B and M). The following entries are possible: BM – Windows 3.1x, 95, NT, … etc BA – OS/2 Bitmap Array CI – OS/2 Color Icon CP – OS/2 Color Pointer IC […]

在C Win32中使用hBitmap = CreateDIBSection()保存.bmp文件

我有以下代码。 我想用这个信息创建一个.bmp文件来显示内存中的数据,这是一个从framegrabber复制到主内存的图像,有人可以让我来吗? 谢谢 LPSTR CreateBMP( HWND hAppWnd, int nImageType ) { void * pWinGBits = NULL; int i; Z_BITMAPINFO zWinGHeader; //用于终止DIB的bitmapinfo // create DC for bitmap. hDCBits = CreateCompatibleDC( ghDCMain ); switch ( nImageType ) { case bayer_filter: zWinGHeader.bmiHeader.biSize = sizeof( BITMAPINFOHEADER ); zWinGHeader.bmiHeader.biPlanes = 1; zWinGHeader.bmiHeader.biClrImportant = 0; zWinGHeader.bmiHeader.biHeight = -lYSize; zWinGHeader.bmiHeader.biWidth = lXSize; […]

由C中的SIGSEGV信号终止

我正在写一个C程序,它读取bmp图像的宽度和高度( http://smsoftdev-solutions.blogspot.com.au/2014/07/code-for-reading-bmp-image-files.html ) 。 但我在终端遇到错误,它表明: i ‘./a.out’ terminated by signal SIGSEGV (Address boundary error) 我做了一些谷歌搜索,他们提到它正在访问额外的内存问题,但我无法真正发现在我的代码中,任何建议将不胜感激 #include struct __attribute__((__packed__)) BitmapHeader { int width; int height; }; void loadBmp(char* filePath, struct BitmapHeader bmpHeaderInfo){ FILE* filePtr = fopen(filePath, “rb”); unsigned char header[54]; fread(header, sizeof(unsigned char), 54, filePtr); } int main(){ char path2BMP[] = “/cup.bmp”; struct BitmapHeader bmpHeaderInfo = […]

在c中复制bmp

背景: 我想将bmp(未压缩的24 RGB)图像从一个文件名复制到另一个文件名。 我正在使用来自TDM-GCC(版本4.9.2,32位,SJLJ)的mingw编译器,它带有代码块。 问题: 程序适用于黑白图像和简单的彩色图像,但不适用于复杂的彩色图像。 请查看附件图片。 我没有足够的声誉来发布其他图片,所以我尝试发布最相关的2。 该程序无法复制lenna图像。 这种行为的原因是什么? 码: #include #include #include #pragma pack(1) /* The following is to access the DIB information https://msdn.microsoft.com/en-us/library/cc230309.aspx https://msdn.microsoft.com/en-us/library/dd183374(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/dd183376(v=vs.85).aspx */ typedef uint8_t BYTE; typedef uint32_t DWORD; typedef int32_t LONG; typedef uint16_t WORD; typedef struct { WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; }BITMAPFILEHEADER; […]

使用qdbmp读取.bmp图像

我正在使用一个名为qdbmc的库来读取bmp灰色图像(lena_gray.bmp) 这是图书馆的链接 这是我的代码: int read_image(char *filename) { struct _BMP* bmp; UINT width, height; UCHAR red,green,blue; bmp = BMP_ReadFile(filename); BMP_CHECK_ERROR( stderr, -1 ); /* Get image’s dimensions */ width = BMP_GetWidth( bmp ); height = BMP_GetHeight( bmp ); printf(“%lu %lu \n”,width,height); /* Iterate through all the image’s pixels */ for (int x = 0 ; x […]

使用C中的调色板数组查找最近的RGB值

我已完成部分代码,但在某些比较中,最接近的值不正确。 例: 正确: Rgb value | Value from array 0xFFFFFD = 0xFFFFFF 不正确: 固定代码 Rgb value | Value from array 0xF4F939 = 0xFF0000 (should be 0xFFFF00) 控制台输出:(正确) C:\Users\honguito\Desktop\Bat\Game_Batch_Files\24_to_8_bitmap>24_to_8_bit_palett e The closest color of 0xFFFFFD is: ‘0xFFFFFF’ C:\Users\honguito\Desktop\Bat\Game_Batch_Files\24_to_8_bitmap> 控制台输出:(不正确) C:\Users\honguito\Desktop\Bat\Game_Batch_Files\24_to_8_bitmap>24_to_8_bit_palett e The closest color of 0xF4F939 is: ‘0xFF0000’ C:\Users\honguito\Desktop\Bat\Game_Batch_Files\24_to_8_bitmap> 那些RGB颜色代码列在一个数组中: int data[] = { 0x000000, 0x800000, […]

从bmp文件中读取字节

如何使用C读取bmp文件中的字节?

解压缩在中间停止,输出文件用零填充(BLACK PIXELS)?

我试图在bmp(位图)文件上应用DCT(离散余弦变换)压缩。 我有一个我在Turbo C ++中运行的ac文件。 这实际上并没有压缩,但我试图实现DCT和IDCT。 代码如下: /* the image to be compressed is a bmp with 24 bpp and with name “college4.bmp” of dimensions 200*160 ie 25*20- 8*8 blocks o/p is college2.dat format: 8 bit signed integers starting rowwise from 0,0 to 8,8 the coefficients order is blue,green,red for the block no 1 then 2 […]

这个代码从图像RGB bmp纯C – Windows操作系统写入灰度bmp有什么问题

这是我的function,我根据维基百科BITMAPINFOHEADER使用标题BMP。 但是,我得到的文件没有任何图像…当填充填充时,过程停止。 // Structures for header info #pragma pack(push,1) /* Windows 3.x bitmap file header */ typedef struct { char filetype[2]; /* magic – always ‘B’ ‘M’ */ unsigned int filesize; short reserved1; short reserved2; unsigned int dataoffset; /* offset in bytes to actual bitmap data */ } file_header; /* Windows 3.x bitmap full header, […]