c语言jpg转bmp
‘壹’ 我想画几个函数图像用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就行了