Solved

How do I resize a CBitmap?

Posted on 2000-04-25
6
1,364 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 117
difference between String.subString() and String.subSequence() 6 200
sum67 challenge 35 101
mapAB Challlenge 35 146
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 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