當前位置:首頁 » 編程語言 » C語言bmp生成

C語言bmp生成

發布時間: 2022-06-05 09:22:13

Ⅰ 如何用c語言編程來顯示一個bmp文件

BOOL BitBlt( HDC hdcDest, // 點陣圖顯示目標設備環境中 int nXDest, // 點陣圖顯示在客戶區的x坐標 int nYDest, // 點陣圖顯示在客戶區的y坐標 int nWidth, // 點陣圖顯示的寬度 int nHeight, // 點陣圖顯示的長度 HDC hdcSrc

Ⅱ 我想畫幾個函數圖像用C語言生成到bmp之類的圖片里去

Windows下的簡單繪圖肯定會首先考慮GDI或者GDI+,不過既然LZ都提到Linux了,那就發個平台無關的生成BMP正弦圖的代碼好了,這個就是最原始的手動生成BMP的代碼,其實也不是很復雜。
---------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef long LONG;

#pragma pack(2)

typedef struct {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER;

typedef struct {
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;

void saveBitmap()
{
// Define BMP Size
const int height = 600;
const int width = 800;
const int size = height * width * 3;
double x, y;
int index;

// Part.1 Create Bitmap File Header
BITMAPFILEHEADER fileHeader;

fileHeader.bfType = 0x4D42;
fileHeader.bfReserved1 = 0;
fileHeader.bfReserved2 = 0;
fileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + size;
fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

// Part.2 Create Bitmap Info Header
BITMAPINFOHEADER bitmapHeader = {0};

bitmapHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapHeader.biHeight = height;
bitmapHeader.biWidth = width;
bitmapHeader.biPlanes = 3;
bitmapHeader.biBitCount = 24;
bitmapHeader.biSizeImage = size;
bitmapHeader.biCompression = 0; //BI_RGB

// Part.3 Create Data
BYTE *bits = (BYTE *)malloc(size);

// Clear
memset(bits, 0xFF, size);

// Sin Graph
for(x = 0; x < 800; x += 0.5)
{
y = sin(x / 100.0) * 200 + 300;
index = (int)y * 800 * 3 + (int)x * 3;

bits[index + 0] = 255; // Blue
bits[index + 1] = 0; // Green
bits[index + 2] = 0; // Red
}

// Write to file
FILE *output = fopen("output.bmp", "wb");

if(output == NULL)
{
printf("Cannot open file!\n");
}
else
{
fwrite(&fileHeader, sizeof(BITMAPFILEHEADER), 1, output);
fwrite(&bitmapHeader, sizeof(BITMAPINFOHEADER), 1, output);
fwrite(bits, size, 1, output);
fclose(output);
}
}

int main()
{
saveBitmap();

return 0;
}

Ⅲ C語言中如何生成BMP格式圖形文件麻煩告訴我

摘要:在科技論文和技術報告中,經常需要插入盡可能精確的各種黑白或彩色的圖形和曲線,周而一般的繪圖工具難以滿足,尤其是通過復雜計算得到的結果更是如此。介紹了在科研人員廣泛使用的C語言中,如何把黑白的或彩色的圖文轉換成BMP圖形格式文件,從而順利地插入用Word軟體寫的中文或英文報告中。

Ⅳ 如何用C語言在已有的bmp圖片上添加文字生成新的圖片

先要了解bmp結構吧,這個是最簡單的圖像數據結構。添加文字,就是要把要添加的地方的像素換成文字,即是把原來的地方的像素點成文字的像素,然後重新保存。如果知道,原圖片的bmp以及文字的bmp圖片,和在添加的地方坐標,就可以完成了。

Ⅳ c語言如何將二進制文件存儲成轉化成.bmp文件

int _tmain(int argc, _TCHAR* argv[])
{
FILE* pFileDat = fopen( "a.dat", "rb" );
FILE* pFileBmp = fopen( "b.bmp", "wb" );

int size = 0; char buf[1024] = {0};
if ( pFileBmp == NULL || pFileDat == NULL )
{
goto end;
}

while ( true )
{
size = fread( buf, 1, 1024, pFileDat );
if ( size == 0 )
{
break;
}

size = fwrite( buf, 1, size, pFileBmp );
if (size == 0)
{
break;
}
}

end:
if (pFileDat) fclose(pFileDat);
if (pFileBmp) fclose(pFileBmp);
return 0;
}

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:640
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:368
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:86
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:310
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:794
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:346
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:213
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:816
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:367
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:594