|
jerome_data wrote: How to save CBitmap To .bmp file without ?
without what?
- NS -
|
|
|
|
|
Hello
I want to do a capture of one control(custom control) in my project in memory and save directly this capture in a bitmap or jpg file.
Help me please.
Jdata
|
|
|
|
|
Using Win32 APIs or MFC?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
both.
i do this
CDC dc;
CRect rectClient;
thecontrol.GetClientRect(&rectClient);
HDC hdc = ::GetDC(thecontrol.m_hWnd);
dc.Attach(hdc);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap bm;
bm.CreateCompatibleBitmap(&dc, rectClient.right, rectClient.bottom);
CBitmap * oldbm = memDC.SelectObject(&bm);
memDC.BitBlt(0, 0, rectClient.right, rectClient.bottom, &dc, 0, 0, SRCCOPY);
here bm as done a screenshot of the control. i want to save this Cbitmap to file .bmp??
If you have other function!!
thanks
|
|
|
|
|
Maybe:
CWindowDC ControlDC(&thecontrol);
CDC MemoryDC;
MemoryDC.CreateCompatibleDC(&ControlDC);
CRect ControlRect;
thecontrol.GetWindowRect(&ControlRect);
CImage ControlImage;
ControlImage.Create(ControlRect.Width(), ControlRect.Height(), 24, 0);
HGDIOBJ hOldBitmap = ::SelectObject(MemoryDC, (HBITMAP)ControlImage);
thecontrol.SendMessage(WM_PRINT, (WPARAM)(HDC)MemoryDC, PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT);
::SelectObject(MemoryDC, hOldBitmap);
ControlImage.Save(_T("c:\\mycontrol.bmp"), ImageFormatBMP);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
CImage is declared in
atlimage.h<br />
<br /> I used that so I wouldn't have to write code to save to a file - let GDI+ do it
You could use CBitmap instead (a DIBSection would make it easier) and write your
own code to save the bitmap.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
ok i try but i have a error on ImageFormatBMP.
undeclared identifier!!!
i have done #include <atlimage.h> to have Cimage class but i have a problem on ImageFormatBMP
thanks
|
|
|
|
|
Try Gdiplus::ImageFormatBMP
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
i have a black bmp file (Gdiplus::ImageFormatBMP)
ty
|
|
|
|
|
I didn't know if WM_PRINT would work with your custom control.
I suppose you can scrape it off the screen if it's visible:
CWindowDC ScreenDC(0);
CDC MemoryDC;
MemoryDC.CreateCompatibleDC(&ScreenDC);
CRect ControlRect;
thecontrol.GetWindowRect(&ControlRect);
CImage ControlImage;
ControlImage.Create(ControlRect.Width(), ControlRect.Height(), 24, 0);
HGDIOBJ hOldBitmap = ::SelectObject(MemoryDC, (HBITMAP)ControlImage);
MemoryDC.BitBlt(0, 0, ControlRect.Width(), ControlRect.Height(), &ScreenDC, ControlRect.left, ControlRect.top, SRCCOPY);
::SelectObject(MemoryDC, hOldBitmap);
ControlImage.Save(_T("c:\\testmy.bmp"), Gdiplus::ImageFormatBMP); Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It's works Excellent!!!
THANKS
|
|
|
|
|
Note: I am using Microsoft Visual C++ .NET (Microsoft Development Environment 2003 Version 7.1)
I have a solution comprising of five projects. For one of the project, I enable three compiler flags (PCM_MULTILINEAR, PCM_USE_FILTER16, PCM_USE_IMAGE8) as fallows:
1- Right click on the project in question
2- Select Properties.
3- Under "Configuration Properties", I click on "C/C++" then select "Preprocessor". Then I add the compiler flags (separated by at the "Preprocessor Definitions" field.
Is there a way to pass these complier flags from the command line when building the solution using "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv.exe" ?
This how I am building now (without enabling the compiler flags):
"C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv.exe" "CMM Tool Kit 7.10.sln" /rebuild release /out test.log
Thanks,
Mohamed
|
|
|
|
|
devenv [...] /D"PCM_MULTILINEAR" as shown as "command line" in the Project properties does not work?
Alternatively, you would set up proper project-configs for that, and call devenv with it:
/build builds the specified solution config (e.g. "debug", "release")
/project specifies a project (instead of a solution)
/projectconfig specifies the config (e.g. "debug", "release"
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
I tried:
call "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv.exe" "CMM Tool Kit 7.10.sln" /rebuild release /D "PCM_MULTILINEAR" /out test.log
But I got the following error message:
Invalid Command Line. Unknown Switch : D.
As far as : "Alternatively, you would set up proper project-configs for that, and call devenv with it:"
Is project-configs simply a text file or a file with a specific extension? Could you please give an example of how the content of project-configs would look like.
Thanks.
|
|
|
|
|
Mohamed Douffir wrote: Is project-configs simply a text file or a file with a specific extension?
Look at one of the projects set up with the VC++-GUI and open the *.vcproj-file.
Alternatively, there is nmake , the Microsoft make-implementation.
Look for help on it in MSDN.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Try here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi guys,
I'm currently figuring how to use of genetic algorithm to produce a image recognition application for my project.
Simply to say, is something like handwriting recognition or neural netwrk.
But to all my researches and understanding, GA are only applicable to path finding alghorithm and optimization. GA works well with binary. My intention was to make use of pixel count by "1s" for blank pixel and "0s" for black pixels.
Can anyone give me guidances or any tips/ related projects as references. Thanks
Ray Luee
|
|
|
|
|
A genetic algorithm does, loosley speaking, try to find a global maximum by looking at a number of random spots in the "solution space".
These spots are called individuals, and how "good" they are is determined.
In the next step ("generation"), it exchanges the worst individuals by some new individuals near the position of the best individuals known so far.
You have no guarantee whatsoever that you will find the global maximum, but you will find one or more local maxima.
Also, you will need to determine what is a "good" and what is "bad" fast and reliably - its called the "fitness function", and it is evaluated for each individual in each generation.
Can you give a suitable fitness function? Then a GA might work very well for you.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Yes, as expected from you, I was told to compared random sample of points on the two images to find a set of relationship that will transform one images to fit onto another using GA.
My understanding of GA was to
Based on fitness of the guesses from past guesses.
Encode using binary strings.
By swapping and recombining.
How will you approach to this situation to get the suitable fitness function?
Rayluee
|
|
|
|
|
rayluee wrote: How will you approach to this situation to get the suitable fitness function?
Actually, when I was teached GA, I was told to find out a fitness-function beforehand.
When a fitness function would "spring to mind", would be fast and "naturally" to find, the problem would be well suited to a GA.
If not, one might force it, but probably the GA would ever be suboptimal.
For your problem of transforming pictures, do you have a "solution space" with many dimensions?
Probably: each pixel is a dimension.
Your fitness function would involve computing some sort of a difference of the pictures, where a minimal difference would be best.
So each individual would consist of a set of pixel manipulations done on pic1, and you would then calculate the difference between the manipulated picture and pic2.
But whether that can be done fast?!?
Also, I have no idea if "crossover" would be sensible in this context.
</Brainstorming>
I hope to have given you something to start thinking.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
How do you traverse, or loop through the controls on the dialog?
The problem I have is that I have a spreadsheet control on a dialog, and when the dialog opens, the spreadsheet control is loaded before the header information is displayed. I thought I could grab the indexes for the controls located in the header and loop thru them to implicitly show them before loading the sheet.
for(int lcv = IDC_VENDID; lcv <= IDC_BTNHEADDOWN; lcv++)<br />
{<br />
GetDlgItem(lcv)->ShowWindow(SW_SHOW);<br />
}
The problem with this approach is that the control indexes aren't sequential, and an exception is thrown when lcv hits a value that references nothing (its not really nothing its a control id for another dialog).
|
|
|
|
|
littleGreenDude wrote: for(int lcv = IDC_VENDID; lcv <= IDC_BTNHEADDOWN; lcv++)
since you have the ID's why don't you just use the one for the window you are after and get it?
|
|
|
|
|
Dude, I'm a programmer, and programmers are fundamentally lazy in nature (so as not to offend anybody in our overly PC society, allow me to rephrase and state that all the good ones I know display this characteristic). And it serves them well to be that way. Think about it, there could be 300 controls in the header of the screen. Would you want to type 300 hundred Show Window statements. I think not. Also, it would be kind of ugly looking code.
Okay, so I'm exaggerating with the 300 number, but even 3 is one too many. I'd match rather have the ability to step from the low control to the high control and jump over the invalid references along the way.
|
|
|
|
|
littleGreenDude wrote: the controls located in the header and loop thru them
If they are real child windows you only need the header/parent then there are API's for like FindFirstChild/FindNext etc.
|
|
|
|
|