Solved

How do I resize a CBitmap?

Posted on 2000-04-25
6
1,340 Views
Last Modified: 2013-11-20
Ive got several bitmaps of varying dimensions between 5*5 and 20*25. I need to be able to resize them programatically to a standard 16*16 bits to fit into an existing CImageList.
Any ideas how I do this? Code appreciated.

Thanks in advance
Yakky
0
Comment
Question by:yakky
6 Comments
 
LVL 2

Expert Comment

by:DKostov
Comment Utility
0
 
LVL 4

Expert Comment

by:captainkirk
Comment Utility
A nice way to do this is to use a DIB or Device Independent Bitmap instead - some image processing software like PaintShop Pro will do the conversion for you. If this is of interest to you, I can provide code to load and display DIBs...
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
Comment Utility
1. Create a CBitmap with desired size using CBitmap::CreateCompatibleBitmap.

2. Create two memory DC using CDC::CreateCompatibleDC.

3. Select the original bitmap and the newly created bitmap into two memory DC respectively.

4. Use CDC::StretchBlt to copy the original bitmap to the newly created bitmap.

5. Deselect the two bitmaps from the memory DCs.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:yakky
Comment Utility
Ok Ive got this far but have got stuck,
can anyone help
Thanks
Yakky

hSmallicon = LoadImage(0, file, IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

if ((hSmallicon !=NULL))
{
   CBitmap bmp = new CBitmap;
   CBitmap ibmp;
   bmp->Attach(hSmallicon);
   CDC     dc1, dc2;  

   ibmp.CreateCompatibleBitmap&dc2,16,16);
CDC    *pWndDC;
pWndDC= AfxGetMainWnd()->GetDC();
if(pWndDC)
{
   dc1.CreateCompatibleDC(pWndDC);
   dc2.CreateCompatibleDC(pWndDC);
   AfxGetMainWnd()->ReleaseDC(pWndDC);
}
if (SelectObject(dc1,m_bmp)==NULL)
{
   TRACE("not selected m_bmp\n");
}
if (SelectObject(dc2,ibmp)==NULL)
{
   TRACE("not selected m_bmp\n");
}
      
TRACE("%d\n",
StretchBlt(dc2.m_hDC, 0, 0,16,16, dc1,0,0,16,16,SRCCOPY));
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
CBitmap bmpDest;
const int nWidth = 16, nHeight = 16;

hSmallicon = ::LoadImage(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

if (hSmallicon != NULL)
{
    CBitmap bmpOrig;
    bmpOrig.Attach(hSmallicon);
    BITMAP b;
    bmpOrig.GetBitmap(&b);

    CDC ScrnDC, dc1, dc2;
    ScrnDC.CreateIC(_T("DISPLAY"), NULL, NULL, NULL);
    dc1.CreateCompatibleDC(&ScrnDC);
    dc2.CreateCompatibleDC(&ScrnDC);

    bmpDest.CreateCompatibleBitmap(&ScrnDC, nWidth, nHeight);

    ScrnDC.DeleteDC();

    CBitmap *pOldBmp1 = dc1.SelectObject(bmpOrig),
            *pOldBmp2 = dc2.SelectObject(bmpDest);

    dc2.StretchBlt(0, 0, nWidth, nHeight, &dc1, 0, 0, b.bmWidth, b.bmHeight, SRCCOPY);
   
    dc1.SelectObject(pOldBmp1);
    dc2.SelectObject(pOldBmp2);

    bmpOrig.Detach();

    ::DeleteObject(hSmallicon);
}
0
 

Author Comment

by:yakky
Comment Utility
Thank you very much indead

Yakky
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 94
sumDigits challenge 9 95
if loop in java 3 114
zeroFront challenge 7 70
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now