Click here to Skip to main content
15,917,454 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Yet another problem with LPCTSTR 2 Pin
GDavy23-Jun-05 3:49
GDavy23-Jun-05 3:49 
GeneralRe: Yet another problem with LPCTSTR 2 Pin
Cedric Moonen23-Jun-05 3:55
Cedric Moonen23-Jun-05 3:55 
GeneralRe: Yet another problem with LPCTSTR 2 Pin
GDavy23-Jun-05 8:44
GDavy23-Jun-05 8:44 
GeneralRe: Yet another problem with LPCTSTR 2 Pin
Cedric Moonen23-Jun-05 8:45
Cedric Moonen23-Jun-05 8:45 
GeneralRe: Yet another problem with LPCTSTR 2 Pin
tomek1823-Jun-05 3:45
tomek1823-Jun-05 3:45 
GeneralRe: Yet another problem with LPCTSTR 2 Pin
GDavy23-Jun-05 3:59
GDavy23-Jun-05 3:59 
GeneralRe: Yet another problem with LPCTSTR 2 Pin
tomek1824-Jun-05 2:00
tomek1824-Jun-05 2:00 
GeneralDrawing Image on Device Context Pin
swati2423-Jun-05 2:27
swati2423-Jun-05 2:27 
Hi,

I am writing an application which supports loading, processing, and displaying of various image file formats.

I have a class, CDib, derived from CBitmap that displays the bitmap data on the device context supplied using BitBlt(...). I think this is a fairly general way dc voodoo.

//!Code Snippet (1)
//!CDib is derived from CBitmap
//!@param dc: reference to CDC where the image is to be drawn
//!@param pbm: CBitmap pointer that contains the image data, in most cases a pointer to itself

BOOL CDib::Draw(CDC& dc, CBitmap* pbm, const CRect* rcDst, const CRect* rcSrc)
{
CRect rc;
if (!rcSrc) {
// if no source rect, use whole bitmap
rc = CRect(CPoint(0,0), GetBitmapSize(pbm));
rcSrc=&rc;
}
if (!rcDst)
// if no destination rect, use source
rcDst=rcSrc;

bool bRet;

//Create a memory DC and load the bitmap onto it
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap* pOld = (CBitmap*)(memDC.SelectObject(pbm));

if(rcSrc->Size() == rcDst->Size()){
bRet = dc.BitBlt(rcDst->left, rcDst->top,
rcDst->Width(), rcDst->Height(),
&memDC, rcSrc->left, rcSrc->top, SRCCOPY);

} else{
dc.SetStretchBltMode(COLORONCOLOR);
bRet = dc.StretchBlt(rcDst->left, rcDst->top,
rcDst->Width(), rcDst->Height(),
&memDC, rcSrc->left, rcSrc->top, rcSrc->Width(), rcSrc->Height(),
SRCCOPY);
}


//!Delete the memory DC
memDC.DeleteDC();

return bRet;
}

This function works fine if I load a BMP file using CBitmap::LoadImage(...).

Now,since the program can load other image file formats, I tried using CBitmap::CreateBitmap(...) but that didn't work. So, what I have done now is to use CreateCompatibleBitmap(...) and CreateCompatibleDC(...) to create a CDC and CBitmap object, and then linked them together using SelectObject(..), and then use SetPixel(...), now the problem is that SetPixel(...) is very very slow. I want to ask the readers if there is an alternate way to SetPixel where I can load a chunk of image data to the CBitmap object, and then pass it to CDib::Draw(..) function.

//!Code snippet 2
//!@param pData: image data that needs to be displayed

void CImageDraw::CreateBitmap(BYTE* pData)
{
//!Create a DC
CDC dc;
dc.CreateCompatibleDC(NULL);

//!If m_dib exists delete it
if((HBITMAP)m_dib)
m_dib.DeleteObject();

m_dib.CreateCompatibleBitmap(AfxGetMainWnd()->GetDC(), m_nImgWidth, m_nImgHeight);

CBitmap *pOldBitmap = (CBitmap *)dc.SelectObject(&m_dib);

for(int y = 0; y < m_nImgHeight; y++){
for(int x = 0; x < m_nImgWidth; x++){
//!This is very very slow.....I need an alternative
dc.SetPixel(x,m_nImgHeight-1-y, RGB(pData[3*x+2+y*m_nImgWidth*3], pData[3*x+1+y*m_nImgWidth*3], pData[3*x+y*m_nImgWidth*3]));
}
}

dc.SelectObject(pOldBitmap);
dc.DeleteDC();
}


Thanking in anticipation
Swati
Generalsave as html format Pin
Ashok_kavi23-Jun-05 1:19
Ashok_kavi23-Jun-05 1:19 
GeneralRe: save as html format Pin
khan++23-Jun-05 1:40
khan++23-Jun-05 1:40 
Generalresx file use from plain C++ problem Pin
keletron23-Jun-05 0:13
keletron23-Jun-05 0:13 
Questionwhy does CreateInstance(&quot;ADODB.Connection&quot;) bring out exception? Pin
liuyue22-Jun-05 23:31
liuyue22-Jun-05 23:31 
AnswerRe: why does CreateInstance(&quot;ADODB.Connection&quot;) bring out exception? Pin
David Crow23-Jun-05 4:05
David Crow23-Jun-05 4:05 
Generalbroland c++ source code to visual c++ Pin
formula_200222-Jun-05 23:16
formula_200222-Jun-05 23:16 
GeneralRe: broland c++ source code to visual c++ Pin
Cedric Moonen22-Jun-05 23:24
Cedric Moonen22-Jun-05 23:24 
GeneralRe: broland c++ source code to visual c++ Pin
formula_200222-Jun-05 23:53
formula_200222-Jun-05 23:53 
GeneralRe: broland c++ source code to visual c++ Pin
toxcct23-Jun-05 0:40
toxcct23-Jun-05 0:40 
GeneralToggle Buttons Pin
Extreme_Coder22-Jun-05 23:02
Extreme_Coder22-Jun-05 23:02 
GeneralThread is needed Pin
Ghasrfakhri22-Jun-05 23:16
Ghasrfakhri22-Jun-05 23:16 
GeneralRe: Toggle Buttons Pin
khan++23-Jun-05 0:06
khan++23-Jun-05 0:06 
GeneralRe: Toggle Buttons Pin
David Crow23-Jun-05 4:07
David Crow23-Jun-05 4:07 
QuestionHow can i change color of a specific word in a sentence Pin
emmatty22-Jun-05 22:19
emmatty22-Jun-05 22:19 
AnswerRe: How can i change color of a specific word in a sentence Pin
Cedric Moonen22-Jun-05 22:25
Cedric Moonen22-Jun-05 22:25 
GeneralRe: How can i change color of a specific word in a sentence Pin
emmatty22-Jun-05 22:30
emmatty22-Jun-05 22:30 
GeneralRe: How can i change color of a specific word in a sentence Pin
ThatsAlok22-Jun-05 22:51
ThatsAlok22-Jun-05 22:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.