473,320 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can’t Display Bitmap of Higher Resolution than CDC area

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 1392x1032. I am trying to draw that at an area of resolution or size 627x474.

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 627x474

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.

Expand|Select|Wrap|Line Numbers
  1. void DemoControl::ShowImage( void *ImageData ) 
  2.     int Width; //Width of Image From Camera 
  3.     int Height; //Height of Image From Camera 
  4.  
  5.     int m_DisplayWidth = 627 ;//width of rectangle area to display 
  6.     int m_DisplayHeight = 474;//height of rectangle area to display 
  7.  
  8.     GetImageSize( &Width, &Height ) ; //this will return Width = 1392, Height 1032 
  9.  
  10.     CBitmap bitmap; 
  11.     bitmap.CreateBitmap(Width,Height,32,1,ImageData); 
  12.     CBitmap* pOldBitmap = memDC.SelectObject((CBitmap*)&bitmap); 
  13.  
  14.     pDC->BitBlt(22, 24, 627, 474, &memDC, 0, 0, SRCCOPY); 
  15.     memDC.SelectObject((CBitmap*)pOldBitmap); 
  16.     ReleaseDC(pDC); 
  17.  
  18.  
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. I have also tried StretchBlt and got the same results.
May 17 '10 #1
4 2468
Banfa
9,065 Expert Mod 8TB
You haven't said what results you are getting, however as currently written, assuming both DCs are still valid when the method gets called then you should get the top left portion of the bitmap copied to the screen.

You will need to use StretchBlt to transform the bigger image onto the smaller screen.

Also what are you doing in the window in response to the WM_PAINT message? The default WM_PAINT handler will clear the window to the background colour. it is normally a mistake to draw outside this handler as anything drawn that way is normally only temporary.
May 17 '10 #2
@Banfa
Thanks for the reply banfa. I am having trouble displaying my image of 1392x1032 on the CDC area which is of size 627x474. It works fine if lets say my image is of around 627x474.

Another question:

bitmap.CreateBitmap(Width,Height,32,1,ImageData);
I am working with a monochrome bitmap therefore in my CreateBitmap
method, the nPlanes should be '1' and the bitCount should be '8'.(please
correct me if im wrong)

However, when I set it as such, my cdc does not display anything and if i put the bitCount as 1, it displays noise whereas anything other than that, I will get nothing.

Here is what i put for my onpaint method

void CDemoTestingDlg::OnPaint()
{
if (IsIconic())
{
CDC* pDC = GetDC();

// Select as object(transparent brush)
pDC->SelectStockObject(NULL_BRUSH);

// Draw
pDC->Rectangle(22, 24, 649, 498);
ReleaseDC(pDC);
}
else
CDialog::OnPaint();

}
May 18 '10 #3
Banfa
9,065 Expert Mod 8TB
Right well I have written several programs that used a memory bitmap image to copy to the actual window.

However in all of them what I did was store (and write to) the memory image where ever I chose but then having written to the memory image called invalidateRect and have the WM_PAINT handler BitBlt or StretchBlt the memory bitmap onto the screen. That ensures that the window is drawn correctly even if another window is temporarily placed over it.

I suggest you do the same as it took me several days of experimenting to conclude this was the easiest and simplest way to get the desired behaviour consistently.
May 18 '10 #4
Alright i forgot to reply to this! I solved it by using DIB and HDC instead! So if anyone has the same prob can ask me n i'll pass u the codes if you are facing the same prob!
May 26 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Patrick | last post by:
Hi all, I've installed the latest MDAC and Jet service packs on Windows 2000. On Linux I've the latest MySQL and MyODBC3.51. Using the ODBC Administrator I've set up a connection, ran the test...
2
by: Paul Nuschke | last post by:
Anyone know how to display a bitmap from an array using ATL, MFC, et al. Thanks, Paul Nuschke
0
by: Richard Liu | last post by:
Hi, all, How can i display File properties dialog(r-click a file in Explorer, then click "Properties"menuitem) Thanks a lot!
1
by: Mamatha | last post by:
Hi I am developing a small application to capture a record a video file through webcam in C#.NET. In this application i created a JPEG images for every slide,means every JPEG image was treated...
0
by: **Developer** | last post by:
How can I display the contents of My Network Places and a shared folder in it? Thanks
3
by: harish | last post by:
Hi friends I am facing problem as follow I can't display image from SQL Database to Picture box Control. Here are the codes that I am writing Dim arrPicture() As Byte = _
4
by: txican | last post by:
the HTML is: ---------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html> <head> <title>foo</title>...
7
by: alexseow | last post by:
Query.asp <%@ LANGUAGE="VBSCRIPT" %> <!-- #include file="../../includes/dbconn.asp"--> <% dim MyRs, sqlstr, MyConn Response.Expires = 0 Response.Buffer = TRUE Response.Clear
3
by: yuanyun.ken | last post by:
hi,dear all js gurus. In my app, server responses some text like: '&nbsp;&nbsp; ' and I need display these content in textarea. But Html would convert specail characters to space, and ignore line...
6
by: sarahaman | last post by:
hi all i am new in oracle! i made one simple form with report and i made one print button with trigger.(when-button-pressed) when i press the print button so its giving me whole data,i do not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.