|
I showed you how determine group membership in this post[^]
You need to use the IsInRole method of the CurrentPrincipal object to check for membership, which you could do in a simple if statement.
if (Thread.CurrentPrincipal.IsInRole(@"MYDOMAIN\MyApplicationAdministrators")
{
}
else if (Thread.CurrentPrincipal.IsInRole(@"MYDOMAIN\MyApplicationMangers")
{
}
You wouldn't really use a switch statement for this. Also, you can use imperative or declarative security to check for group membership at method level as well, e.g.
http://msdn.microsoft.com/en-us/library/system.security.permissions.principalpermissionattribute.aspx[^]
[PrincipalPermission(SecurityAction.Demand, Role = "MYDOMAIN\MyApplicationAdministrators")]
static void CheckAdministrator()
{
Console.WriteLine("User is an administrator");
}
|
|
|
|
|
Hello, i have designed a window in c# which contains one combobox(contains detected USB devices), one picturebox(for the video), one label, one start button(starts the camera)and one refresh button.
I have a USB security IR camera which i want to connect to the computer and hopefully get some video feed in the picturebox.
I have debugged and builded the project and the designed window pops up as it should. When i push the refresh button while the USB camera is connected,it is written in the combobox "USB 2.0 grabber". When i then push the start button nothing happens. Can somebody help me/explain to me how to get the video feed into the picture box? I really appreciate some help.
Source code follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AForge.Video;
using AForge.Video.DirectShow;
namespace cam_aforge1
{
public partial class Form1 : Form
{
private bool DeviceExist = false;
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSource = null;
public Form1()
{
InitializeComponent();
}
private void getCamList()
{
try
{
videoDevices = new FilterInfoCollection (FilterCategory.VideoInputDevice);
comboBox1.Items.Clear();
if (videoDevices.Count == 0)
throw new ApplicationException();
DeviceExist = true;
foreach (FilterInfo device in videoDevices)
{
comboBox1.Items.Add(device.Name);
}
comboBox1.SelectedIndex = 0;
}
catch (ApplicationException)
{
DeviceExist = false;
comboBox1.Items.Add("No capture device on your system");
}
}
private void rfsh_Click(object sender, EventArgs e)
{
getCamList();
}
private void start_Click(object sender, EventArgs e)
{
if (start.Text == "&Start")
{
if (DeviceExist)
{
videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
064 CloseVideoSource();
videoSource.DesiredFrameSize = new Size(160,120);
videoSource.Start();
label2.Text = "Device running...";
start.Text = "&Stop";
timer1.Enabled = true;
}
else
{
label2.Text = "Error: No Device selected.";
}
}
else
{
if (videoSource.IsRunning)
{
timer1.Enabled = false;
CloseVideoSource();
label2.Text = "Device stopped.";
start.Text = "&Start";
}
}
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap img = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = img;
}
private void CloseVideoSource()
{
if (!(videoSource == null))
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource = null;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
label2.Text = "Device running... " + videoSource.FramesReceived.ToString() + " FPS";
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
CloseVideoSource();
}
}
}
<pre>
|
|
|
|
|
Nothing happens? The label on the button at least should change. If that isn't happening, make sure you actually hooked the event up to the button.
064 CloseVideoSource();
This is a pasting failure, right? Calling Close there would mess up the rest of the start code.
|
|
|
|
|
Edit your original message and in the pre block add the attribute/value lang="cs", that way you will get the colour syntax for C#, like the bit below;
private void timer1_Tick(object sender, EventArgs e)
{
label2.Text = "Device running... " + videoSource.FramesReceived.ToString() + " FPS";
}
|
|
|
|
|
How would one access each pixel on a form quick enough for a bitmap to be drawn 30 times a second?
I would like to avoid Bitmap.SetPixel and if possible avoid XNA/Direct X. I built a 3D engine that plots its own triangles etc with textures and shadows. I just don't think using Bitmaps is quick enough. I.E really slow just drawing a black screen.
Is it possible to access per-pixel data in XNA?
|
|
|
|
|
Search for the use of LockBits() .
It converts bitmap images to and from byte arrays. You have to keep track of which byte means what colour component (Alpha, Red, Green, Blue, order may be mangled). Byte array operations are a lot faster than SetPixel() .
Some code I wrote after searching the web for the same thing:
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
System.Drawing.Imaging.BitmapData imageData = image.LockBits(
rectangle,
System.Drawing.Imaging.ImageLockMode.ReadWrite,
image.PixelFormat
);
IntPtr ptr = imageData.Scan0;
int byteCount = Math.Abs(imageData.Stride) * image.Height;
byte[] rgbValues = new byte[byteCount];
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, byteCount);
for (int rgbIndex = 3; rgbIndex < rgbValues.Length; rgbIndex += 4)
{
}
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, byteCount);
image.UnlockBits(imageData);
Ciao,
luker
|
|
|
|
|
I already was using locked bits, sorry. I should have mentioned that much. Looking from the code you've posted though, i've managed to fix the colouring in what I do have. The Red and the Blue were the wrong way aroung :p
Thanks for teh help
|
|
|
|
|
You mentioned SetPixel in the initial question. You're not using that after locking, right? Something similar to what's posted here (locking the bits, marshalling into a byte[], setting the byte values, marshalling it back) is the usual procedure and it is quite fast (I believe, never done it myself).
|
|
|
|
|
Nah, I'm not doing that. I'm locking and unlocking. I just used set pixel to deter people from recommending to use it. I looked back in my previous questions and saw you had made some comments
Locking and Unlocking is still not quick enough unfortunatley
|
|
|
|
|
You can always work with the bits using pointers. Christian Graus outlines a method here[^].
|
|
|
|
|
Interesting article. Its quite similar to my implementaion. In his though he changes the data in the loop. Whilst in mine on the other hand I calculate the entire image in a byte[] then transfer it to a function similar to his to write the bitmap. Maybe I could directly interact in the image processing loop.
Time to experiment
|
|
|
|
|
I wonder if what you're doing inside that pixel loop is too intensive. In particular, if you're reading R, G, B, A properties from a Color each time, that might cause speed issues. If you can have your renderer write directly into the byte array that might help.
|
|
|
|
|
Not going to lie. My ambition in this project is a raytracer. If I can realtime
|
|
|
|
|
A realtime ray tracer will be hard (understatement) without using some hardware acceleration, unless for a very small viewport.
|
|
|
|
|
true, true, Worth a shot. To get a frame a second it has to be ~300px * 150px viewport with reflections and ambient occlusion turned off. I don't know anything about handling hardware though. Currently it is all handled by c# .NET & GDI
|
|
|
|
|
It's tricky to write a software renderer that will be fast enough.
If you want direct pixel access, LockBits is indeed the answer. Depending on what your engine is producing, you may want to draw shapes instead (though if you are texture mapping and lighting, by pixel may be necessary).
|
|
|
|
|
My old engine used the graphics.DrawLine and the graphics.FillPolygon . This (even drawing a simple triangle) was much quicker than using a hand built pixel plotter using locked bits :/
My new engine has lighting and diffuse textures (working but slow at a frame per second with a few meshes on the screen)
Thanks
|
|
|
|
|
i have created a wcf service in 3.5 and trying to host it on 11s6. service was created on windows 7
when i host and browse for the service i get the error
"This collection already contains an address with scheme http. There can be at most one address per scheme in this collection"
i tried couple of things in web config but still getting the error
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://localhost/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
any idea how to get through this
|
|
|
|
|
Are you using multiple bindings in the service? If you use multiple bindings that use same protocol, it throws error.
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
|
|
|
|
|
i am using basichttp binding
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHTTP" sendTimeout="00:10:00" closeTimeout="00:05:00" openTimeout="00:1:00" receiveTimeout="00:05:00"
allowCookies="true" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="F2F.Service1" behaviorConfiguration="F2F.Service1Behavior">
<endpoint address="" binding="basicHttpBinding" contract="F2F.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="F2F.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
|
|
|
|
|
I am working with WCF and Rest services, where i defined a UriTempalte with some http request, i know how to call this Request and Response functionality in ASp.Net, can i cal same Request, and get Response in Javascript/Jquery. I googled alot, please any one help me regarding this...
Thnks in Advance..
|
|
|
|
|
It's been a while, but it should be something like this I think.
var val1 = document.getElementById('clientid1').value;
var val2 = document.getElementById('clientid2').value;
var val3 = document.getElementById('clientid3').selectedIndex;
var val4 = document.getElementById('clientid4').options[index].innerHTML;
var val5 = document.getElementById('clientid5').innerHTML;
var datapropt = "{'val1':'" + val1 + "'";
datapropt += ", 'val2':'" + val2 + "'";
datapropt += ", 'val3':'" + val3 + "'";
datapropt += ", 'val4':'" + val4 + "'}";
$.ajax({
type: "POST",
url: "StaticWebMethods.asmx/TheWebMethodName",
data: datapropt,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
location.reload(true);
}
});
the function in the StaticWebMethods.asmxfile would look similar to this:
[WebMethod]
public static bool TheWebMethodName(int val1, string val2, string val3, string val4){
}
Hope this helps.
V.
|
|
|
|
|
I am looking to create a small application that I can load an xml or to connect to a DB and generate some controls on a User interface.
The xml or DB needs to store only 10 controls.
Best regards,
Yous
|
|
|
|
|
Uh huh... well that's easy enough, many ways to go about it. Are you just looking to experiment? Or do you have a real scenario?
|
|
|
|
|
I have a small scenario.
I 'd like to create/store in a XML or db some controls like textbox, listbox, combobox,... Défined by the Administrator.
When the user start the gui, the user interface will be generated from the xml or db.
After,The user Will fill the datas selected with the controls and after i need to generate an XML file or db with the content.
|
|
|
|