cpicturecpicture
The code for dialog box:
void cLiveJPEG::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetDlgItem(IDC_STATIC_MJPEGWIN)->GetClientRect(&rect);
CWnd *pWnd = (CWnd*)GetDlgItem(IDC_STATIC_MJPEGWIN);
if (pWnd){
CDC *pDC = pWnd->GetDC();
CMemDC cDC(pDC);
m_cPict->Show(&cDC, rect);
}
}
#ifndef _MEMDC_H_
#define _MEMDC_H_
//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email: keithr@europa.com
//
// You may freely use or modify this code provided this
//
// History - 10/3/97 Fixed scrolling bug.
//Added print support. - KR
//
//11/3/99 Fixed most common complaint. Added
//background color fill. - KR
//
//11/3/99 Added support for mapping modes other than
//MM_TEXT as suggested by Lee Sang Hun. - KR
//
// This class implements a memory Device Context which allows
// flicker free drawing.
class CMemDC : public CDC {
private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_oldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
public:
CMemDC(CDC* pDC, const CRect* pRect = NULL) : CDC()
{
ASSERT(pDC != NULL);
// Some initialization
m_pDC = pDC;
m_oldBitmap = NULL;
m_bMemDC = !pDC->IsPrinting();
// Get the rectangle to draw
if (pRect == NULL) {
pDC->GetClipBox(&m_rect);
} else {
m_rect = *pRect;
}
if (m_bMemDC) {
// Create a Memory DC
CreateCompatibleDC(pDC);
pDC->LPtoDP(&m_rect);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_oldBitmap = SelectObject(&m_bitmap);
SetMapMode(pDC->GetMapMode());
pDC->DPtoLP(&m_rect);
SetWindowOrg(m_rect.left, m_rect.top);
} else {
// Make a copy of the relevent parts of the current DC for printing
m_bPrinting = pDC->m_bPrinting;
m_hDC= pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
// Fill background
FillSolidRect(m_rect, pDC->GetBkColor());
}
~CMemDC()
{
if (m_bMemDC) {
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY);
//Swap back the original bitmap.
SelectObject(m_oldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
}
// Allow usage as a pointer
CMemDC* operator->()
{
return this;
}
// Allow usage as a pointer
operator CMemDC*()
{
return this;
}
};
#endif
In MS PowerPoint, Big picture(4MB Jpg) can be rotated really fast.
I was wondering if PowerPoint is using IPicture.
Anybody please give me a clue?
Useful.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
Hi,
Thanks you for CPicture class, I derived it from CStatic and now I can place a CStatic image in my dialog resource editor to put the final place and size of the image, borders, ..., it help me a lot of.
Bye.
I want to put image to IDC_STATIC control.
How do I use it ?
This is my code below, but it display nothing.
bool bGetBitmap = false;
OnPaint()
{
if (bGetBitmap) {
CStatic *pStaic;
pStaic=(CStatic*)GetDlgItem(IDC_STATIC_BITMAP);
CDC *pDc;
pDc = pStaic->GetDC();
CRect ClientArea;
pStaic->GetWindowRect(&ClientArea);
m_Picture.UpdateSizeOnDC(pDc);
m_Picture.Show(pDc,CRect(0,0,ClientArea.Width(),ClientArea.Height()));
}
}
OnButton1()
{
bGetBitmap = true;
m_Picture.Load("C:\\123.bmp");
Invalidate();
}
do like this :
CRect m_ClientRect;
m_ctlFOTO.GetClientRect(&m_ClientRect);
m_Picture.Show(m_ctlFOTO.GetWindowDC(), m_ClientRect);
***
m_ctlFOTO is a control variable for the static container
Hi,
I am using these great classes to display images with Visual C++ .Net. The only thing is when I load a big image, I would need some scrollbar on the side to be able to look at the entire picture, do anyone would know how to do that ?
Thanks
Hi,
I am looking for a way to obtain the pixels value of the loaded image, do you have any idea ?
Thanks a lot !
It too searching the way to load different image format from the RESOURCE.
thanks
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
Add this member function to class CPicture.
// Caller should call ::DeletecObject(hbitmap_got) later.
HBITMAP CPicture::GetBitmap(CDC* pDC)
{
HBITMAP hbitmap = NULL;
if(m_pPicture != NULL)
{
CSize size = GetSize(pDC);
HDC hdc = ::CreateCompatibleDC(pDC->GetSafeHdc());
if(hdc)
{
hbitmap = ::CreateCompatibleBitmap(hdc, size.cx, size.cy);
if(hbitmap)
{
HBITMAP hbitmapOld = (HBITMAP) ::SelectObject(hdc, hbitmap);
Draw( CDC::FromHandle(hdc) );
::SelectObject(hdc, hbitmapOld);
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-27278-1.html
很棒棒哒
再说了
好好伤心