|
The people here are smart enough to answer a question if it's posted once. Personally, I never answer questions that have been posted several times. It's just a matter of principal.
|
|
|
|
|
Hello everyone!
I want to thank you all up front for any assistance you can provide--I am new, and it will become more obvious here in a second. =)
I am brand new to c# (and visual programming in general, I usually work on Linux) but for a project that I am working on I have the need to get video from a web cam and do image capture.
I have the video working (through directshow) and I am able to take pictures from my video box. Now for the real problem. Over the live video I need to either layer a transparent panel (with border) or draw a rectangle so that the user can decide what portion of the video they wish to capture for the still image. Eventually I will need to let them resize the capture block (keeping ratio) as well.
I hate to speak in generalities, but can anyone get me started please. This is part of an MDI, and thus far I cannot get any panel transparencies to work (they always show the color of the form behind the image, even when the video is the form background)
After a week of brick walls I am coming to the experts for direction--at least point me down the best path if you would..
Thanks for your time and assistance!!
Edwa5823
|
|
|
|
|
You could let the control draw a rectangle as the user selects area for stillimage, and then use the 'control to bitmap' function to capture that exact rectangle.
Bitmap _capturedImage = null;
Brush _redbrush = new SolidBrush(Color.Red);
Brush _blackbrush = new SolidBrush(Color.Black);
Pen _pen = new Pen(_blackbrush);
Point _mousedown = new Point(-1,-1);
Rectangle _captureRect = new Rectangle(_mousedown, 0, 0);
bool _mouseheld = false;
</p>
private void videopanel_MouseDown(object sender, MouseEventArgs e)
{
_mouseheld = true;
_mouseDown = e.Location;
}
</p>
private void videopanel_MouseMove(object sender, MouseEventArgs e)
{
if(_mouseheld)
{
videopanel.Refresh();
Graphics g = videopanel.CreateGraphics();
Point _mousemove = e.Location;
g.DrawRectangle(
_pen,
_mouseDown.X,
_mouseDown.Y,
_mousemove.X - _mouseDown.X,
_mousemove.Y - _mouseDown.Y);
}
}
</p>
private void videopanel_MouseUp(object sender, MouseEventArgs e)
{
_mouseheld = false;
Graphics g = videopanel.CreateGraphics();
Point _mouseup = e.Location;
_captureRect = new Rectangle(
_mousedown,
_mouseup .X - _mouseDown.X,
_mouseup .Y - _mouseDown.Y);
_pen = new Pen(_redbrush);
g.DrawRectangle(_pen, _captureRect);
}
</p>
private void CaptureButton_Click(object sender, EventArgs e)
{
Graphics g = videopanel.CreateGraphics();
Bitmap _bitmapComplete = new Bitmap(videopanel.Width, videopanel.Height);
Rectangle _bitmapRect = new Rectangle(
0,
0,
videopanel.Width,
videopanel.Height);
videopanel.DrawToBitmap(_capturedImage, _bitmapRect);
_capturedImage = new Bitmap(
_captureRect.Width,
_captureRect.Height,
g);
g.DrawImage(_bitmapComplete, _bitmapRect,
_captureRect, GraphicsUnit.Pixel);
}
NB!
Untested code though. Just something that popped into my head. Might have to refresh between each call to MouseMove to avoid multiple rectangles for instance.
Hope it might be of some help.
-Larantz-
-- modified at 18:56 Friday 27th October, 2006
Forgot to only draw while moving if mousebutton is held
Tested it now on .net 1.1. The storing and drawing of rectangle works like a charm, though I don't have 2.0 for Control.DrawToBitmap() method.
|
|
|
|
|
If you want the selected rectangle to draw in all four quadrants from start of selection, you can rewrite the MouseMove and MouseUp eventhandlers as follows:
private Point _rectstart = new Point(-1,-1);
private Point _rectend = new Point(-1,-1);
</p>
private void videopanel_MouseMove(object sender, MouseEventArgs e)
{
if(mouse_down)
{
videopanel.Refresh();
_pen = new Pen(this._blackbrush);
Graphics g = this.videopanel.CreateGraphics();
Point _mousemove = new Point(e.X, e.Y);
if(_mousemove.X > _mousedown.X &&
_mousemove.Y > _mousedown.Y)
{
_rectstart = new Point(
_mousedown.X,
_mousedown.Y);
_rectend = new Point(
_mousemove.X,
_mousemove.Y);
}
else if(_mousemove.X < _mousedown.X &&
_mousemove.Y < _mousedown.Y)
{
_rectstart = new Point(
_mousemove.X,
_mousemove.Y);
_rectend = new Point(
_mousedown.X,
_mousedown.Y);
}
else if(_mousemove.X > _mousedown.X &&
_mousemove.Y < _mousedown.Y)
{
_rectstart = new Point(
_mousedown.X,
_mousemove.Y);
_rectend = new Point(
_mousemove.X,
_mousedown.Y);
}
else
{
_rectstart = new Point(
_mousemove.X,
_mousedown.Y);
_rectend = new Point(
_mousedown.X,
_mousemove.Y);
}
_captureRect = new Rectangle(
_rectstart,
new Size(
_rectend.X - _rectstart.X,
_rectend.Y - _rectstart.Y));
g.DrawRectangle(
_pen,
_captureRect);
}
}
</p>
private void videopanel_MouseUp(object sender, MouseEventArgs e)
{
mouse_down = false;
Graphics g = this.videopanel.CreateGraphics();
_pen = new Pen(_redbrush);
g.DrawRectangle(_pen, _captureRect);
}
-Larantz-
|
|
|
|
|
In my app, there are labels and rich text boxes on a report. When I select Japanese, Korean, or Chinese locales, the text in the labels is displayed as Asian characters. But, the rich text box contains question marks (I'm running XP, SP2, US). Is there a way to display Asian characters in a rich text box on this operating system, or do I need a Chinese operating system, a Japanese operating system, and a Korean operating system to view the Asian characters in a Rich Text Box?
This code works for languages like German, Italian, French.
m_rtfCircuitDesc.Rtf = @"{\rtf1\ansi \nowwrap " + strDesc + "}";
Thanks in advance.
-- modified at 15:09 Friday 27th October, 2006
|
|
|
|
|
Does anyone see what's wrong with the following code?
I followed some earlier advice and simplified things greatly. I no longer get exceptions thrown but my secondStrucure has no no calculated data in it when my bigStructureObj is returned. In my testApp, I populate the bigStructureObj with all the data the VB6 program sends to the dll (This problem is not occuring in VB6.)
I have the following dll code / c# code. I am definitely new to this and am guessing I'm just not getting the reading I've been doing.
#define theSIZE 145
typedef struct {
float smooth[theSIZE];
float first_der[theSIZE];
float sec_der[theSIZE];
float integral[theSIZE];
} thirdStructure;
typedef struct {
long num_v_points;
float v_time[theSIZE];
thirdStructure results;
} secondStrucure;
typedef struct
{
long window;
long num_points;
float xdata[theSIZE];
float ydata[theSIZE];
float v_time;
secondStrucure rdata;
float integral_const;
float integral_time;
float desired_x; .
} bigStructureObj;
//******************************************************************************
[StructLayout(LayoutKind.Sequential)]
internal struct thirdStructure
{
[MarshalAs(UnmanagedType.SafeArray)]
internal float[] fSmooth;
[MarshalAs(UnmanagedType.SafeArray)]
internal float[] fFirstDer;
[MarshalAs(UnmanagedType.SafeArray)]
internal float[] fSecondDer;
[MarshalAs(UnmanagedType.SafeArray)]
internal float[] fIntegral;
public thirdStructure(int c)
{
this.fSmooth = new float[c];
this.fFirstDer = new float[c];
this.fSecondDer = new float[c];
this.fIntegral = new float[c];
}
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct secondStrucure
{
[MarshalAs(UnmanagedType.I4)]
internal int NumVirtualPoints;
[MarshalAs(UnmanagedType.SafeArray)]
internal float[] fv_time;
[MarshalAs(UnmanagedType.Struct)]
internal thirdStructure vb_Results;
public secondStrucure(int b)
{
this.NumVirtualPoints = 0;
this.fv_time = new float[b];
this.vb_Results = new thirdStructure(b);
}
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
internal struct bigStructureObj
{
[MarshalAs(UnmanagedType.I8)]
internal long iWindowSize;
[MarshalAs(UnmanagedType.I8)]
internal long iNumRealPoints;
[MarshalAs(UnmanagedType.SafeArray)]
internal float[] fRealTimePoints;
[MarshalAs(UnmanagedType.SafeArray)]
internal float[] fRealPoints;
[MarshalAs(UnmanagedType.R4)]
internal float fVirtualTimeWidth;
[MarshalAs(UnmanagedType.Struct)]
internal vb_LOESS_II_RESULTS vb_well_data;
[MarshalAs(UnmanagedType.R4)]
internal float fIntegralConst;
[MarshalAs(UnmanagedType.R4)]
internal float fIntegralTime;
[MarshalAs(UnmanagedType.R4)]
internal float fDesired_x;
public bigStructureObj(int a)
{
this.iWindowSize = 0;
this.iNumRealPoints = 0;
this.fRealTimePoints = new float[a];
this.fRealPoints = new float[a];
this.fVirtualTimeWidth = 0;
this.vb_well_data = new secondStrucure(a);
this.fIntegralConst = 0;
this.fIntegralTime = 0;
this.fDesired_x = 0;
}
}
|
|
|
|
|
|
What exactly you want to do?
"My advice to you is to get married. If you find a good wife, you will be happy; if not, you will become a philosopher." Socrates
|
|
|
|
|
|
What code have you written so far? No-one will do this for you. Show your efforts so far and when you get stuck people will offer help.
Kevin
|
|
|
|
|
|
|
Rahithi wrote: if somebody help me to code this, it will be better for me now.
Of course it would be better for you now if someone just wrote the code for you.
In the long run, however, it's better for you if you learn two things from this:
1. Don't expect other people to do your homework.
2. If you have no idea on how to do the assignment, an hour before it's due is not a good time to start working on it.
Of course we are willing to help you with any problem you have while doing your assignment. This of course requires that you actually made an attempt, so that you know specifically what it is that you have problems with.
---
b { font-weight: normal; }
|
|
|
|
|
Wow, that's ballsy for sure. Please do my homework because I waited until the last minute.
|
|
|
|
|
|
|
You don't know anything about C#, but you have to turn in a web site navigation assignment in 4 hours?? Good Luck!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
You have everything you need in your description above. Break it down into steps. The entire project should take under 1/2 hour even if new to C#
|
|
|
|
|
First step is File -> New -> Project , or Ctrl+Shift+N for you advanced users.
|
|
|
|
|
|
I can call a JScript function from a c# App doing as follows:
SHDocVw.InternetExplorer oIe;
oIe = new SHDocVw.InternetExplorerClass();
Object strUrl = @"C:\blank.htm";
Object o=null;
oIe.Navigate2(ref strUrl ,ref o,ref o,ref o,ref o);
mshtml.HTMLDocument doc = (mshtml.HTMLDocument) oIe.Document;
doc.parentWindow.execScript("alert('Messge from JScript')", "JScript");
MessageBox.Show("Done");
oIe.Quit();
and what happens is that untill the JScrip dialog is closed my app is blocked.
How can i mak the call async? I tryed with BeginInvoke but got errors.
Regards
|
|
|
|
|
sterenzi wrote: but got errors.
What errors? We can't see them from here.
led mike
|
|
|
|
|
I get what follows:
An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dll
You can't get with the code i provided, I'll put the sample code for errors in a few mins.
|
|
|
|
|
OK, if you try the following code you can get the error,notice that I'm not sure this is the best way to follow...
delegate Object execAsyncJScriptDelegate(string param, string lang);
private void button2_Click(object sender, System.EventArgs e)
{
SHDocVw.InternetExplorer oIe;
oIe = new SHDocVw.InternetExplorerClass();
Object strUrl = @"C:\blank.htm";
Object o=null;
oIe.Navigate2(ref strUrl ,ref o,ref o,ref o,ref o);
mshtml.HTMLDocument doc = (mshtml.HTMLDocument) oIe.Document;
try
{
execAsyncJScriptDelegate jFunc = new execAsyncJScriptDelegate(doc.parentWindow.execScript);
IAsyncResult ar = jFunc.BeginInvoke("alert('Message from JScript')", "JScript", null, null);
MessageBox.Show("Done");
oIe.Quit();
while (!ar.IsCompleted)
{
Application.DoEvents();
}
jFunc.EndInvoke(ar);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
|
|
|
|
|
Well in .NET 2.0 I emulated your attempt using WebBrowser.Document.InvokeScript(). It did not throw an exception but the script did not execute and the IAsyncResult is completed upon return. So it appears that async invocation of scripts might not be supported.
led mike
|
|
|
|
|