Monday, October 20, 2008

How to load images from URI into a .NET image object?

In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it.

The first step, was to retrieve the image from camera into
Image
object. So that it can be displayed or do some processing on it.

Some of the IP cameras have an interface to acquire images or streams. One of the easiest interfaces is giving some steel JPEG images. For example via a simple HTTP request (e.g. http://webcam.mmhk.cz/axis-cgi/jpg/image.cgi) we have an JPEG image.

Here is code snippet to acquire an image from a URI and display in a PictureBox.


//uri resource
Uri uri = new Uri(
"http://webcam.mmhk.cz/axis-cgi/jpg/image.cgi");

//create a stream using a http web request
System.IO.Stream s =
System.Net.HttpWebRequest.Create(uri)
.GetResponse().GetResponseStream();

//create an image object from stream
Image img = Image.FromStream(s);

//display image in a picture box
this.pictureBox1.Image = img;


Simple and easy!

Labels:

Saturday, October 18, 2008

ASP.NET MVC Beta Released

According to this, today beta version of ASP.NET MVC framework has released. You can download it from here. You can also visit www.asp.net/mvc to explore tutorials, quickstarts, and videos to learn more.

The ASP.NET MVC Beta works with both .NET 3.5 and .NET 3.5 SP1, and supports both VS 2008 and Visual Web Developer 2008 Express SP1 (which is free - and now supports class libraries and web application project types).

The Model-View-Controller (MVC) pattern separates the components of an MVC Web application. This separation gives you more control over the individual parts of the application, which lets you more easily develop, modify, and test them.

In an ASP.NET Web site, URLs typically map to files that are stored on disk (usually .aspx files). These .aspx files include markup and code that is processed in order to respond to the request.

The ASP.NET MVC framework maps URLs to server code differently than a typical ASP.NET Web site. Instead of mapping URLs to ASP.NET pages or handlers, the framework maps URLs to controller classes. Controller classes handle incoming requests, such as user input and interactions, and execute appropriate application and data logic, based on user input. (ASP.NET MVC controllers implement a pattern known as the Front Controller pattern.) A controller class typically calls a separate view component that generates HTML output as the response.

You can read more here.

This is a new and great feature that have been added. Have a look at samples to learn more about it.

Wednesday, October 15, 2008

.NET Framework 4 features: Parallel Extensions

Today most of new processors are dual core (let me say multi-core).
Intel and AMD are trying to convince programmers to use the benefits of multi-core processing. You can find many white papers from both Intel and AMD that explains how we can write our codes so that it can be executed better in multi core processors.

One way of achieving this goal is to write your programs using multi threads, and let compiler decide which threads can be executed concurrently in different cores.
Of course this is the easiest way possible, but not the best approach.

Intel have some tools that with using them you can define a new thread (rather than the thread which is provided by your programming language) and you can define some flags to say which threads can run concurrently. This approach works well with Intel processors, but making a general purpose code with this approach is a headache!

Today when I was reading some beta news about .NET features, I saw something very interesting: Parallel Extensions.

In perhaps the most significant development in the brief history of the field of implicit parallelism in computing, one of Microsoft's development teams announced last Friday that the next .NET Framework 4.0 -- the first glimpses of which we'll see later this month from PDC in Los Angeles -- will include the so-called Parallel Extensions as a standard feature. This after the Extensions were first introduced in a Community Technology Preview last November.

The significance of these extensions is that they enable existing .NET languages (today, most predominantly, C#) to incorporate implicit parallelism directly in programs. In other words, rather than simply write ordinary procedural code and use compiler switches to determine whether code can be forked into parallel threads, a developer can use entirely new syntax to invoke methods that execute multiple threads concurrently.

You can read more about this feature in BetaNews.

For C/C++ developers, Intel has a software solution, named Intel Parallel Studio. Here you can find more about this solution.

Labels: ,

Thursday, August 7, 2008

Need to create BarCodes in your .NET Web/Desktop Application?

Need to create BarCodes in your .NET Web/Desktop Application? And you do not want to pay?
Here is a free barcode font to create "Code 39" barcodes very easily.
All you need to do is to install this font (in Windows XP, Vista %systemroot%\fonts) and where you need to place a barcode in your application, just change the font to "Free 3 of 9" and place asterisks before and after your data. e.g. when you want to have a barcode for ABC123 you just need to draw *ABC123* using "Free 3 of 9" font.

And here there is good article from Rui Miguel Barbosa in CodeProject about using this font in a web application.

And here there is another free barcode generating tool from CodeProject.

Tuesday, July 1, 2008

Runing Executable Files in ASP .NET

In this post I will provide you with a code snippet that runs an executable file (.exe) on server side.
For this you need to first declare an object of System.Diagnostics.Process type.
Then set few parameters and then start executing!

System.Diagnostics.Process batch =
new System.Diagnostics.Process();
batch.StartInfo.FileName =
Server.MapPath("~/YourExeFile.exe");
batch.StartInfo.Arguments =
String.Format("Arguments go here");
batch.StartInfo.CreateNoWindow = true;
//if you do not want
//to display the window...
batch.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden;

//now you can start the job...
batch.Start();

//if you want to wait until
//the process terminates,
//you can use the following line:
batch.WaitForExit();


Also note that in order to be able to execute files, you need to have some permissions, here you can find more about security permissions.

You can use this snippet in conjunction with my previous post to build some thing like YouTube ;)

After the user uploads a new video (MPG, AVI and etc.) you can convert the uploaded file to .flv file using this code and FFmpeg tool.

This is a short code for converting videos:

batch.StartInfo.FileName =
Server.MapPath("~/ffmpeg.exe");
batch.StartInfo.Arguments =
String.Format(@"-i ""{0}\t.mpg""
""{0}\t.flv"" -y",
Server.MapPath("~"));

Labels:

YouTube like FLV Flash Video Player for ASP .NET

You may need to show some videos on your ASP .NET site, right?
You can use YouTube and upload your videos to YouTube and put the link of your uploaded video in your site, it's very easy, but you might not like to have YouTube code in your site...
Here is the solution:
Have your own ASP .NET FLV (Flash Video) Player, sounds great!
The ASPNetFlashVideo Component allows you to add YouTube style Flash Videos (.flv files) to ASP.Net websites. ASPNetFlashVideo requires no Flash programming and is unique.
Flash Video can be encoded easily using free tools provided by Riva and Adobe.
You can also use FFmpeg free tool.
It is a command-line based program, and you can easily use it like:
ffmpege.exe -i test.avi test.flv

You also index your flv files with flvTool2 like this:
flvtool2.exe -U test.flv


It's now done!

All you need to do is to place a ASPNETFlashVideo control on your ASPX pages and set it's 'VideoURL' property to .flv file's path.

This control also supports skinning, full screen playback, does not display "Click to activate and use this control" message and etc.

There is also another YouTube like flash video player available at MyCSharpCorner that automatically converts your uploaded videos to .flv files. But it's source code is not available.

Labels:

Saturday, June 21, 2008

Need to access your files every where?

Need to access your files every where? And again you do not want to pay?
Accessing your files every where is a vital thing that most of us need to have.
Normally accessing files remotely need to have an static IP in your source computer, but you do not like to pay?
Here are some solutions:

Use the services provided by LogMeIn
With LogMeIn you can access to your desktop and files from a remote computer. All you need is just an Internet connection in your source computer and signing up in LogMeIn services and have a small program installed on your source computer...
That's all!

LogMeIn have some free services that only support desktop sharing, it is easy to use...
You control your computer's desktop remotely using a browser-based program.
And if you pay a little and upgrade your account, you can have file-transfer service as well.
You can test these features for a limited time, but as I say before, desktop sharing is free...

The second solution is to have a VPN and simply connecting to your Virtual Private Network and accessing your shared files and folders...
But there is an small problem here and that is: Your IP changes every time, so you need an static IP.
You do NOT want to pay for an Static IP? Here is the solution:
No-IP

Signing up and installing an small program, then you choose a sub domain name for your source computer, that's all!
Now you have a URL that every time points to your source computer...
The resident program updates your computer's IP address (each time it changes) in the sub domain's records.

With this free service, you can setup your own web server (e.g. for testing purposes), set up your own VPN and better than all: have remote-connections to your computer using Remote Desktop.

It is really fantastic!

I've setup my own web-server in my home computer for testing purposes.
I've also setup remote connections so when ever I need to access my files, it could not be easier than this using these free services...

Have a try!