Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 785309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:51:24+00:00 2026-05-14T20:51:24+00:00

Hi there dear gurus and expert coders. i am not gonna start with im

  • 0

Hi there dear gurus and expert coders.

i am not gonna start with im a newbie and don’t know much about image programming but unfortunately those are the facts 🙁

I am trying to display an image from a bitmap pointer *ImageData which is of resolution
1392×1032. I am trying to draw that at an area of resolution or size 627×474.

However, repeated trying doesnt seem to work. It works when I change the bitmap image I created from *ImageData width and height to resolution or size of around 627×474

I really do not know how to solve this after trying all possible solutions from various forums and google.

pDC is a CDC* and memDC is a CDC initialized in an earlier method
Anything uninitialized here was initialized in other methods.

Here is my code dear humble gurus. Do provide me with guidance Yoda and Obi-Wan provided to Luke Skywalker.

void DemoControl::ShowImage( void *ImageData )
{


    int Width; //Width of Image From Camera
    int Height; //Height of Image From Camera

    int m_DisplayWidth = 627 ;//width of rectangle area to display
    int m_DisplayHeight = 474;//height of rectangle area to display

    GetImageSize( &Width, &Height ) ; //this will return Width = 1392, Height 1032

    CBitmap bitmap;

    bitmap.CreateBitmap(Width,Height,32,1,ImageData);

    CBitmap* pOldBitmap = memDC.SelectObject((CBitmap*)&bitmap);

    pDC->BitBlt(22, 24, 627, 474, &memDC, 0, 0, SRCCOPY);

    memDC.SelectObject((CBitmap*)pOldBitmap);

    ReleaseDC(pDC);

}

Ok heres some additional parts

I think i should explain how the flow goes.

(a) A class (lets say DemoTestingDlg class) will pass the CDC as below to another class (lets say DemoControl class)

m_Demo = new DemoControl ; 

m_Demo->Initialisation( this, this->GetDC() ) ; 

(b) At the DemoControl class

bool DemoControl::Initialisation( CDemoTestingDlg m_FormControl, CDC m_StaticDisplay ) {

          pDC = m_StaticDisplay ; 
          memDC.CreateCompatibleDC(pDC); 

}

pDC and memDC is as such in the header:

CDC* pDC ; CDC memDC; 

(c) If lets say an image is captured, the image pointer is passed to the DemoTestingDlg class which will subsequently call a showImage method in the Demo Control Class which is the method I wrote in the question. Am i doing it right?

Note: It did show an image if lets say they are of the same size (by they i mean the CDC and bitmap) so i was under the impression that my CDC pointer was passed correctly

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:51:25+00:00Added an answer on May 14, 2026 at 8:51 pm

    StretchBlt is your friend 🙂

    Edit: OK how do you get pDC? When is your function called? Form OnPaint or DrawItem?

    This is a StretchBlt I do from a DrawItem call in an overriden CStatic.

    HDC hBitmapDC   = CreateCompatibleDC( pDrawItemStruct->hDC );
    
    HBITMAP hBitmap = GetBitmap();
    HGDIOBJ hOld    = SelectObject( hBitmapDC, (HGDIOBJ)hBitmap );
    
    StretchBlt( pDrawItemStruct->hDC, pDrawItemStruct->rcItem.left, pDrawItemStruct->rcItem.top, pDrawItemStruct->rcItem.right, pDrawItemStruct->rcItem.bottom,
                hBitmapDC, 0, 0, 4, 4, SRCCOPY );
    
    SelectObject( hBitmapDC, hOld );
    DeleteObject( hBitmapDC );
    

    Its not using the MFC classes to stretch a 4×4 bitmap into a larger space but works perfectly. My guess is that you aren’t doing it in response to a WM_PAINT/WM_DRAWITEM and/or are using the wrong DC.

    Edit re your edit: Do you then call DrawImage from inside an OnPaint or DrawItem call?

    I would have thought you are better off not cacheing that CDC and passing the CDC in each time you wish to draw it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are nice SO question and answers about this issue, but these options didn't
There was a similar question posted asking in general about alternatives to Qt. Well,
Dear all devexpress winform gurus:) My way is simple. First, i create a bindinglist:
Dear Guys I am somehow newbie and sometimes guru , but at this moment
Dear all, is there a way to scroll, as in relatively shift the contents
Dear stackoverflow users, Some years ago i used mathematica for several months. After not
Dear folks, There seems to be a problem with password protection for accessing a
There's documentation about chrome.sockets on http://developer.chrome.com/ , but I can't find anything concerning chrome.experimental.sockets
Dear Powershell Gurus, I have a few thousands of files in a folder called
Dear developers out there, I have an application up and running with the Telerik

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.