Solved

How do I resize a CBitmap?

Posted on 2000-04-25
6
1,401 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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