-
October 15th, 2012, 03:34 PM
#1
Copy CImage to clipboard
Code:
CImage tmpImage = pDoc->m_imageArray[0];
int w = tmpImage.GetWidth();
int h = tmpImage.GetHeight();
int Bpp = tmpImage.GetBPP();
BITMAPINFOHEADER bmInfohdr;
bmInfohdr.biSize = sizeof(BITMAPINFOHEADER);
bmInfohdr.biWidth = w;
bmInfohdr.biHeight = -h;
bmInfohdr.biPlanes = 1;
bmInfohdr.biBitCount = Bpp;
bmInfohdr.biCompression = BI_RGB;
bmInfohdr.biSizeImage = w*h*Bpp;
bmInfohdr.biXPelsPerMeter = 0;
bmInfohdr.biYPelsPerMeter = 0;
bmInfohdr.biClrUsed = 0;
bmInfohdr.biClrImportant = 0;
BITMAPINFO bmInfo;
bmInfo.bmiHeader = bmInfohdr;
bmInfo.bmiColors[0].rgbBlue=255;
void* pBits = tmpImage.GetBits();
HANDLE hData = ::GlobalAlloc (GMEM_MOVEABLE, sizeof(BITMAPINFO) + w * h * 3);
LPVOID pData = (LPVOID) ::GlobalLock (hData);
LPBYTE p_imagebits;
p_imagebits = (LPBYTE)pData + sizeof(BITMAPINFO);
memcpy(pData,&bmInfo,sizeof(BITMAPINFO));
DWORD dwBytes = ((DWORD) w * Bpp) / 32;
if(((DWORD) w * Bpp) % 32) {
dwBytes++;
}
dwBytes *= 4;
unsigned long m_dwSizeImage = dwBytes * h; // no compression
memcpy (p_imagebits, pBits, m_dwSizeImage);
::GlobalUnlock (hData);
COleDataSource* pods = new COleDataSource;
pods->CacheGlobalData (CF_DIB, hData);
pods->SetClipboard ();
I'm trying to copy the DIB from the CImage into the clipboard. I get an access read violation on the second memcpy. Can anyone explain what I've done wrong?.
-
October 16th, 2012, 06:11 AM
#2
Re: Copy CImage to clipboard
Originally Posted by jcjc
Code:
HANDLE hData = ::GlobalAlloc (GMEM_MOVEABLE, sizeof(BITMAPINFO) + w * h * 3);
// ...
DWORD dwBytes = ((DWORD) w * Bpp) / 32;
if(((DWORD) w * Bpp) % 32) {
dwBytes++;
}
dwBytes *= 4;
unsigned long m_dwSizeImage = dwBytes * h; // no compression
// ...
memcpy (p_imagebits, pBits, m_dwSizeImage);
How many bytes did you allocate and how many are you copying?
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
October 16th, 2012, 12:32 PM
#3
Re: Copy CImage to clipboard
CImage::GetBits:
Return Value
A pointer to the bitmap buffer. If the bitmap is a bottom-up DIB, the pointer points near the end of the buffer. If the bitmap is a top-down DIB, the pointer points to the first byte of the buffer.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|