비트맵 파일 픽셀 intensity를 반으로 줄이려고 하는데요...
해지개
질문 제목 : 비트맵 파일 픽셀 intensity를 반으로 줄이려고 하는데요...비트맵파일 픽셀 줄이기질문 내용 :
이코드는 그냥 이미지 사이즈를 반으로 줄이는 코드인데요..
이미지 사이즈 말고 픽셀을 반으로 줄이려면 어떻게 코드를 짜야하나요..??
코드좀 부탁드립니다ㅠㅠㅠㅠㅠㅠㅠㅠㅠ
#include stdio.h
#include stdlib.h
#include windows.h
#define r 0.5 // ratio
int main()
{
char infname[] = inputimage.bmp;
char outfname[] = outputimage1.bmp;
file *infp, *outfp;
hdc hdcold, hdcnew;
hbitmap hbmold, hbmnew;
bitmapfileheader filehead;
bitmapinfoheader infohead;
dword width,height,imgsize;
byte *pimage; infp = fopen(infname,rb);
if ( !infp ) {
printf(file open error\n);
return -1;
}
fread(&filehead,sizeof(bitmapfileheader),1,infp);
fread(&infohead,sizeof(bitmapinfoheader),1,infp);
width = infohead.biwidth;
height = infohead.biheight;
imgsize = width * height * (infohead.bibitcount/8);
pimage = (byte*)malloc(imgsize);
fread(pimage,1,imgsize,infp);
fclose(infp);
hbmold = createdibitmap(getdc(null),&infohead,cbm_init,pimage,(bitmapinfo*)&infohead,dib_rgb_colors);
hdcold = createcompatibledc(getdc(null));
selectobject(hdcold, hbmold);
// create new image
hdcnew = createcompatibledc(getdc(null));
hbmnew = createcompatiblebitmap(getdc(null),width*r,height*r);
selectobject(hdcnew, hbmnew);
setstretchbltmode(hdcnew, halftone);
stretchblt(hdcnew,0,0,width*r,height*r,hdcold,0,0,width,height,srccopy);
infohead.biwidth = width * r;
infohead.biheight = height * r;
infohead.bisizeimage = imgsize * (r*r);
getdibits(hdcnew,hbmnew, 0, infohead.biheight, pimage,
(bitmapinfo*)&infohead,dib_rgb_colors);
// write
filehead.bfsize = sizeof(bitmapinfoheader) + infohead.bisizeimage;
outfp = fopen(outfname,wb);
if ( !outfp ) {
printf(file open error\n);
return -1;
}
fwrite(&filehead, sizeof(bitmapfileheader),1,outfp);
fwrite(&infohead, sizeof(bitmapinfoheader),1,outfp);
fwrite(pimage, 1, infohead.bisizeimage, outfp);
fclose(outfp);
free(pimage);
deleteobject(hbmold);
deleteobject(hbmnew);
deletedc(hdcold);
deletedc(hdcnew);
}