Solved

How do I resize a CBitmap?

Posted on 2000-04-25
6
1,376 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
List out all word 7 317
Hibernate methods 2 77
isEverywhere  challenge 19 82
wordappend challenge 8 200
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

829 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