jase jennings
February 13th, 2003, 05:06 PM
Hi,
I'm creating a thumbnail of an image, and placing it into an image list for use in a CListCtrl.
Problem is, my image appears upside down !
Can somebody please take a qick look at my code and see if you can see any obvious reason as to why the dib i create appears upside down ?
Here's the code. Don't worry about the ImageObject and ImageData stuff, they're classes from an image processing library. Effectively, ImageObject is used to load the image from disk file. ImageData respresents the bitmap and all it's attributes. It's the gdi stuff that's the problem ...
void CThumbnailDlg::DrawThumbnails()
{
CBitmap* pImage = NULL;
HBITMAP hBitmap = NULL;
HPALETTE hPal = NULL;
HDC hMemDC = NULL;
HGDIOBJ hOldObj = NULL;
POINT pt;
CFile ImgFile;
CDib dib;
CString strPath;
int nWidth, nHeight;
// no images
if(m_VectorImageNames.empty())
return;
// set the length of the space between thumbnails
// you can also calculate and set it based on the length of your list control
int nGap = 6;
// hold the window update to avoid flicking
m_ListThumbnail.SetRedraw(FALSE);
// reset our image list
for(int i=0; i<m_ImageListThumb.GetImageCount(); i++)
m_ImageListThumb.Remove(i);
// remove all items from list view
if(m_ListThumbnail.GetItemCount() != 0)
m_ListThumbnail.DeleteAllItems();
// set the size of the image list
m_ImageListThumb.SetImageCount(m_VectorImageNames.size());
i = 0;
// draw the thumbnails
std::vector<CString>::iterator iter;
for(iter = m_VectorImageNames.begin(); iter != m_VectorImageNames.end(); iter++)
{
// load the bitmap
//strPath = m_strImageDir + "\\" + *iter;
//ImgFile.Open(strPath, CFile::modeRead);
//dib.Read(ImgFile);
//ImgFile.Close();
BTCImageObject ImageObject;
BTCImageData ImageData;
if(!ImageObject.Load("c:\\a.jpg"))
{
AfxMessageBox("Error loading jpg");
}
ImageData = ImageObject.GetObjectData();
LPBITMAPINFO bmi = ImageData.GetBitmapInfo();
// borrow our dib header to create our thumbnail bitmap
nWidth = ImageData.GetWidth();
nHeight = ImageData.GetHeight();
bmi->bmiHeader.biWidth = THUMBNAIL_WIDTH;
bmi->bmiHeader.biHeight = THUMBNAIL_HEIGHT;
I'm creating a thumbnail of an image, and placing it into an image list for use in a CListCtrl.
Problem is, my image appears upside down !
Can somebody please take a qick look at my code and see if you can see any obvious reason as to why the dib i create appears upside down ?
Here's the code. Don't worry about the ImageObject and ImageData stuff, they're classes from an image processing library. Effectively, ImageObject is used to load the image from disk file. ImageData respresents the bitmap and all it's attributes. It's the gdi stuff that's the problem ...
void CThumbnailDlg::DrawThumbnails()
{
CBitmap* pImage = NULL;
HBITMAP hBitmap = NULL;
HPALETTE hPal = NULL;
HDC hMemDC = NULL;
HGDIOBJ hOldObj = NULL;
POINT pt;
CFile ImgFile;
CDib dib;
CString strPath;
int nWidth, nHeight;
// no images
if(m_VectorImageNames.empty())
return;
// set the length of the space between thumbnails
// you can also calculate and set it based on the length of your list control
int nGap = 6;
// hold the window update to avoid flicking
m_ListThumbnail.SetRedraw(FALSE);
// reset our image list
for(int i=0; i<m_ImageListThumb.GetImageCount(); i++)
m_ImageListThumb.Remove(i);
// remove all items from list view
if(m_ListThumbnail.GetItemCount() != 0)
m_ListThumbnail.DeleteAllItems();
// set the size of the image list
m_ImageListThumb.SetImageCount(m_VectorImageNames.size());
i = 0;
// draw the thumbnails
std::vector<CString>::iterator iter;
for(iter = m_VectorImageNames.begin(); iter != m_VectorImageNames.end(); iter++)
{
// load the bitmap
//strPath = m_strImageDir + "\\" + *iter;
//ImgFile.Open(strPath, CFile::modeRead);
//dib.Read(ImgFile);
//ImgFile.Close();
BTCImageObject ImageObject;
BTCImageData ImageData;
if(!ImageObject.Load("c:\\a.jpg"))
{
AfxMessageBox("Error loading jpg");
}
ImageData = ImageObject.GetObjectData();
LPBITMAPINFO bmi = ImageData.GetBitmapInfo();
// borrow our dib header to create our thumbnail bitmap
nWidth = ImageData.GetWidth();
nHeight = ImageData.GetHeight();
bmi->bmiHeader.biWidth = THUMBNAIL_WIDTH;
bmi->bmiHeader.biHeight = THUMBNAIL_HEIGHT;