[vtkusers] Animation using bitmaps -> Adapting code from OnEditCopy (MFC)

Ted Christiansen ted at caept.com
Thu Sep 5 14:40:52 EDT 2002


Hello,

I am trying to add animation to my application by generating frames
which are stored as bitmaps and then are redisplayed.  I was using the
vtkRendererSource, vtkBMPwriter and an array of CPicture objects (from
www.codeproject.com).  Sometimes it worked, but other times it crashed
while doing a recursive write in vtkImageWriter (I think).

A better way might be to adapt the code from vtkMFCview::OnEditCopy.
The question is once I have this bitmap data how do I redraw it on the
CDC?

Ted

 LPBITMAPINFOHEADER  lpbi;   // pointer to BITMAPINFOHEADER
 DWORD               dwLen;   // size of memory block
 HANDLE              hDIB = NULL; // handle to DIB, temp handle

 vtkWindow *vtkWin   = pView->GetVTKWindow();
 int       *size     = vtkWin->GetSize();
 int       dataWidth = ((size[0]*3+3)/4)*4;

    dwLen = sizeof(BITMAPINFOHEADER) + dataWidth*size[1];

 // allocate memory for the bitmap
 hDIB = ::GlobalAlloc(GHND, dwLen);

 // setup bitmap info header
 lpbi = (LPBITMAPINFOHEADER) ::GlobalLock(hDIB);
 lpbi->biSize = sizeof(BITMAPINFOHEADER);
 lpbi->biWidth = size[0];
 lpbi->biHeight = size[1];
 lpbi->biPlanes = 1;
 lpbi->biBitCount = 24;
 lpbi->biCompression = BI_RGB;
 lpbi->biClrUsed = 0;
 lpbi->biClrImportant = 0;
 lpbi->biSizeImage = dataWidth*size[1];

   // start memory rendering
 pView->SetupMemoryRendering(size[0],size[1],
pView->GetDC()->GetSafeHdc());
    vtkWin->Render();

 // copy the bitmap data into the bitmap
    memcpy((LPSTR)lpbi + lpbi->biSize, pView->GetMemoryData(),
dataWidth*size[1]);

 ::GlobalUnlock(hDIB);

 // turn screen rendering back on
 pView->ResumeScreenRendering();

// now how can we draw this bitmap on the view (CDC)?





More information about the vtkusers mailing list