Re: display array in a frame wnd



It looks like Scott and Dan have answered this fairly thoroughly.

Critical thing about the GetDC() was that by calling it you obtain a DC, but you never
release it. You keep coming up with very convoluted ways to accomplish rather simple
things, such as not using the CPaintDC, or using pointers when pointers aren't necessary,
etc. Try for simpler code, it will come up faster and work more reliably.
joe
On Fri, 7 Sep 2007 18:28:15 +0200, "J-F Portala" <jfportala@xxxxxxx> wrote:

Hi Joseph,

I think you are probably right in the fact that my first applications using
document/view
were not satisfying me and and I did not go further.

At the moment, I think it will take me long time to understand correctly
document/view architecture and use
it correctly.
I have also to reconsider my class architecture (vision system - grabbing
system - cameras - external communications - image processing.- api
sequence..),
which is not easy. Some display are corresponding to several cameras (global
display), others are only for cameras.

I can't spend too much time for self training, and I have difficulties to
evaluate necessary time.
That is the reason why I go on my work on CFrameWnd. But perhaps CView can
be used as a CFramWnd
wich permits me perhaps to migrate slowly.

Here is the code I have used to display my IplImage* (pointer on my image
structure).
It works and I think the method to display the image in a CView or a
CFrameWnd must be similar.

CDisplayImg is a subclass of CFrameWnd
I just have to create a CDisplay object and
use
pDisplayImg->ShowImage(pImg) ;
to get a window with my image.

But, I have a little problem and perhaps you will have an idea.
When I resize the window(with the mouse on the border frame), the
refreshment is uncomfortable because it
goes from image to blank to image etc (it is flashing).

I have put the fonction DrawToHDC in the on paint function of the window.
Is there a technique to avoid this flashing.
It is the same if I want to draw with the mouse a rectangle (simulation of
selecting area)
If I want to see the drawing, it is flashing.
I think it is due to refreshment but I have no idea to optimize it.

Do you see something wrong.

Thank you for your help

Jeff

void CDisplayImg::ShowImage(IplIMage* pImg)
{
m_pImg = pImg ;
CRect rect ;
GetClientRect(&rect) ;
DrawToHDC(this->GetDC()->m_hDC,rect) ;
}

void CDisplayImg::DrawToHDC( HDC hDCDst, RECT* pDstRect,bool bFlag )
{
if( pDstRect && m_pImg && m_pImg->depth == IPL_DEPTH_8U &&
m_pImg->imageData )
{
int bmp_w = m_pImg->width, bmp_h = m_pImg->height;

CvRect roi = cvGetImageROI( m_pImg );
CvRect dst = RectToCvRect( *pDstRect );

if( roi.width == dst.width && roi.height == dst.height )
{
Show( hDCDst, dst.x, dst.y, dst.width, dst.height, roi.x,
roi.y );
return;
}

if( roi.width > dst.width )
{
SetStretchBltMode(
hDCDst, // handle to device context
HALFTONE );
}
else
{
SetStretchBltMode(
hDCDst, // handle to device context
COLORONCOLOR );
}

FillBitmapInfo( bmi, bmp_w, bmp_h, Bpp(), m_pImg->origin );

::StretchDIBits(
hDCDst,
dst.x, dst.y, dst.width, dst.height,
roi.x, roi.y, roi.width, roi.height,
m_pImg->imageData, bmi, DIB_RGB_COLORS, SRCCOPY );
}
}

void CDisplayImg::FillBitmapInfo( BITMAPINFO* bmi, int width, int height,
int bpp, int origin )
{
assert( bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 ||
bpp == 32));

BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);

memset( bmih, 0, sizeof(*bmih));
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = width;
bmih->biHeight = origin ? abs(height) : -abs(height);
bmih->biPlanes = 1;
bmih->biBitCount = (unsigned short)bpp;
bmih->biCompression = BI_RGB;

if( bpp == 8 )
{
RGBQUAD* palette = bmi->bmiColors;
int i;
for( i = 0; i < 256; i++ )
{
palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed =
(BYTE)i;
palette[i].rgbReserved = 0;
}
}
}

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • [PATCH 2/2] display: Driver ks0108 and cfag12864b
    ... Adds support for additional "display" devices, ... +static const unsigned int FirstMinor = 0; ... +void cfag12864b_E(unsigned char _State) ... +void cfag12864b_CS1 ...
    (Linux-Kernel)
  • Re: display array in a frame wnd
    ... document/view architecture and use ... Some display are corresponding to several cameras (global ... void CDisplayImg::FillBitmapInfo(BITMAPINFO* bmi, int width, int height, ... int bpp, int origin) ...
    (microsoft.public.vc.mfc)
  • Cone display
    ... display but I cannot get this to work could someone explain to me how ... void display ... void reshape(int w, int h) ... void ExtractCommandLineParameters(int argc, char **argv) ...
    (comp.graphics.api.opengl)
  • Re: polymorph object - why doesnt it work???
    ... virtual void display() const; ... class Node: public Cell { ... void insert(char*, int); ...
    (comp.lang.cpp)
  • Accessing base class method using derived class object
    ... using namespace std; ... void display() ... int main ...
    (microsoft.public.dotnet.framework.clr)

Loading