|
|
Input
System.IO.MemoryStream which has a Write() method. That is how you put it into a Memory Stream.
Kushina wrote: then convert the stored data to a jpeg image
Not sure what that means but since the camera takes jpeg images then the incoming bytes are already a jpeg.
HOWEVER, if what you are really asking is how can you write an application that interfaces with a camera then the steps are:
1. Learn how USB devices work
2. Learn how to interface to USB devices in C#.
3. Learn how the interface to the specific camera works (with 1/2)
4. Write C# code to access the camera using 1/2/3.
5. Do something with the images. Presumably store them as files. Then learn more about C# System.io classes.
Naturally the above presumes you know some C# in the first place. If not then you must also learn the basics of C#.
|
|
|
|
|
Thank you for your kind reply ,response and your help .
It was very useful for me , but I'm still a bit confused and it could be because I did not point out clearly the problem .
I'm a beginner in c# but I have learned some basics in this language .
We have used link sprite jpeg camera in our project . our doctor has divided the project into a group of tasks and we have to learned
to implement it step by step .
This camera has a manual which contains all commands to communicate with the camera
(http://www.mediafire.com/view/?ec79xt02620zil5[^])
we were able till now to send the reset command and get back the return msg .
now we want the camera to take a pictures which has a dimensions (160*120);my task is to get the bytes that represent the picture and how to save it in memory stream to be processed later on . after that how this picture can be displayed as a jpeg image or any other extenssion.
|
|
|
|
|
Say we have a struct A that looks like this:
struct A
{
public string a0;
public string a1;
public string a2;
public string a3;
public unsafe string this[int index]
{
get { return *(&a0 + index); }
}
}
Ok so you can't do that, it would only work for unmanaged types. Fixed size array then? Nope, also only works for unmanaged types.
So then I had a terrible idea:
struct A
{
public string a0;
public string a1;
public string a2;
public string a3;
public unsafe string this[int index]
{
get { return get(ref this, index); }
}
delegate string Get(ref A obj, int index);
static Get get;
static A()
{
DynamicMethod dm = new DynamicMethod("getat", typeof(string), new Type[] { typeof(A).MakeByRefType(), typeof(int) }, typeof(A));
ILGenerator gen = dm.GetILGenerator();
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Ldflda, typeof(A).GetField("a0"));
gen.Emit(OpCodes.Sizeof, typeof(IntPtr));
gen.Emit(OpCodes.Ldarg_1);
gen.Emit(OpCodes.Mul);
gen.Emit(OpCodes.Conv_I);
gen.Emit(OpCodes.Add);
gen.Emit(OpCodes.Ldind_Ref);
gen.Emit(OpCodes.Ret);
get = (Get)dm.CreateDelegate(typeof(Get));
}
}
And guess what, it works (as far as I tested).
This is a total hack, obviously. But is it OK? Assuming it isn't given bad indexes, can it fail somehow?
I'm not really too interested in "how to do this the right way" (unless you've got something that isn't "just use an array" or "use a switch, it's only 4 items" (that's just for the example)), just in how terrible this way really is.
modified 8-Nov-12 12:15pm.
|
|
|
|
|
I'll give it an A+ for creativity, but a D for maintainability.
|
|
|
|
|
Terrible idea. I *would* use an array or switch , but if you are against that for some absurd reason, you can also dynamically get the variable by name via reflection or expression trees (if you care about performance).
|
|
|
|
|
Can you guarantee that reflection will give you the fields in the right order? I know that it actually, in practice, does (I have some attribute based reflection code to find data display properties in some real business code and you get the fields in declaration order), but when you're indexing into it that needs to be guaranteed.
If you can then yeah I'd have a one shot reflection lookup that creates a cache array of int→PropertyInfo and then look up into that.
|
|
|
|
|
harold aptroot wrote: This is a total hack, obviously. But is it OK? Assuming it isn't given bad indexes, can it fail somehow?
Not much exceptions that are thrown by those functions, according to MSDN. You might want to check whether the topic 'verification' from this page[^] applies to your situation.
No, wouldn't call it a hack, but emitting code is not a widely-understood topic; so you might wanna document what you did there. An implementation that 'generates' the required switch-code and compiling that with the built-in mechanism would be more familiar - also a bit slower, but I doubt that the layout of the class will change often, so it'd be a matter of compiling once and re-using the existing thing.
I'd go for reflection, as mentioned by others. Caching the results might improve speed there, but it's fast enough for most tasks without additional caching.
|
|
|
|
|
Thanks, looks like it'll be fine.
Yea I know, normally I would do something sane, but the situation demands it
|
|
|
|
|
harold aptroot wrote: normally I would do something sane
It's not "insane code", just a tad more scary than seeing someone compile code on the fly. Maintainability might be an issue. It may fail due to a security-update when you're celebrating a wedding in Hawaii, so it'd be best to put some explanation and some hyperlinks in the xml-comment header.
harold aptroot wrote: but the situation demands it
Is this situation a person? It prolly ain't Mr. Performance
This is one of the rare times where the situation itself is more interesting then the programming-exercise.
|
|
|
|
|
Oh it's just for research, not that interesting..
|
|
|
|
|
..and since when do people learn voluntarily?
Are you trying to imply you're actually researching the differences? Trying to emit compiled code, just to see if it works? What kind of pervert would go out and "try*"?
So, from your answer I take it that the requirement is the boss, and that he's reading CodeProject?
*) FWIW, it is faster
|
|
|
|
|
If it is more because you don't want to write the code or generate it then:
FooBar abc = new FooBar();
abc.abc0 = "123";
abc.abc1 = "456";
abc.abc2 = "789";
abc.abc3 = "101112";
string kapaow = (string)(abc.GetType().GetFields()[3].GetValue(abc));
|
|
|
|
|
Hello everyone,
i'm using an outlook add-in using these below events i got sent and received mails in my wcf service but only when outlook is running if outlook is closed and somebody send me mails than the add-in does not call my wcf service method
here are events
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemSend += new ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
this.Application.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);
}
Please help me
Thanks
|
|
|
|
|
Think about this. You're creating an Outlook Add-In. If Outlook is not running, your Add-In is not running either. So how are are these events going to fire if Outlook is not running??
Your solution is to either leave Outlook running all the time, or rewrite your app as a Windows Service that uses Outlook functionality.
|
|
|
|
|
...or talk to Chris Elston about this time travel module he's been asked to work on...
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Hello Dave Kreskowiak,
I agreed with you. but i'm talking about those mails which come to me when my outlook is not running and as i run my outlook i got all mails in my outlook but i wonder on which event i can call my WCF service method to get those mails
Thanks
|
|
|
|
|
There is no seperate event.
All new emails that come into the client will raise the exact same event, no matter if they show up when Outlook starts or not.
The problem is that your Add-In may not have wired up the event handlers before that happens. Add-Ins are loaded before Outlook checks with the mail servers to pickup mail, but it doesn't wait for each Add-In to completely load and initialize itself. You have to make sure that one of the first things you do is wire up the events you want and don't take forever to init your code.
|
|
|
|
|
I have a stream object containing html that I can read as a List<Char>. The stream contains html. What I need to do is convert the stream of html into xml and store the xml into a xmlDocument in C#. Can anyone show me some code that will help me do this?
Thanks,
Steve Holdorf
|
|
|
|
|
Please explain what do you mean by "convert html to xml". Both are just strings wiht set format, but there are many cases that valid html is not valid xml (for example <br> and <p> tags may be not terminated)
You can try to parse the html and try to "fix" it, but it may not be worth the effort.
On the other hand if you have control over the html and can ensure correct structure yourself, nothing prvents you from creating XmlDocument out of it using Load() or LoadXml() methods.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
What I mean is that I am reading excel spreadsheet cells pasted into an editor and pulling the content of the editor into a stream of html. Next, what I want to dso is take the html stream and make it into an XML stream that I can load into an XMLDocument (ie <table .. ></table> into <table>......<table>) then I will parse the xml data and store it into the database.
Thanks,
Steve Holdorf
|
|
|
|
|
You'll need to use something like the HTML Agility Pack[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard,
The codeplex library is great. One question; however. It's class object works by writting the html to a file on the server then the app code must read the file back into an xmldocument. Because of security reasons we can't allow the application to save a file from the browser to the server and then read it back from the server. Is there anyway to have the html to xml converter class write the converted html to a stream or some thing else besides a file on the server?
Thanks a lot!!!!!
Steve Holdorf
|
|
|
|
|
As well as the overloads of the Load method which take a file path, there are overloads which take a Stream or a TextReader as the source:
- File path:
void Load(string) void Load(string, bool) void Load(string, Encoding) void Load(string, Encoding, bool) void Load(string, Encoding, bool, int)
- Stream:
void Load(Stream) void Load(Stream, bool) void Load(Stream, Encoding) void Load(Stream, Encoding, bool) void Load(Stream, Encoding, bool, int)
void Load(TextReader)
There's also a LoadHtml method which accepts a string containing the HTML to load.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Goodmorning to all!
Ehm i want create a button ribbon and when i press it load a windows form integrated into outlook 2010 or 2007 or 2013 (if it exited from building). Ehm i started creating button ribbon with this guide:
http://blogs.msdn.com/b/mcsuksoldev/archive/2010/07/12/building-and-deploying-an-outlook-2010-add-in-part-1-of-2.aspx
When i press it i would load a form into outlook that load all contacts of my public folder with this name "Contatti Itech" into a datagrid view.
How can i do it?
Plz help me!
Thanks for any help! Code are appreciated too!!!
Ehm i forgot one thing:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Reflection;
using System.Diagnostics;
namespace OutlookInteropSample
{
public partial class MainForm : Form
{
private ToolTip contactToolTip = new ToolTip();
private Outlook.MAPIFolder oContactsFolder = null;
public MainForm()
{
InitializeComponent();
}
private void buttonGetContacts_Click(object sender, EventArgs e)
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
oContactsFolder = oNS.GetFolderFromID("000000001A447390AA6611CD9BC800AA002FC45A0300D4985F464F07654AA9CA8D6B785E166E000000004E3B0000", Type.Missing);
Console.WriteLine(oContactsFolder.EntryID);
getContacts(oContactsFolder);
oApp = null;
oNS = null;
}
private void ChiamaFunzia()
{
}
private void listViewContacts_ItemMouseHover(object sender, ListViewItemMouseHoverEventArgs e)
{
contactToolTip.SetToolTip((Control)listViewContacts, getContactInfo((ListViewItem)e.Item));
contactToolTip.Active = true;
}
private void getContacts(Outlook.MAPIFolder oContacts)
{
try
{
listViewContacts.Items.Clear();
string filter = "[MessageClass] = \"IPM.Contact\"";
Outlook.Items oContactItems = oContacts.Items.Restrict(filter);
foreach (Outlook.ContactItem oContact in oContactItems)
{
try
{
ListViewItem item = new ListViewItem();
item.Text = oContact.Email1DisplayName;
item.Tag = oContact;
this.listViewContacts.Items.Add(item);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
oContactItems = null;
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString(), this.Name);
}
finally
{
this.listViewContacts.EndUpdate();
}
if (this.listViewContacts.Items.Count > 0)
{
this.buttonSendEmail.Enabled = true;
}
else
{
this.buttonSendEmail.Enabled = false;
}
}
private string getContactInfo(ListViewItem contact)
{
Outlook.ContactItem oContact = (Outlook.ContactItem)contact.Tag;
StringBuilder sb = new StringBuilder();
if (oContact.CompanyName != null && oContact.CompanyName.Length > 0) sb.AppendLine("Archivia come: " + oContact.CompanyName);
oContact = null;
return sb.ToString();
}
private void listViewContacts_MouseLeave(object sender, EventArgs e)
{
contactToolTip.Active = false;
}
private void listViewContacts_DoubleClick(object sender, EventArgs e)
{
ListViewItem activeItem = ((ListView)sender).SelectedItems[0];
if (activeItem != null)
{
Outlook.ContactItem oContact = (Outlook.ContactItem)activeItem.Tag;
EditContact editBox = new EditContact(oContact);
oContact = null;
if (editBox.ShowDialog() == DialogResult.OK)
{
getContacts(oContactsFolder);
}
}
}
private void buttonSendEmail_Click(object sender, EventArgs e)
{
Outlook.Application oApp = new Outlook.Application();
if (this.listViewContacts.SelectedItems != null &&
this.listViewContacts.SelectedItems.Count > 0)
{
Outlook.ContactItem oRecip = (Outlook.ContactItem)(this.listViewContacts.SelectedItems[0].Tag);
Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));
email.Recipients.Add(oRecip.Email1Address);
email.Subject = "Just wanted to say...";
email.Body = "Have a great day!";
if (MessageBox.Show("Are you sure you want to send a good day message to " + oRecip.Email1DisplayName + "?", "Send?", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
try
{
((Outlook.MailItem)email).Send();
MessageBox.Show("Email sent successfully.", "Sent");
}
catch (Exception ex)
{
MessageBox.Show("Email failed: " + ex.Message, "Failed Send");
}
}
oRecip = null;
email = null;
}
}
private void MainForm_Load(object sender, EventArgs e)
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
oContactsFolder = oNS.PickFolder();
getContacts(oContactsFolder);
oApp = null;
oNS = null;
}
}
}
The long string [000000001A447390AA6611CD9BC800AA002FC45A0300D4985F464F07654AA9CA8D6B785E166E000000004E3B0000] is id for my public folder. Is there anyway to get public folder by name such as "Contatti Itech"?
Thanks again!
modified 8-Nov-12 4:54am.
|
|
|
|