Solved

What is the best method for rendering bitmaps in an MS windows application window?

Posted on 2015-01-30
4
164 Views
Last Modified: 2015-01-30
Hi:

I'm building a windows based application which will display bitmap frames.
Basically I'm capturing individual frames from a pc camera; doing some analysis
and then wanting to display that frame in a window.

Our current implementation is a 32 bit application  is written in unmanaged C++ .

I've looked at the opencv implementation -->> cv::imshow().
Under the covers, what they are doing would work for us.

But,  rather than have opencv own the window, we want our app to,
so we can add some additional processing.

opencv's implementation is old school windows with doing BitBlt() and StretchBlt()
during the WM_PAINT messages of the target window (owner draw).

Are there other approaches out there which would answer our needs?
Does GDI++ provide any "rendering an image to a target window" functionality?

If our target changed to be a managed winforms or WPF application, what would be the
best prescribed approach?

Thanks in advice for your advice,

JohnB
0
Comment
Question by:jxbma
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Are you thinking of something like

void DrawBitmap(HWND hwnd, Gdiplus::Image* pImg) {

  Gdiplus::Graphics graphics(hwnd);
  Gdiplus::Rect rc(0, 0, 800, 400);
  graphics.DrawImage(pImg, rc);
}

// ...

Gdiplus::Image img(L"c:\\path\\image.bmp", FALSE);

DrawBitmap(hwndMyWindow,&img);

Open in new window

?

See also https://msdn.microsoft.com/en-us/library/windows/desktop/ms534462%28v=vs.85%29.aspx ("Image class") and https://msdn.microsoft.com/en-us/library/windows/desktop/ms536051%28v=vs.85%29.aspx ("Graphics.DrawImage(Image*, const Rect) method")
0
 
LVL 1

Author Comment

by:jxbma
Comment Utility
jkr:: Yes sir, as usual you are spot on your game.

I guess an additional question is:

Would I do this as an "owner draw" in my WM_PAINT message?

Do I have to worry about stretching as the parent window resizes?

Thanks,
JB
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
You can of course do that in yoru WM_PAINT handler, 'owner draw' style or not. If you want to use the window's corners as the 'Rect' used with 'DrawImage()', yes, then stretching would be an issue. If you however use the same seize regardless of the window's actual size, there won't be a problem.
0
 
LVL 1

Author Closing Comment

by:jxbma
Comment Utility
Right as usual!

Thanks,
JB
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now