当前位置:首页 » 编程语言 » 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 01:25:41 浏览:67
引用jar怎么发布到服务器 发布:2025-02-12 01:07:44 浏览:333
旧电脑开服务器 发布:2025-02-12 01:02:50 浏览:277
电脑服务器两个电源什么意思 发布:2025-02-12 00:55:15 浏览:220
linux外网不能访问端口 发布:2025-02-12 00:55:13 浏览:438
安卓系统哪里可以看充电次数 发布:2025-02-12 00:53:53 浏览:723
如何选物理服务器cpu 发布:2025-02-12 00:48:22 浏览:68
怎么买编程 发布:2025-02-12 00:31:42 浏览:932
固态硬盘如何做缓存盘 发布:2025-02-12 00:19:48 浏览:519
cm13源码下载 发布:2025-02-12 00:13:58 浏览:554