CxImage
.Load()
.CreateFromHANDLE()
.CopyToHandle()
.Save()
.Draw()
.GetWidth()
.GetHeight()
.Negative()
.Light()
.Filter()
.Flip()
.Mirror()
.RotateLeft()
.RotateRight()
.Rotate()
.Resample()
.Crop()
.Expand()
.Thumbnail()
::FindType()
class CImageDoc : public CDocument
{
...
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CImageDoc)
public:
...
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual void DeleteContents();
...
//}}AFX_VIRTUAL
// Implementation
public:
CxImage *m_pImage;
virtual ~CImageDoc();
...
// Generated message map functions
protected:
//{{AFX_MSG(CImageDoc)
...
afx_msg void OnImageNegative();
afx_msg void OnImageBrighten();
afx_msg void OnImageDarken();
afx_msg void OnImageContrastIncrease();
afx_msg void OnImageContrastDecrease();
afx_msg void OnImageSoftening();
afx_msg void OnImageShapen();
afx_msg void OnImageEdge();
afx_msg void OnImageEmboss();
afx_msg void OnImageFlip();
afx_msg void OnImageMirror();
afx_msg void OnImageRotateleft();
afx_msg void OnImageRotateright();
afx_msg void OnImageRotate30();
afx_msg void OnImageEnlarge();
afx_msg void OnImageShirink();
afx_msg void OnImageCrop();
afx_msg void OnImageExpend();
afx_msg void OnImageThumbnail();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
...
};
BEGIN_MESSAGE_MAP(CImageDoc, CDocument)
//{{AFX_MSG_MAP(CImageDoc)
...
ON_COMMAND(ID_IMAGE_NEGATIVE, OnImageNegative)
ON_COMMAND(ID_IMAGE_BRIGHTEN, OnImageBrighten)
ON_COMMAND(ID_IMAGE_DARKEN, OnImageDarken)
ON_COMMAND(ID_IMAGE_CONTRAST_INCREASE, OnImageContrastIncrease)
ON_COMMAND(ID_IMAGE_CONTRAST_DECREASE, OnImageContrastDecrease)
ON_COMMAND(ID_IMAGE_SOFTENING, OnImageSoftening)
ON_COMMAND(ID_IMAGE_SHAPEN, OnImageShapen)
ON_COMMAND(ID_IMAGE_EDGE, OnImageEdge)
ON_COMMAND(ID_IMAGE_EMBOSS, OnImageEmboss)
ON_COMMAND(ID_IMAGE_FLIP, OnImageFlip)
ON_COMMAND(ID_IMAGE_MIRROR, OnImageMirror)
ON_COMMAND(ID_IMAGE_ROTATELEFT, OnImageRotateleft)
ON_COMMAND(ID_IMAGE_ROTATERIGHT, OnImageRotateright)
ON_COMMAND(ID_IMAGE_ROTATE30, OnImageRotate30)
ON_COMMAND(ID_IMAGE_ENLARGE, OnImageEnlarge)
ON_COMMAND(ID_IMAGE_SHIRINK, OnImageShirink)
ON_COMMAND(ID_IMAGE_CROP, OnImageCrop)
ON_COMMAND(ID_IMAGE_EXPEND, OnImageExpend)
ON_COMMAND(ID_IMAGE_THUMBNAIL, OnImageThumbnail)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
...
CImageDoc::CImageDoc()
{
// TODO: add one-time construction code here
m_pImage = NULL;
}
...
BOOL CImageDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
// {
m_pImage = new CxImage;
m_pImage->Load(lpszPathName, CxImage::FindType(lpszPathName));
// }
return TRUE;
}
void CImageDoc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
// {
if (m_pImage)
delete m_pImage;
// }
CDocument::DeleteContents();
}
...
void CImageDoc::OnImageNegative()
{
// TODO: Add your command handler code here
m_pImage->Negative();
UpdateAllViews(NULL);
/* RGBQUAD color;
DWORD x, y;
for(y=0 ; y<m_pImage->GetHeight() ; y++)
for(x=0 ; x<m_pImage->GetWidth() ; x++)
{
color = m_pImage->GetPixelColor(x, y);
color.rgbRed = ~color.rgbRed;
color.rgbGreen = ~color.rgbGreen;
color.rgbBlue = ~color.rgbBlue;
m_pImage->SetPixelColor(x, y, color);
}
UpdateAllViews(NULL);
*/
}
void CImageDoc::OnImageBrighten()
{
// TODO: Add your command handler code here
m_pImage->Light(30);
UpdateAllViews(NULL);
/* RGBQUAD color;
DWORD x, y;
for(y=0 ; y<m_pImage->GetHeight() ; y++)
for(x=0 ; x<m_pImage->GetWidth() ; x++)
{
color = m_pImage->GetPixelColor(x, y);
color.rgbRed = __min(255, color.rgbRed+30);
color.rgbGreen = __min(255, color.rgbGreen+30);
color.rgbBlue = __min(255, color.rgbBlue+30);
m_pImage->SetPixelColor(x, y, color);
}
UpdateAllViews(NULL);
*/
}
void CImageDoc::OnImageDarken()
{
// TODO: Add your command handler code here
m_pImage->Light(-30);
UpdateAllViews(NULL);
}
void CImageDoc::OnImageContrastIncrease()
{
// TODO: Add your command handler code here
m_pImage->Light(0, 20);
UpdateAllViews(NULL);
/* RGBQUAD color;
DWORD x, y;
for(y=0 ; y<m_pImage->GetHeight() ; y++)
for(x=0 ; x<m_pImage->GetWidth() ; x++)
{
color = m_pImage->GetPixelColor(x, y);
color.rgbRed = __max(0, __min(255, color.rgbRed+(color.rgbRed-128)/5));
color.rgbGreen = __max(0, __min(255, color.rgbGreen+(color.rgbGreen-128)/5));
color.rgbBlue = __max(0, __min(255, color.rgbBlue+(color.rgbBlue-128)/5));
m_pImage->SetPixelColor(x, y, color);
}
UpdateAllViews(NULL);
*/
}
void CImageDoc::OnImageContrastDecrease()
{
// TODO: Add your command handler code here
m_pImage->Light(0, -20);
UpdateAllViews(NULL);
}
void CImageDoc::OnImageSoftening()
{
// TODO: Add your command handler code here
long kernel[]={ 0, 1, 0,
1, 2, 1,
0, 1, 0 };
m_pImage->Filter(kernel, 3, 6, 0);
UpdateAllViews(NULL);
}
void CImageDoc::OnImageShapen()
{
// TODO: Add your command handler code here
long kernel[]= { 0, -1, 0,
-1, 5, -1,
0, -1, 0 };
m_pImage->Filter(kernel, 3, 1, 0);
UpdateAllViews(NULL);
}
void CImageDoc::OnImageEdge()
{
// TODO: Add your command handler code here
long kernel[]= {-1, -1, -1,
-1, 8, -1,
-1, -1, -1 };
m_pImage->Filter(kernel, 3, 0, 0);
UpdateAllViews(NULL);
}
void CImageDoc::OnImageEmboss()
{
// TODO: Add your command handler code here
long kernel[]= {-1, 0, 0,
0, 0, 0,
0, 0, 1 };
m_pImage->Filter(kernel, 3, 0, 128);
UpdateAllViews(NULL);
}
void CImageDoc::OnImageFlip()
{
// TODO: Add your command handler code here
m_pImage->Flip();
UpdateAllViews(NULL);
/* RGBQUAD color1, color2;
DWORD x, y;
DWORD cy = m_pImage->GetHeight();
DWORD cx = m_pImage->GetWidth();
for(y=0 ; y<cy/2 ; y++)
for(x=0 ; x<cx ; x++)
{
color1 = m_pImage->GetPixelColor(x, y);
color2 = m_pImage->GetPixelColor(x, cy-1-y);
m_pImage->SetPixelColor(x, y, color2);
m_pImage->SetPixelColor(x, cy-1-y, color1);
}
UpdateAllViews(NULL);
*/
}
void CImageDoc::OnImageMirror()
{
// TODO: Add your command handler code here
m_pImage->Mirror();
UpdateAllViews(NULL);
}
void CImageDoc::OnImageRotateleft()
{
// TODO: Add your command handler code here
m_pImage->RotateLeft();
UpdateAllViews(NULL);
}
void CImageDoc::OnImageRotateright()
{
// TODO: Add your command handler code here
m_pImage->RotateRight();
UpdateAllViews(NULL);
}
void CImageDoc::OnImageRotate30()
{
// TODO: Add your command handler code here
m_pImage->Rotate(30);
UpdateAllViews(NULL);
}
void CImageDoc::OnImageEnlarge()
{
// TODO: Add your command handler code here
DWORD cx = m_pImage->GetWidth();
DWORD cy = m_pImage->GetHeight();
m_pImage->Resample((DWORD)(cx*1.5), (DWORD)(cy*1.5));
UpdateAllViews(NULL);
}
void CImageDoc::OnImageShirink()
{
// TODO: Add your command handler code here
DWORD cx = m_pImage->GetWidth();
DWORD cy = m_pImage->GetHeight();
m_pImage->Resample((DWORD)(cx*0.5), (DWORD)(cy*0.5));
UpdateAllViews(NULL);
}
void CImageDoc::OnImageCrop()
{
// TODO: Add your command handler code here
DWORD x1 = m_pImage->GetWidth()/10;
DWORD x2 = m_pImage->GetWidth()*9/10;
DWORD y1 = m_pImage->GetHeight()/10;
DWORD y2 = m_pImage->GetHeight()*9/10;
m_pImage->Crop(x1, y1, x2, y2);
UpdateAllViews(NULL);
}
void CImageDoc::OnImageExpend()
{
// TODO: Add your command handler code here
DWORD cx = m_pImage->GetWidth()/10;
DWORD cy = m_pImage->GetHeight()/10;
RGBQUAD backColor = {255, 255, 255, 0};
m_pImage->Expand(cx, cy, cx, cy, backColor);
UpdateAllViews(NULL);
}
void CImageDoc::OnImageThumbnail()
{
// TODO: Add your command handler code here
RGBQUAD backColor = {255, 255, 255, 0};
m_pImage->Thumbnail(100, 100, backColor);
UpdateAllViews(NULL);
}
void CImageView::OnDraw(CDC* pDC)
{
CImageDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(pDoc->m_pImage)
{
pDoc->m_pImage->Draw(pDC->GetSafeHdc(),
CRect(0, 0, (int)(pDoc->m_pImage->GetWidth()),(int)(pDoc->m_pImage->GetHeight())));
}
}