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.

Thursday, 7 August 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, 1 July 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("~"));

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.

Friday, 20 June 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!

Wednesday, 18 June 2008

SQL Express


Most often our apps are involved with databases. Since the release of SQL Server 2005, Microsoft announced a light-weight version of SQL named: SQL Express.
SQL Express is a successor of Microsoft Database Engine and is the freely-downloadable and distributable version of Microsoft's SQL Server relational database management system.
It offers a database solution specifically targeted for embedded and smaller-scale applications. Unlike its predecessor, MSDE, there is no concurrent workload governor which "limit[s] performance if the database engine receives more work than is typical of a small number of users." It does, however, have a number of technical restrictions which make it undesirable for large-scale deployments.
You can find these restrictions list from here.
The latest release of it is SQL Express Service Pack 2.
You can get it from here.

SQL Express have a small setup file size (about 54 MB) and can be installed very easily.

You can have silent setup of SQL Express with these command arguments:
-q /norebootchk /qn reboot=ReallySuppress addlocal=all instancename="sqlexpress" SQLAUTOSTART=1 ADDUSERASADMIN=1

(For complete listing visit here)

Also note that SQL Express has some prerequisites like:
Windows Installer 3.1 and .NET Framework 2.0

Before your install script tries to install SQL Express, you check whether SQL Express is installed or not.
You just need to check this registry entry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\CurrentVersion

If the value of "CurrentVersion" is some thing like (or greater than) this: 9.00.3042.00
Then the SQL Express SP2 is already installed and your setup program does not need to install it again.

FireFox 3 Released!


Mozilla Firefox 3 has been released. Available for Windows, Mac OS X and Linux in 46 different localisations, Firefox 3 is the most major Mozilla browser release since the launch of Firefox 2 in October 2006 and represents the culmination of over three years work (development on Firefox 3 began before even Firefox 1.5 came out). According to the press release announcing Firefox 3, the new version has over 15,000 improvements.

Firefox 3 can be downloaded from the redesigned Firefox product page or the Firefox 3.0 directory on releases.mozilla.org (it's not yet being offered to Firefox 2 users via the software update system). More information can be found in the Firefox 3 Release Notes.

The use of newer technologies means that Firefox 3 has higher system requirements than Firefox 2. In Microsoft land, Windows 95, 98, ME and NT 4.0 are no longer supported. On the Mac side, the minimum OS X version jumps from 10.2 Jaguar to 10.4 Tiger. In both cases, the operating system versions that are no longer supported have long since been abandoned by even Microsoft and Apple.

The Mozilla servers have been experiencing problems due to high demand for Firefox 3. This actually delayed the full release of Firefox 3 by more than an hour. According to a Mozilla Developer News weblog post, Firefox 3 is being downloaded more than 14,000 times a minute.

With the launch of Firefox 3, Mozilla is hoping to set a Guinness World Record for the most downloads in twenty-four hours. The number of downloads so far can be tracked at downloadcounter.sj.mozilla.com. Only full, completed downloads count and users have until 11:16am Pacific Daylight Time on Wednesday (6:16pm UTC/GMT) to make a participating download. The official Mozilla Blog has an entry about the Download Day with more details.

Those who just can't get enough of the Firefox 3 launch are invited to attend a Mozilla Party to celebrate or watch the action live from Mozilla HQ on Air Mozilla.

Read the full article for more details about what's new in Firefox 3 here.

Wednesday, 11 June 2008

Need to create PDF files from your .NET applications?

Need to create PDF files from your .NET applications? and you do NOT want to pay for a component?
Here is the solution:
iTextSharp

iText is a free and open source library for creating and manipulating PDF, RTF, and HTML files in Java. It was written by Bruno Lowagie, Paulo Soares, and others; it is distributed under the Mozilla Public License with the LGPL as alternative license.
iText# (iTextSharp) is a port of the iText open source java library written entirely in C# for the .NET platform. iText# is a library that allows you to generate PDF files on the fly. It is implemented as an assembly.

This open source project is hosted in sourceforge.net
You can get it from: iTextSharp Home Page

And here is a nice tutorial of iTextSharp on CodeProject.com

Also note that this component is not working for Persian (Farsi) language...

Friday, 30 May 2008

Tuesday, 15 April 2008

Call server side code by javascript using Ajax.Net framework


Call server side code by javascript using Ajax.Net framework
taken from: http://www.codeproject.com/KB/ajax/Ajax_Call_using_AjaxNet.aspx


Lots of time we require to call server side code using JavaScript (it means Ajax Call) and without post back. There are lots of technologies are available for that. Some people use Ajax.dll to perform this operation. But now when Ajax.Net framework is available then there is no need to use third party dll for Ajax Call...

View the complete article...