Jumat, 19 Juni 2009

Tugas 4

program:
void CMbohDlg::OnButton1()
{ int i,j,red,green,blue,gray; long int warna,warnagray;
CDC* pDC = m_pic1.GetDC(); CDC dcMem1; CRect rect; BITMAP bm;
HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),"a.bmp",IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(hBitmap)
{ if(m_bmpBitmap.DeleteObject()) m_bmpBitmap.Detach(); m_bmpBitmap.Attach(hBitmap);
}
m_pic1.GetClientRect(rect); m_bmpBitmap.GetBitmap(&bm);
dcMem1.CreateCompatibleDC(pDC); dcMem1.SelectObject(&m_bmpBitmap);
for(i=0;iStretchBlt(0,0,rect.Width(),rect.Height(),&dcMem1,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}

void CMbohDlg::OnButton2()
{ int i,j,red,green,blue,th; long int warna,wgray,xgray; CDC* pDC = m_pic2.GetDC(); CDC dcMem1;
CRect rect; BITMAP bm;
HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),"a.bmp",IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(hBitmap)
{
if(m_bmpBitmap.DeleteObject()) m_bmpBitmap.Detach(); m_bmpBitmap.Attach(hBitmap);
}
m_pic2.GetClientRect(rect); m_bmpBitmap.GetBitmap(&bm);
dcMem1.CreateCompatibleDC(pDC); dcMem1.SelectObject(&m_bmpBitmap);
th= int (256/16);
for(i=0;iStretchBlt(0,0,rect.Width(),rect.Height(),&dcMem1,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
}

//fungsi menggubah warna ke rgb
void WarnaToRGB(long int warna,int *Red, int *Green, int *Blue)
{ *Red = warna & 0x000000FF; *Green = (warna & 0x0000FF00) >> 8;
*Blue = (warna & 0x00FF0000) >> 16; }

//fungsi mengubah rgb ke warna
long int RGBToWarna(int Red, int Green, int Blue)
{ return(Red+(Green<<8)+(blue<<16));}

Tidak ada komentar:

Posting Komentar