Monday, 20 October 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!

Saturday, 18 October 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, 15 October 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.