|
How to capture/save a bitmap on the picture box using VC++?
Aparna
|
|
|
|
|
GDI+
capture and save a bitmap of what?
Screen shot? Your active window?
by save do you mean to file or draw on the screen?
|
|
|
|
|
you can write it Byte wise. (like printf, but then it's called fwrite or write or something) You can then write pixel per pixel.
(Note: bitmaps have headers, this should be written first)
(Note: Write BGR NOT RGB (don't know why it just is)
(NOTE: remember Y-axis is inverted)
hope it helps!
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
How should an application create a file so that it inherits the permissions of the folder it is created in?
Microsoft says, in http://www.eu.microsoft.com/resources/documentation/windows/2000/server/reskit/en-us/serverop/part1/sopch03.mspx,
The version of NTFS included with Windows 2000 offers an important new feature for managing security — inheritable permissions. The Security dialog box offers the option to Allow inheritable permissions from parent to propagate to this file object *which is enabled by default*. (Emphasis mine)
And, in http://www.microsoft.com/resources/documentation/WindowsServ/2003/all/techref/en-us/Default.asp?url=/resources/documentation/windowsServ/2003/all/techref/en-us/w2k3tr_sec_authz_over.asp,
Inheritance of permissions You can control permissions for new objects created in a container object by setting inheritable permissions on the container. The permissions that you set on a container are also inherited by existing objects in the container *as well as newly created objects*. (Emphasis mine)
Well, it doesn’t seem to work that way at all. The second article also gives the following code for opening a file that will be written:
hfile=CreateFile(pszFile,GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
That’s exactly how I open an output file in my application, except that I use CREATE_ALWAYS instead of OPEN_EXISTING, because the file to be written may not exist yet.
The problem is that a file created by the application DOES NOT inherit permissions from the folder it is created in. This is true even if the file already exists and DOES inherit permissions before CreateFile() is called! When the “Security” tab of the file properties is examined, the “Allow inheritable permissions…” checkbox is cleared. This means that, if an Administrator creates the file, no non-Administrator users can open the file, even for read access.
How can I fix this problem?
|
|
|
|
|
From MSDN:
CREATE_ALWAYS Creates a new file. If the file exists, the function overwrites the file and clears the existing attributes.
Maybe two calls one with CREATE_NEW
if it fails you use OPEN_EXISTING
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Both files have been found. They are part of Cygwin.
www.cygwin.com
Hi all,
I'm trying to compile a project I obtained from Sourceforge. There are #includes for files such as <strings.h> and <poll.h>. I'm pretty sure they are not files missing from the project I downloaded, but more so, files I'm missing for a library that I have not downloaded.
I've done a quick search on google, and I get the impression that they exist on unix dev environments. The author of the project says his project compiles ni VC7.x and the code is like this :
#ifdef WIN32
#include <poll.h>
#include <strings.h>
#endif
and this is in several files, so it seems that they are available somewhere for win32.
Anyone know where I can get these or with which library they exists? (it's not in the latest Platform SDK, i looked)
Thanx
Jubjub <b></b>
|
|
|
|
|
Hi,
I am pretty new to DirectX and I need to accomplish the following thing:
Preview a live video stream from a webcam and be able to select (draggable&resizable rectangle) an area of the live video and apply some real-time image processing only on that area.
This involves video overlay (for the selection rectangle) and video processing of a portion of the video stream.
I understand DirectShow will let me preview a live video stream "quite easily". But will it give me the flexibility I need for overlaying the video and processing a portion of it?
If so how? And if not, what could I use?
Anything that could point me in the right direction would be greatly appreciated.
Thanks!
|
|
|
|
|
go to see my article http://www.codeproject.com/useritems/Motion_Detection.asp
|
|
|
|
|
Thanks, but I am looking for something in C++, not C#.
Also I would like to know what the best way is to achieve what I am trying to do. DirectShow + DirectDraw, or DirectDraw only?
Since I am starting with DirectX, I would like to get a few pointers in the right direction... For example, once I manage to get a preview of the live video feed using DirectShow, how do I implement localized video processing? What's the best way to do that?
Thanks!
|
|
|
|
|
I've done something similar to this for the project I'm working on at the moment. I've used a DirectShow filter graph to capture the images, inside that graph is a sample grabber filter which pushes images into my application. They are then connverted into textures which are drawn with Direct3D.
The key to this is that is that there are two distinct parts, both of which can be implemented in a number of ways. Frame capturing can be done with DirectShow, VFW or Video4Linux. Once you've got the frames in your image you can present them any way you like (GDI, Direct3D, DirectDraw, OpenGL, ...)
Adding the image processing is fairly simple. You can either add the image processing into your application after you have retrieved the data or you can modularise it by making it a directshow filter. My personal opinion is to do as little manipulation of frames as possible in DirectShow to ensure you have the most upto date frames flowing through the filter graph. Either way you end up dealing with an array of bytes which represent the image (depending on the camera format typically red, green blue triplets)
Drawing rectangles around regions is a minor problem compared to getting everything else correct, but all the drawing API's support this to some degree.
Simple Image Processing Architecture with DirectShow:
Source Filter
|
CSampleGrabber Filter -- Application -- Texture -- Direct3D Surface
|
Null Renderer
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Thanks Andrew!
I think I need to spend some time learning DirectShow. I know DirectDraw and I understand how to apply image processing and overlay to a video buffer (primary surface, back buffer...). However I am missing the piece to get the video from the webcam to a buffer (DirectShow).
Can you tell me briefly how it works?
Merlinos
|
|
|
|
|
Have a look at the playcap sample (\DXSDK\Samples\C++\DirectShow\Capture\PlayCap) in the DirectX SDK. It runs through the steps to create a filter graph, and add a renderer. You should be able to build on the example to add an instance of the CSampleGrabber filter (\DXSDK\Samples\C++\DirectShow\Filters\Grabber) into the graph.
Once the sample grabber is in the graph you pass it a callback, which is triggered when a frame arrives. In that callback, copy the image data onto the DirectDraw surface.
Hopefully that will get you started - good luck!
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
I am trying to add the CSamlpeGrabber into the playcap sample but I am running into some issues.
I get the following linking errors:
playcap.obj : error LNK2001: unresolved external symbol "public: __thiscall CSampleGrabber::CSampleGrabber(struct IUnknown *,long *,int)" (??0CSampleGrabber@@QAE@PAUIUnknown@@PAJH@Z)
strmbasd.lib(wxdebug.obj) : error LNK2001: unresolved external symbol __imp__timeGetTime@0
Can you tell me what I am missing here? Thanks!
Also, I tried a different way to insert the grabber sample using simply its CLSID and when I do that I get the following error:
playcap.obj : error LNK2001: unresolved external symbol _CLSID_GrabberSample
I am sorry to ask all these newbie's questions but I am a DirectShow newbie.
|
|
|
|
|
to get timeGetTime working you need to link to winmm.lib
including <initguid.h> should eliminate the problem with the clsid
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Is there a way to create a new window, which is brought to the front, from a process which is not the current process. On NT5 upwards, Windows does not allow processes which are not the current process to bring newly created windows to the front.
AllowSetForegroundWindow() will work, but not on Win95/98
I need a method which works on Win95/WinNT4 upwards.
Is this possible ?
|
|
|
|
|
Try SetWindowPos (&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
If i understand what you mean (you asking how to steal input focus on 2K/XP if a window belonging to another process has the focus) You need to attach your threads input Q to the active windows input Q - other wise as you say SetForgroundWindow does nothing.
Like this:
AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL),
GetCurrentThreadId(),TRUE);
SetForegroundWindow();
SetFocus();
AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL),
GetCurrentThreadId(),FALSE);
That will attach ure threads input Q to the input Q of the window with the foucs, steal the focus - which is now allowed, then detach it.
I hope thats what u ment )
|
|
|
|
|
Diddy wrote:
AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL),
GetCurrentThreadId(),TRUE);
SetForegroundWindow();
SetFocus();
AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL),
GetCurrentThreadId(),FALSE);
This is exactly what I want, thanks.
Two questions though:
Shouldn't the ThreadProcessId be stored when GetWindowThreadProcessId() is first called ? Otherwise, when you call it the second time, you are getting the ThreadProcessId of your apps window and not the original window, since it is no longer the Foreground Window.
Also, will it not make the other app unstable, because by stealing the threads input for a short period, you are also stealing its' messages. This means that certain messages, received during the time that my app has the other apps thread input, will not be handled by the other app. Bit of a convoluted description, I know )
Anyway, will it make the other app (or my app) unstable ?
Thanks again for your help.
|
|
|
|
|
1) Yes ) Thats called me trying to attack the situation with copy and paste ) Well spotted.
2) No. It's not stealing its input - its stealing - or rather sharing - its input states. Each thread has a number of states associated with all the windows it has created - such as the one that has the focus, and the curent cursor for each etc. When you call SetFocus, it says is the focus state set for our thread for at least one window we have created - if thats a no, it does nothing - if its a yes, it sets the focus to the window provided. AttachThreadInput simply combins the states for both threads, so thread A and thread B are now working with the same state - since you are attaching to the current forground window, your focus state is now set and you can change the focus to one of your own windows.
In other words:
defenestration wrote:
This means that certain messages, received during the time that my app has the other apps thread input, will not be handled by the other app
Isn't true - its nothing to do with the messages - just to do with certian states of the thread (specifically focus, active, capture windows, key state, queue status, and so on).
It's the recomended way by MSDN anyway - and I have used it for ages with no stabality problems. One thing to be aware of - never put a break point between attaching and detacting. If you are debuging - you will be attaching to MSDEVS thread, and because your app is being debugged, you will be bascially freeze the debugger.
Hope it helps
|
|
|
|
|
Diddy wrote:
Hope it helps
It certainly has. Thanks for the explanation Diddy!
|
|
|
|
|
Hi,
I'm in the process of making my program more robust. I've had a couple integer divide by zero exceptions from my program so I am now going through all divisions within my code and maknig sure they aren't 0.
However, just wondering if there is such thing as floating point divide by zero? I can't seem to find such an exception and coudlnt' generate it myself for testing. Do FLOATs work differently than integers?
Thanks in advance!
|
|
|
|
|
I ran a test and to my supprise, no exception was generated! Why? I am still looking for the answer.
Look in MSDN library under the following:
"Floating-Point Exception Modes"
and
"_controlfp"
I hope that is some help!
Here is a clip from a math parser I wrote (in C) back in 1994 (the code still works):
int matherr( struct exception *except )
{
char t = *(_User.def.name);
int endx=-1, sndx=-1, n = _User.def.nargs;
char *str[2] = { "is","caused" };
char *errors[6] =
{
"outside the domain",
"an illegal value",
"overflow",
"underflow",
"partial loss of significance",
"total loss of significance",
};
switch( except->type )
{
case DOMAIN: endx = 0 ; sndx = 0 ; break ;
case SING: endx = 1 ; sndx = 0 ; break ;
case OVERFLOW: endx = 2 ; sndx = 1 ; break ;
case UNDERFLOW: endx = 3 ; sndx = 1 ; break ;
case PLOSS: endx = 4 ; sndx = 1 ; break ;
case TLOSS: endx = 5 ; sndx = 1 ; break ;
}
if( t && endx>-1 && sndx>-1)
{
_Error( "math","'%s': argument %s %s",
_User.def.name,str[sndx],errors[endx] );
}
else _Error( "math",errors[endx] );
return 1;
}
#include <float.h>
#include <signal.h>
static void fphandler( int sig, int num );
static char *_FpeErrors[10] =
{
"invalid number",
"denormal",
"divide by zero",
"overflow",
"underflow",
"inexact",
"unemulated",
"square root of negative number",
"stack underflow",
"unknown",
};
void p_setfperror(void)
{
if( signal( SIGFPE, fphandler ) == SIG_ERR )
_Error( "p_setfperror","could not set floating point error handler" );
else _FpeSet = 1;
}
static void fphandler( int sig, int fperr )
{
int ndx;
_fpreset();
if( _Error_Flag > -1 )
{
switch( fperr )
{
case FPE_INVALID: ndx = 0; break;
case FPE_DENORMAL: ndx = 1; break;
case FPE_ZERODIVIDE: ndx = 2; break;
case FPE_OVERFLOW: ndx = 3; break;
case FPE_UNDERFLOW: ndx = 4; break;
case FPE_INEXACT: ndx = 5; break;
case FPE_UNEMULATED: ndx = 6; break;
case FPE_SQRTNEG: ndx = 7; break;
case FPE_STACKUNDERFLOW: ndx = 8; break;
default: ndx = 9;
}
_FpeMsg = _FpeErrors[ndx];
}
_Error_Flag = -1;
}
Good Luck!
INTP
|
|
|
|
|
Thanks for the resources. Would you happen to know what the Alpha machines are? I guess we're concerned with x86 right?
I still can't generate a floating point divide by zero. Perhaps the compiler is doing something so that it gets trimmed away. But I just hope it doesn't happen in my program
Has anyone actually seen a floating point exception before? One related to arithematic error? I don't think I have.
Thanks!
|
|
|
|
|
Ryan is right about the infinity thing, but the code sample I gave you was from a math parser that did catch divide-by-zero (all calculations where done using double values).
May be you sould also look up: "ID: Q72726"
The best solution of course is to always test the denominator to make sure it is not zero before using it.
INTP
|
|
|
|
|
herbert_chow wrote:
However, just wondering if there is such thing as floating point divide by zero? I can't seem to find such an exception and coudlnt' generate it myself for testing. Do FLOATs work differently than integers?
A floating-point divide-by-zero doesn't generate an exception - even at the FPU level. FPU's know that anything divided by 0 is infinite, so they actually return a result of infinity (which is a valid number in the IEEE floating point formats, BTW). They don't flag an error condition, so the only way you can check is to determine if the result is infinity.
However, a much better way is to make sure it never happens in the first place...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|