Senin, 22 Juni 2009

Tugas 5

Program di bawah ini merupakan program utama dari program untuk pengenalan angka dari 0 - 9 :

//Konversi dari data pixel ke RGB dan dari data RGB ke data Pixel:
void WarnaToRGB(long int warna,int *Red, int *Green, int *Blue)
{
*Red = warna & 0x000000FF;
*Green = (warna & 0x0000FF00) >> 8;
*Blue = (warna & 0x00FF0000) >> 16;
}
long int RGBToWarna(int Red, int Green, int Blue){return(Red+(Green<<8)+(Blue<<16));
}

//Program untuk melakukan load angka (*.bmp).
void CAngkaDlg::OnLoad1()
{static char BASED_CODE szFilter[]="Bitmap Files (*.bmp)|*.bmp||";
CFileDialog m_ldFile(TRUE,"*.bmp",name, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
if(m_ldFile.DoModal()==IDOK) { name=m_ldFile.GetPathName();
}
CDC* pDC = m_pic1.GetDC(); CDC dcMem;
CRect rect; BITMAP bm;
HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),name,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);
dcMem.CreateCompatibleDC(pDC); dcMem.SelectObject(&m_bmpBitmap);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0, bm.bmWidth,bm.bmHeight,SRCCOPY);
}

//Program untuk menampilkan proyeksi integral horizontal dari angka .
void CAngkaDlg::OnHip1() {
int i,j; int red,green,blue; long int warna;
CDC* pDC = m_pic1.GetDC(); CDC dcMem; CRect rect; BITMAP bm;
HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),name,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
m_pic1.GetClientRect(rect); m_bmpBitmap.GetBimap(&bm);
dcMem.CreateCompatibleDC(pDC); dcMem.SelectObject(&m_bmpBitmap);
for(j=0;j<,bm.bmWidth;j++){
hx1[j]=0;
for(i=0;i<,bm.bmHeight;i++)
{
warna=dcMem.GetPixel(j,i);
WarnaToRGB(warna,&red,&green,&blue);
hx1[j]+=(float)(255-red)/255;}
hx1[j]=hx1[j]/2;
}
CDC* pDC1 = m_pic3.GetDC();
for(i=1;iMoveTo(i*0.75,0);
pDC1->LineTo(i*0.75,hx1[i]); }
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0, bm.bmWidth,bm.bmHeight,SRCCOPY);
}

//Program untuk menampilkan proyeksi integral vertikal dari angka.
void CAngkaDlg::OnVip1() {
int i,j; int warna,red,green,blue; CDC* pDC = m_pic1.GetDC();
CDC dcMem1; CRect rect; BITMAP bm;
HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),name,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(j=0;j<,bm.bmHeight;j++) {
hy1[j]=0;
for(i=0;i<,bm.bmWidth;i++) {
warna=dcMem1.GetPixel(j,i);
warnaToRGB(warna,&red,&green,&blue);
hy1[j]+=(float)(255-red)/255; }
hy1[j]=hy1[j]/2;
}
CDC*pDC1= m_pic2.GetDC(); for(i=0;i pDC1->MoveTo(0,0.75*i); pDC1->LineTo(hy1[i],0.75*i);
}}

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));}