|
You already have the code. All you need to do is use a FileStream instead of a MemoryStream to write the bytes out to a file.
|
|
|
|
|
Still cannot figure out. Please help the novice.
|
|
|
|
|
Please find below the extarct of my application where the stream is stored in an image control named frameHolder and function SavePic grabs the current frame and save it to disk. frameHolder is shown on the Main Window. Making it invisible captures blank picture.
MainWindow.xaml.cs
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
LoaclWebCamsCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
LocalWebCam = new VideoCaptureDevice(LoaclWebCamsCollection[0].MonikerString);
LocalWebCam.DesiredFrameSize = new System.Drawing.Size(320, 240);
//MessageBox.Show(LocalWebCam.DesiredFrameSize.ToString());
LocalWebCam.NewFrame += new NewFrameEventHandler(Cam_NewFrame);
LocalWebCam.Start();
}
void Cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
BitmapImage bi = new BitmapImage();
try
{
img = (Bitmap)eventArgs.Frame.Clone();
MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Bmp);
ms.Seek(0, SeekOrigin.Begin);
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
bi.Freeze();
Dispatcher.BeginInvoke(new ThreadStart(delegate
{
frameHolder.Source = bi;
}));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "NW CDM Test of Image Capture Failed");
}
}
Sultan Uz Zaman at 4 hrs ago
Reply Modify the comment. Delete the comment.
A button click event does the follwoing to save the pic:
public static void SavePic(string imageFile)
{
//Cam_NewFrame(null,null);
//image1.Source = frameHolder.Source;
//Image frame = frameHolder.Cam_NewFrame(null,null);
// Release any previous buffer
MainWindow myWin = Application.Current.MainWindow as MainWindow;
RenderTargetBitmap bitmap = new RenderTargetBitmap(320, 240, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(myWin.frameHolder);
using (FileStream stream = File.Create(Global.xImageLocation+"\\"+imageFile)) // or .png
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.QualityLevel = 90;
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.Save(stream);
}
}
|
|
|
|
|
Didn't you just post a code dump about this the other day? If so, what part of the code doesn't work?
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
Friends i use this code to get image from database
and show it on picturebox1
but i am getting
this error
system.drawing.image.fromstream(stream stream,boolean ....)
in database column datatype is varbinary(MAX)
byte[] data = new byte[0];
data = (byte[])(dsetName.Tables[0].Rows[0]["picture"]);
MemoryStream mem = new MemoryStream(data);
pictureBox1.Image = Image.FromStream(mem);
if there is some thing missing in my code than suggest me
|
|
|
|
|
You haven't actually told us what error you're getting.
|
|
|
|
|
error is Parameter not valid and
system.drawing.image.fromstream(stream stream ,boolean)
|
|
|
|
|
|
in my program a sending some text to an active windows.
i send like this:
.
.
.
MSG = lblMSG.Text.Trim();
SendKeys.Send(MSG);
SendKeys.SendWait("{ENTER}");
SendKeys.Flush();
the problem is - sometime the string Changing for no reason.
for example:
9999.999 ==> 9999.9999
9999.999 ==> 999.999
why ?
|
|
|
|
|
Message Closed
modified 7-Sep-15 5:20am.
|
|
|
|
|
Is there a question or problem? This looks just to be a code dump.
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
|
I have removed your code. The forums in Code Project are not intended to act as a personal back-up store for code.
|
|
|
|
|
That's what I wondered about it looking like a code dump. He could at least write an article on it if he wanted to share it with the community
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
All i found is real matrix svd, i want complex matrix. so i need help ,please .thank you.
i want c# lib.
|
|
|
|
|
Hi
I am calling a SSRS report from C#. A main report and a subreport in it.
The main report is working correctly but the subreprot is showing The subreport 'Name' could not be found at location
I put the main report and subreport in the bin folder.
Please find the code used by me as below
sqlcomm = new SqlCommand("mainreport query", conn);
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlcomm);
dataAdapter.Fill(dataset);
this.reportViewer1.ProcessingMode = ProcessingMode.Local;
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\sale_dept.rdl";
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dataset.Tables[0]));
this.reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(addsubreport);
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
private void addsubreport(object sender, SubreportProcessingEventArgs e)
{
SqlConnection conn = new SqlConnection(source);
DataSet dataset = new DataSet();
conn.Open();
SqlCommand sqlcomm = new SqlCommand("subreport query", conn);
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlcomm);
dataAdapter.Fill(dataset);
e.DataSources.Add(new ReportDataSource("discount", dataset.Tables[0]));
}
When i done debug with breakpoint it found that the eventhandler is not getting fired.
The control is not going to the 'addsubreport' event handler. I am stucked here please help
|
|
|
|
|
Hi guys,
I want to using Cutter for cut an image(.svg) with a definition layout image (.png, .svg, .plt) by winform (C#).
So, I don't know how to do it. Please suggest me some solutions.
What format of definition layout image can I use for that? (.png or .svg or .plt)
Images example:
Image for cutting: here
Layout: here
Thanks you.
|
|
|
|
|
This is not a good question - I have no idea what you are goign on about.
What is "Cutter"? I dunno.
What are you trying to do? I dunno.
What does it have to do with C#? I dunno.
Am I going to follow random links which start "appbox"? Nope. Dunno what is on the other end, and don't want to find out the hard way.
And we can't see your screen, access your HDD, or read your mind. We only get what you give us to work with.
So explain what you are trying to achieve, tell us what problem you are having, explain what you have tried, tell us where you are stuck, and what help you need. And don't post links to random sites.
But at the moment, we can't help you.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sorry!!!
>>What is "Cutter"? I dunno
I mean cutting machine.
>>What are you trying to do? I dunno.
I need the vector images drawn into vector line drawings for an cutting machine to read and cut them.
>>What does it have to do with C#? I dunno.
I want to use C# (Winform)
|
|
|
|
|
phinq1910 wrote: I mean cutting machine.
Well that's not exactly narrowing it down and completely useless.
Do you have some kind of command and control software for this machine or a manual on what language it understands? You better because you're dead in the water without it.
|
|
|
|
|
hi,
i have my program that Captures weighing and send it to a open window.
its work excellent , except with a single software - Microsoft Word
I have tried everything and have no idea why.
my code:
this is the GlobalKeyBoardHook.cs class
public class GlobalKeyboardHook
{
[DllImport("user32.dll")]
static extern int CallNextHookEx(IntPtr hhk, int code, int wParam, ref keyBoardHookStruct lParam);
[DllImport("user32.dll")]
static extern IntPtr SetWindowsHookEx(int idHook, LLKeyboardHook callback, IntPtr hInstance, uint theardID);
[DllImport("user32.dll")]
static extern bool UnhookWindowsHookEx(IntPtr hInstance);
[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string lpFileName);
public delegate int LLKeyboardHook(int Code, int wParam, ref keyBoardHookStruct lParam);
public struct keyBoardHookStruct
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
const int WH_KEYBOARD_LL = 13;
const int WM_KEYDOWN = 0x0100;
const int WM_KEYUP = 0x0101;
const int WM_SYSKEYDOWN = 0x0104;
const int WM_SYSKEYUP = 0x0105;
LLKeyboardHook llkh;
public List<Keys> HookedKeys = new List<Keys>();
IntPtr Hook = IntPtr.Zero;
public event KeyEventHandler KeyDown;
public event KeyEventHandler KeyUp;
public GlobalKeyboardHook()
{
llkh = new LLKeyboardHook(HookProc);
}
~GlobalKeyboardHook()
{ unhook(); }
public void hook()
{
IntPtr hInstance = LoadLibrary("User32");
Hook = SetWindowsHookEx(WH_KEYBOARD_LL, llkh, hInstance, 0);
}
public void unhook()
{
UnhookWindowsHookEx(Hook);
}
public int HookProc(int Code, int wParam, ref keyBoardHookStruct lParam)
{
if (Code >= 0)
{
Keys key = (Keys)lParam.vkCode;
if (HookedKeys.Contains(key))
{
KeyEventArgs kArg = new KeyEventArgs(key);
if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null))
KeyDown(this, kArg);
else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null))
KeyUp(this, kArg);
if (kArg.Handled)
return 1;
}
}
return CallNextHookEx(Hook, Code, wParam, ref lParam);
}
// --- from here start the program --
GlobalKeyboardHook gHook;
gHook = new GlobalKeyboardHook();
gHook.KeyDown += new KeyEventHandler(gHook_KeyDown);
foreach (Keys key in Enum.GetValues(typeof(Keys)))
{
gHook.HookedKeys.Add(key);
}
gHook.hook();
public void gHook_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == KeyPressg)
{
ProccName = (GetActiveWindowTitle().ToString());
Start(ProccName);
gHook.unhook();
gHook.hook();
}
else
{
}
}
private string GetActiveWindowTitle()
{
const int nChars = 256;
StringBuilder Buff = new StringBuilder(nChars);
IntPtr handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto)]<br />
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
public void Start(string NAME)
{
MSG = lblMSG.Text.Trim();
IntPtr zero = IntPtr.Zero;
for (int i = 0; (i < 60) && (zero == IntPtr.Zero); i++)
{
Thread.Sleep(500);
zero = FindWindow(null, NAME);
}
if (zero != IntPtr.Zero)
{
try
{
string text = lblMSG.Text.Trim();
text = text.Replace("gHook", "");
if (text.Length == 0) return;
SendKeys.SendWait(text);
if (MyParam._KeyAfter == "Enter")
{
MyParam.FromKEY = true;
SendKeys.SendWait("{ENTER}");
}
else if (MyParam._KeyAfter == "TAB")
{
SendKeys.SendWait("{TAB}");
}
else if (MyParam._KeyAfter == "Key Down")
{
SendKeys.SendWait("{DOWN}");
}
SendKeys.Flush();
}
catch { }
}
}
Any ideas why ?
thanks
EDIT
public void Start(string NAME)
{
<pre>
MSG = lblMSG.Text.Trim();
IntPtr zero = IntPtr.Zero;
for (int i = 0; (i < 60) && (zero == IntPtr.Zero); i++)
{
Thread.Sleep(500);
zero = FindWindow(null, NAME);
}
if (zero != IntPtr.Zero)
{</pre>
modified 5-Sep-15 6:09am.
|
|
|
|
|
No, and please don't repeat the question.
Can you find the Window of Word? That is where you start; if the Window cannot be found, you cannot post anything to it.
Now, I'd also like to know what "everything" means, to prevent from advising something you already tried.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
1) Why are you even using a keyboard hook? I fail to see how capturing keystrokes system-wide has anything to do with pushing keystrokes to Word.
2) When you call your Start method, what is the value of NAME ? If that value doesn't match EXACTLY the name of the window you're trying to find, it's not going to work. Your ignoring any error that is set if the return value from FindWindow is null (zero in your case). To get that error you have to call the Win32 function GetLastError and examine the returned value.
Read the documentation on FindWindow and GetWindowText for the pitfalls of using these functions.
|
|
|
|
|
thanks for the help,
the name is Exact.... still not working...but only in Word
|
|
|
|