OS Window 64 บิต
Microsoft Visual Studio 2010
คือผมลองหัดใช้ภาษา C ในการเขียนผ่านโครงสร้าง 3ส่วนของ FILE image(BMP) แบบ Binary โดยใช้ 24 บิต ต่อ พิกเซล
โดยไม่ใช้ Library หรือ API มาช่วยนะคับ
พยายามยามหาขนาด ของความกว้างและความสูง และ การคำนวน ของรูปภาพ
โดยที่เราไม่ต้องไปกำหนดค่าให้ พอลอง output ออกมา ค่ามันมั่วไปหมดเลยนะคับ
เลยอยากจะขอคำชี้แนะด้วยนะคับ - -*
code
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้
#include<stdio.h>
#include<stdlib.h>
//Bitmap file header
struct bmpfileheader
{
unsigned short filetype;
unsigned long filesize;
short reserved1;
short reserved2;
unsigned long bitmapoffset;
};
typedef struct bmpfileheader BMP_H;
//DIB header (bitmap information header)
struct bitmapheader
{
unsigned long size;
long width;
long height;
unsigned short planes;
unsigned short bitsperpixel;
unsigned long compression;
unsigned long sizeofbitmap;
unsigned long horzres;
unsigned long vertres;
unsigned long colorsused;
unsigned long colorsimp;
};
typedef struct bitmapheader BMP_INFO;
//Color table
struct color
{
unsigned char blue;
unsigned char green;
unsigned char red;
};
typedef struct color RGB;
int main(void)
{
FILE* fp=NULL;
char buffer[25];
BMP_H *bmp_h=NULL;
BMP_INFO *bmp_info=NULL;
RGB *rgb=NULL;
fp = fopen("f:\\n1.bmp", "rb");
//Bitmap file header
bmp_h=(BMP_H*)malloc(sizeof(BMP_H));
fread(bmp_h,sizeof(BMP_H),1, fp);
printf("\n-------Bitmap file header-------\n");
printf("filetype=%x\n",bmp_h->filetype);
printf("filesize=%d\n",bmp_h->filesize);
printf("reserved1=%d\n",bmp_h->reserved1);
printf("reserved2=%d\n",bmp_h->reserved2);
printf("bitmapoffset=%d\n",bmp_h->bitmapoffset);
//DIB header (bitmap information header)
bmp_info=(BMP_INFO*)malloc(sizeof(BMP_INFO));
fread(bmp_info,sizeof(BMP_INFO), 1, fp);
printf("\n-------Bitmap information header-------\n");
printf("size=%d\n",bmp_info->size);
printf("width=%d\n",bmp_info->width);
printf("height=%d\n",bmp_info->height);
printf("planes=%d\n",bmp_info->planes);
printf("bitsperpixel=%d\n",bmp_info->bitsperpixel);
printf("compression=%d\n",bmp_info->compression);
printf("sizeofbitmap=%d\n",bmp_info->sizeofbitmap);
printf("horzres=%d\n",bmp_info->horzres);
printf("vertres=%d\n",bmp_info->vertres);
printf("colorsused=%d\n",bmp_info->colorsused);
printf("colorsimp=%d\n",bmp_info->colorsimp);
fclose(fp);
free(bmp_h);
free(bmp_info);
return(0);
/*กำหนดค่า
fseek(fp,0,SEEK_END);
bmp_info->size=ftell(fp);
bmp_info->bitsperpixel=24;
bmp_info->width=512;
bmp_info->height=512;
*/
}
ปล.สวัสดีปีใหม่คับ ละก็ขอขอบคุณล่วงหน้าด้วยคับ _/\_
มีปัญหาภาษาCนะคับ เรื่อง image processing
Microsoft Visual Studio 2010
คือผมลองหัดใช้ภาษา C ในการเขียนผ่านโครงสร้าง 3ส่วนของ FILE image(BMP) แบบ Binary โดยใช้ 24 บิต ต่อ พิกเซล
โดยไม่ใช้ Library หรือ API มาช่วยนะคับ
พยายามยามหาขนาด ของความกว้างและความสูง และ การคำนวน ของรูปภาพ
โดยที่เราไม่ต้องไปกำหนดค่าให้ พอลอง output ออกมา ค่ามันมั่วไปหมดเลยนะคับ
เลยอยากจะขอคำชี้แนะด้วยนะคับ - -*
code
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้
ปล.สวัสดีปีใหม่คับ ละก็ขอขอบคุณล่วงหน้าด้วยคับ _/\_