當前位置:首頁 » 編程語言 » c語言jpg轉bmp

c語言jpg轉bmp

發布時間: 2022-05-29 22:09:48

『壹』 我想畫幾個函數圖像用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語言將jpg圖像轉換成bmp圖像

用JPEG工作組提供的程序或庫。

JPEG工作組的程序和庫及文件和使用說明等 可以取得:
http://www.ijg.org/

『叄』 C語言生成BMP圖像問題

= =實話告訴你 這句話和生成BMP關系不大 只是為了產生某種灰度的花紋而已
fputc(c, fp); /* B */
fputc(c, fp); /* G */
fputc(c, fp); /* R */
這幾行才是真正輸出顏色的代碼 你可以在每個fputc前面修改c的值以控制顏色

『肆』 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;
}

『伍』 c語言如何將jpg圖片轉換成點陣圖,有代碼嗎

目前為止好象沒有.
我有能打開16位BMP的代碼/

『陸』 求jpeg轉bmp程序源代碼,要用C語言編寫在ARMLinux下能用的。

有Delphi的要嗎?

『柒』 怎麼用C語言將jpg圖像轉換成bmp圖像

把XXXX.JPG的JPG改成BMP就行了

熱點內容
如何讓助理伺服器可以被遠程 發布:2025-02-12 04:47:11 瀏覽:769
存儲空間不足但 發布:2025-02-12 04:46:27 瀏覽:273
樹莓派編程板 發布:2025-02-12 04:41:45 瀏覽:904
php取整 發布:2025-02-12 04:33:21 瀏覽:221
我的世界創造伺服器位置 發布:2025-02-12 04:24:49 瀏覽:701
毛利潤演算法 發布:2025-02-12 04:22:42 瀏覽:754
戰艦少女r紅茶腳本 發布:2025-02-12 04:05:05 瀏覽:465
峰火戰國伺服器什麼時候開 發布:2025-02-12 03:56:31 瀏覽:175
電腦配置慢怎麼解壓 發布:2025-02-12 03:52:18 瀏覽:716
androidsdk功能 發布:2025-02-12 03:43:07 瀏覽:87