Solved

How do I resize a CBitmap?

Posted on 2000-04-25
6
1,412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:DKostov
ID: 2748931
0
 
LVL 4

Expert Comment

by:captainkirk
ID: 2749164
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
ID: 2749655
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:yakky
ID: 2750527
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
ID: 2751950
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
ID: 2752138
Thank you very much indead

Yakky
0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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