os window7
microsoft visual studio 2010
คือผมลองเขียน image ผ่านโครงสร้างนะคับ โดยไม่ใช้ libarary กับ API
ผมใช้ตัวนี้นะคับ graphics.h
มันมีปัญหาตรงสี red นะคับ ลองแก้ดูมันก็ยังไม่หายซักที
1.red ภาพมันจะมีจุดพิกเซลแปลกๆอยู่กระจายไปทั่วเลยนะคับ
rgb->blue=0xffffff; //white
rgb->green=0xffffff; //white
rgbq=(rgb->red)<<0;
putpixel(i,j,rgbq);
2.ส่วนภาพ ขาว_ดำ เก_สเกล เขียว น้ำเงิน และภาพRGB ไม่มีปัญหานะคับ
ปล.ขอขอบคุณล่วงหน้าทุกท่านนะคับ _/\_
code
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้[open_code]
//Read Write Display Image BMP
#include<stdio.h>
#include<stdlib.h>
#include "graphics.h"
#pragma pack(push,2) //2 bite packing
//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; //<<16
unsigned char green; //<<8
unsigned char red; //<<0
};
typedef struct color RGB;
#pragma pack(pop) // deing
int main(void)
{
FILE* fp=NULL;
FILE* cp=NULL;
int i=0,j=0,pixel=0;
BMP_H *bmp_h=NULL;
BMP_INFO *bmp_info=NULL;
RGB *rgb=NULL;
unsigned long rgbq,icc,cc;
unsigned char gray_scale ;
fp=fopen("F:\\n1.bmp", "rb");
cp=fopen("F:\\nn3.bmp", "wb");
rgb=(RGB*)malloc(sizeof(RGB));
bmp_h=(BMP_H*)malloc(sizeof(BMP_H));
bmp_info=(BMP_INFO*)malloc(sizeof(BMP_INFO));
fseek(fp,bmp_h->bitmapoffset,SEEK_SET);
//Bitmap file header
fread(bmp_h,sizeof(BMP_H),1, fp);
fwrite(bmp_h,sizeof(BMP_H),1, cp);
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)
fread(bmp_info,sizeof(BMP_INFO), 1, fp);
fwrite(bmp_info,sizeof(BMP_INFO), 1, cp);
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);
/*
//Color table
printf("\n-------Color table-------\n");
for(j=0;j<bmp_info->height;j++)
{
for(i=0;i<bmp_info->width;i++)
{
pixel=pixel+1;
fread(rgb,sizeof(RGB),1,fp);
printf("PIXEL=%2d BLUE=%3d GREEN=%3d RED=%3d\n",pixel,rgb->blue,rgb->green,rgb->red);
}
}
*/
//display
initwindow(bmp_info->width,bmp_info->height,"SCHEAY");
printf("\n---------Image----------\n");
for(j=(bmp_info->height)-1;j>-1;j--)
{
for(i=0;i<bmp_info->width;i++)
{
fread(rgb,sizeof(RGB),1,fp);
fwrite(rgb,sizeof(RGB),1,cp);
//Invert Color
//rgb->blue=255-(rgb->blue);
//rgb->green=255-(rgb->green);
//rgb->red=255-(rgb->red);
//rgbq=((((rgb->blue))<<16)+(((rgb->green))<<8)+(((rgb->red))<<0));
//putpixel(i,j,rgbq);
//
//gray_scale
//rgbq=((rgb->blue)+(rgb->green)+(rgb->red))/3;//OR
//rgbq=(0.299*(rgb->red))+(0.587*(rgb->green))+(0.114*(rgb->blue));
//rgb->blue=rgbq;
//rgb->green=rgbq;
//rgb->red=rgbq;
//rgbq=((((rgb->blue))<<16)+(((rgb->green))<<8)+(((rgb->red))<<0));
//putpixel(i,j,rgbq);
//
//black and white
//rgbq=(rgb->blue+rgb->green+rgb->red)/3;
//if(rgbq<128)
// rgbq=0x000000; //ดำ
//else
// rgbq=0xffffff; //ขาว
//putpixel(i,j,rgbq);
//
//chanal RGB
//rgb->blue=0xffffff; //white
//rgb->green=0xffffff; //white
//rgb->red=0xffffff; //white
//rgbq=(rgb->blue)<<16;
//rgbq=(rgb->green)<<8;
//rgbq=(rgb->red)<<0;
//putpixel(i,j,rgbq);
//
//24BiT
rgbq=(((rgb->blue)*(256*256))+((rgb->green)*256)+(rgb->red));//OR
//rgbq=((((rgb->blue))<<16)+(((rgb->green))<<8)+(((rgb->red))<<0));
putpixel(i,j,rgbq);
//
}
}
while (!kbhit( ))
{
delay(20);
}
fclose(fp);
fclose(cp);
free(bmp_h);
free(bmp_info);
free(rgb);
return(0);
}
[/close_code]
ภาษา C Image Processing
microsoft visual studio 2010
คือผมลองเขียน image ผ่านโครงสร้างนะคับ โดยไม่ใช้ libarary กับ API
ผมใช้ตัวนี้นะคับ graphics.h
มันมีปัญหาตรงสี red นะคับ ลองแก้ดูมันก็ยังไม่หายซักที
1.red ภาพมันจะมีจุดพิกเซลแปลกๆอยู่กระจายไปทั่วเลยนะคับ
rgb->blue=0xffffff; //white
rgb->green=0xffffff; //white
rgbq=(rgb->red)<<0;
putpixel(i,j,rgbq);
2.ส่วนภาพ ขาว_ดำ เก_สเกล เขียว น้ำเงิน และภาพRGB ไม่มีปัญหานะคับ
ปล.ขอขอบคุณล่วงหน้าทุกท่านนะคับ _/\_
code
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้