Comparing Two Images in C#
I’ve recently been doing a bit of work generating images, I have also need to compare the images that I generate with an image that has already exists.
I found a number of web sites that suggested the following way of comparing two images, by cycling through each pixel in an image and returning false if there is a mismatch in the pixels.
Search This Blog
Sunday, April 04, 2010
Thursday, April 01, 2010
*A quick brain tickler**…*
*A quick brain tickler**…*
Please look at the math below:
They say only people with an IQ with 120 and over are able to figure this
out.
If:
2 + 3 = 10 = 2
7 + 2 = 63 = 7
6 + 5 = 66 = 6
8 + 4 = 96 = 8
Then:
ch
9 + 7 = ????
The number you find out is the password to open the attachment.
Sign your name, save it, and forward it, replacing the original
attachment with your saved updated attachment, to any more smart
people you know
For answer, get back after 24 hours
Please look at the math below:
They say only people with an IQ with 120 and over are able to figure this
out.
If:
2 + 3 = 10 = 2
7 + 2 = 63 = 7
6 + 5 = 66 = 6
8 + 4 = 96 = 8
Then:
ch
9 + 7 = ????
The number you find out is the password to open the attachment.
Sign your name, save it, and forward it, replacing the original
attachment with your saved updated attachment, to any more smart
people you know
For answer, get back after 24 hours
Download File here
Saturday, March 13, 2010
Working with Delegates in C#
| Abstract In this article I'll discuss what delegates are with lucid code examples. Introduction | |
Delegates in C# are like functions pointers in C/C++. A multi cast delegate can refer to several methods. A delegate can be used to invoke a method, the call to which can only be resolved or determined at runtime. This article discusses what delegates are and how they can be used in C# with lucid code examples. |
Friday, March 12, 2010
Understanding Connection Pooling in .NET
Abstract
Connection Pooling can increase the database performance to a huge extent. This article discusses what Connection Pooling actually is, how it can boost the performance of database access and how we can create a Connection Pool in .NET and add and remove connections to it.
Connection Pooling can increase the database performance to a huge extent. This article discusses what Connection Pooling actually is, how it can boost the performance of database access and how we can create a Connection Pool in .NET and add and remove connections to it.
| Introduction | |
Connecting to the database is resource intensive and a relatively slow operation in an application but the most crucial of them all. A Connection Pool is a container of open and reusable connections. A Connection Pool is released from the memory when the last connection to the database is closed. The basic advantage of using Connection Pooling is an improvement of performance and scalability while the main disadvantage is that one or more database connections, even if they are currently not being used, are kept open. The Data Providers in ADO.NET have Connection Pooling turned on by default; if you need to turn it off, specify Pooling = false in the connection string being used. Connection Pooling gives you an idle, open, reusable connection instead of opening a new one every time a connection request to the database is made. When the connection is closed or disposed, it is returned to the pool and remains idle until a request for a new connection comes in. If we use Connection Pooling efficiently, opening and closing of connections to the database becomes less resource expensive. This article discusses what Connection Pooling is all about and how Connection Pooling can be used efficiently to boost the performance and scalability of applications. |
Working with Images Using .NET
Abstract
In this code snippet I will examine how to work with images using Visual Studio .NET 2003 and SQL Server 2000 database.
Introduction
Some applications, be it desktop or web, require working with images. Aptly speaking, the good paradigm is banking applications. Withdrawal of an amount of money from a bank account requires signature verification of the account holder. Normally, specimen signatures of customers are archived as images in such applications.
In this code snippet I will examine how to work with images using Visual Studio .NET 2003 and SQL Server 2000 database.
Introduction
Some applications, be it desktop or web, require working with images. Aptly speaking, the good paradigm is banking applications. Withdrawal of an amount of money from a bank account requires signature verification of the account holder. Normally, specimen signatures of customers are archived as images in such applications.
Working with Images Using .NET
Abstract
In this code snippet I will examine how to work with images using Visual Studio .NET 2003 and SQL Server 2000 database.
Introduction
Some applications, be it desktop or web, require working with images. Aptly speaking, the good paradigm is banking applications. Withdrawal of an amount of money from a bank account requires signature verification of the account holder. Normally, specimen signatures of customers are archived as images in such applications.
There can be a couple of ways to work around to store images. One is typically to tag each image with a unique identifier and save the image at a physical location accessible by the application. Store that unique identifier and the physical absolute/relative path in a database table. Now, when the application looks in for a given identifier from database table then the path against the identifier can be pulled from the table and uses that path in any image control to display the image.
In this code snippet I will examine how to work with images using Visual Studio .NET 2003 and SQL Server 2000 database.
Introduction
Some applications, be it desktop or web, require working with images. Aptly speaking, the good paradigm is banking applications. Withdrawal of an amount of money from a bank account requires signature verification of the account holder. Normally, specimen signatures of customers are archived as images in such applications.
There can be a couple of ways to work around to store images. One is typically to tag each image with a unique identifier and save the image at a physical location accessible by the application. Store that unique identifier and the physical absolute/relative path in a database table. Now, when the application looks in for a given identifier from database table then the path against the identifier can be pulled from the table and uses that path in any image control to display the image.
Multithreading with an Example of .NET Application
Abstract
In this article I will discuss the basics of multithreading and how it could be effective over a single thread application. It also includes the advantages and disadvantages of multithreading. The article includes the complete .NET project for creating a simple multithreaded application.
In this article I will discuss the basics of multithreading and how it could be effective over a single thread application. It also includes the advantages and disadvantages of multithreading. The article includes the complete .NET project for creating a simple multithreaded application.
Introduction
Threads are also known as lightweight processes. However, if we go into depth then we would know that a thread is not actually a process; rather it provides ways for executing different parts of a program. Now let us discuss what it actually means by multithreading. Multithreading (as the name suggests multi+threading) is nothing but an efficient execution of multiple threads at a time to enhance the performance of the application. For example, we are doing a file copy operation with a status bar on UI indicating the completion percentage. Here we need to keep track of how much file size is copied and at the same time we also need to advance the progress bar accordingly. This can not be done efficiently in a single thread and you have to use multiple threads.
The above example shows just one instance where we are forced to use multithreading. However, when we are not forced we can also use this for the betterment of the application performance. And of course, all this depends on how effectively the thread is implemented in an application. Most of the developers do not use multithreaded applications and continue with a single thread. However, the efficient use of threads can give birth to a highly powerful application.
Thursday, March 11, 2010
Localization in ASP.NET 2.0 (advanced)
Abstract
This article will cover some more of the Visual Studio 2005 enhancements for making Resources easier to include in your project, as well as showing the various ways that Resources can be included through code within your applications.
In the previous article, the Visual Studio .NET 2005 features for easily Localizing a web site were explored without using any code.
This article will cover some more of the Visual Studio 2005 enhancements for making Resources easier to include in your project, as well as showing the various ways that Resources can be included through code within your applications.
In Visual Studio 2005 Web Site's there is the concept of a "Resources" folder living on the root of your web site. In this folder you can place, surprisingly enough, resources. Unlike the Resources discussed in the Previous Article, any Resources placed in the Resources folder have scope across the whole Application, in that they can be accessed from any Web Form or Code, whereas the Resources stored in "LocalResources" folders are only associated with a specific .aspx.
Visual Studio 2005 not only supports the use of the Resources folder, it's embraced and encouraged, this is done by offering Developers Strongly Typed access right in to their Resource files through the Resources Namespace, for example if there is a .resx in the Resources folder called "Bob" and within Bob.resx there is a Resource String called "Alice" with a value of Cake, in your .aspx all you need to do to access the Resource String "Alice" (with full intellisense of course) is type: -
string AlicesFavFood = Resources.Bob.Alice.ToString();
Oh, ResGen is Dead, RIP ResGen.
Now you've picked yourself up off the floor after that moment of enthusiastic bouncing let's continue.
The above happens without the need to recompile, all that you the developer needs to do, is Save the .resx file and you instantly get all the Intellisense within your application.
Intellisense on your Resources is really usful, especially if you're no the person that put together the Resource files, this allows you to quickly get hold of the right Resources within your applications. However. And it's a Big However. To me, it's very rare that I will know the name a of Resource for my controls before I come to actually write the controls them selves, this leaves us in somewhat of a Chicken and Egg situation.
I see this functionality being useful mainly where you have General resources, such as you might have on an e-commerce site, strings such as "Price", "Shopping Basket" and "Checkout" might be strings you regularly use in many different e-commerce applications, I see having a Resource file that you drop in to each of your projects with General Resources being used with the Intellisense, otherwise I think it may be an otherwise unused piece of Visual Studio 2005 functionality.
Accessing resources in code can be achieved in a variety of ways, mainly depending on the source of the Resource. Along with the meta Resources discussed in the previous article it's also possible to explicitly include Text from Resource Files stored in the LocalResources folder as so: -
Or in Code Beside/Behind you can access the LocalResources of a page by using the GetPageResourceObject() method of the Page.
string LocalResource = (string)GetPageResourceObject("LabelResource1.Text");
It's also possible to Localize static content, i.e. just basic strings that don't need to have Server Side access.
Some Default Content
Using Application level resources is possible through the Resources member as shown above, but it can also be accessed programatically in pages via the GetAppResourceObject() method, as so: -
string ApplicationResource = (string)GetAppResourceObject("Bob", "Alice");
As well as the Programatic access, it's possible to retreive the Application level Resources declaritavly like this: -
So there you have some more of the new features in ASP.NET 2.0, everything about Localization in ASP.NET 2.0 is so much easier. The next articles in this series will discuss .Resource files in ASP.NET 2.0 and Database stored Resources.
Happy Dotnetting... :)
This article will cover some more of the Visual Studio 2005 enhancements for making Resources easier to include in your project, as well as showing the various ways that Resources can be included through code within your applications.
In the previous article, the Visual Studio .NET 2005 features for easily Localizing a web site were explored without using any code.
This article will cover some more of the Visual Studio 2005 enhancements for making Resources easier to include in your project, as well as showing the various ways that Resources can be included through code within your applications.
In Visual Studio 2005 Web Site's there is the concept of a "Resources" folder living on the root of your web site. In this folder you can place, surprisingly enough, resources. Unlike the Resources discussed in the Previous Article, any Resources placed in the Resources folder have scope across the whole Application, in that they can be accessed from any Web Form or Code, whereas the Resources stored in "LocalResources" folders are only associated with a specific .aspx.
Visual Studio 2005 not only supports the use of the Resources folder, it's embraced and encouraged, this is done by offering Developers Strongly Typed access right in to their Resource files through the Resources Namespace, for example if there is a .resx in the Resources folder called "Bob" and within Bob.resx there is a Resource String called "Alice" with a value of Cake, in your .aspx all you need to do to access the Resource String "Alice" (with full intellisense of course) is type: -
string AlicesFavFood = Resources.Bob.Alice.ToString();
Oh, ResGen is Dead, RIP ResGen.
Now you've picked yourself up off the floor after that moment of enthusiastic bouncing let's continue.
The above happens without the need to recompile, all that you the developer needs to do, is Save the .resx file and you instantly get all the Intellisense within your application.
Intellisense on your Resources is really usful, especially if you're no the person that put together the Resource files, this allows you to quickly get hold of the right Resources within your applications. However. And it's a Big However. To me, it's very rare that I will know the name a of Resource for my controls before I come to actually write the controls them selves, this leaves us in somewhat of a Chicken and Egg situation.
I see this functionality being useful mainly where you have General resources, such as you might have on an e-commerce site, strings such as "Price", "Shopping Basket" and "Checkout" might be strings you regularly use in many different e-commerce applications, I see having a Resource file that you drop in to each of your projects with General Resources being used with the Intellisense, otherwise I think it may be an otherwise unused piece of Visual Studio 2005 functionality.
Accessing resources in code can be achieved in a variety of ways, mainly depending on the source of the Resource. Along with the meta Resources discussed in the previous article it's also possible to explicitly include Text from Resource Files stored in the LocalResources folder as so: -
Or in Code Beside/Behind you can access the LocalResources of a page by using the GetPageResourceObject() method of the Page.
string LocalResource = (string)GetPageResourceObject("LabelResource1.Text");
It's also possible to Localize static content, i.e. just basic strings that don't need to have Server Side access.
Some Default Content
Using Application level resources is possible through the Resources member as shown above, but it can also be accessed programatically in pages via the GetAppResourceObject() method, as so: -
string ApplicationResource = (string)GetAppResourceObject("Bob", "Alice");
As well as the Programatic access, it's possible to retreive the Application level Resources declaritavly like this: -
So there you have some more of the new features in ASP.NET 2.0, everything about Localization in ASP.NET 2.0 is so much easier. The next articles in this series will discuss .Resource files in ASP.NET 2.0 and Database stored Resources.
Happy Dotnetting... :)
How to do a language switch in a master page.
As the rap song goes: “There’s no champagne in the champagne room...”, there is no page in MasterPage. It derives from UserControl. As such it does not support the InitializeCulture() method for us to override as described in this post. Newbies love master pages, even though half the time they do not understand them, so here is a solution, compounding the misuse, but here it goes.
Don't try to access controls in InitializeCulture()
InitializeCulture() is an empty protected virtual method in the Page class. So it is empty in the inherited class too that the IDE generates. When overriding it there is no need to call the base method.
What is noteworthy is the fact that is IS VERY EARLY ON, in the page lifecycle. Way before any controls exist. So most postback handlers that depend on controls are worthless for setting the culure in the thread, BECAUSE THEY ARE ALL LATE.
So how do we do a dropdown or a listbox to switch languages? Isn’t the dropdown a server control? Here is the magic that keeps so many people, that are enamored with localization, stumped.
There is a Http collection called the “form data set” which is passed in every request. It is a name value collection. The keys are the name attributes of the html elements in the form tag. The values depend on the element. For a dropdown that value is the selected value (if no value, then the selected text, if none then the first item) These are what is known as “successful control” rules. At the time of submission the browser gathers up these values and submits the collection along with the request.
Notice no aspnet so far. The aspnet representation of that collection is the HttpRequest.Form property. Its type isSystem.Collections.Specialized.NameValueCollection and thenicest thing is, IT HAS NOTHING TO DO WITH SERVER CONTROLS. How do we know? Just try retrieving the values from a regular html form element without runat=server and you will know; all without the aspnet runtime doing anything more than reading the browser request.
So we get it for free, and we get it right away and we get it every time.This is the key concept. Plus the collection items map to form elements. So we can grab values out of it inside the InitializeCulture() method and never wait for the full controls to be built. The HttpRequest is exposed as the Request property of the page class.
the server control
<asp:DropDownList runat="server" ID="ddl" AutoPostBack="true" />
renders as the html element, with both the name and value attributes the same(provided not declared in a template like a user control or a master page)
<select name="ddl" id="ddl">
Here is a sample of that code. Here is a video demo
EVERY PAGE NEEDS THE THREAD SET DE NOVO, because the thread dies at the end of the page lifecycle. So it becomes a pain to do this code over and over again. We can inherit from our own page class that overrides this method and never have to see it from code behind. The problem is that OO intimidateas the hell out of newbies. Also the class would be too closely coupled with the form element under question and I myself have a paranoia of coupling business logic. User controls and master pages do not support the InitializeCulture() method.
So System.Globalization is really in the way of code globalization! ;)
Here is a solution how to do a language switch dropdown in a master page with globalized code.
Happy Dotnetting... :)
What is noteworthy is the fact that is IS VERY EARLY ON, in the page lifecycle. Way before any controls exist. So most postback handlers that depend on controls are worthless for setting the culure in the thread, BECAUSE THEY ARE ALL LATE.
So how do we do a dropdown or a listbox to switch languages? Isn’t the dropdown a server control? Here is the magic that keeps so many people, that are enamored with localization, stumped.
There is a Http collection called the “form data set” which is passed in every request. It is a name value collection. The keys are the name attributes of the html elements in the form tag. The values depend on the element. For a dropdown that value is the selected value (if no value, then the selected text, if none then the first item) These are what is known as “successful control” rules. At the time of submission the browser gathers up these values and submits the collection along with the request.
Notice no aspnet so far. The aspnet representation of that collection is the HttpRequest.Form property. Its type isSystem.Collections.Specialized.NameValueCollection and thenicest thing is, IT HAS NOTHING TO DO WITH SERVER CONTROLS. How do we know? Just try retrieving the values from a regular html form element without runat=server and you will know; all without the aspnet runtime doing anything more than reading the browser request.
So we get it for free, and we get it right away and we get it every time.This is the key concept. Plus the collection items map to form elements. So we can grab values out of it inside the InitializeCulture() method and never wait for the full controls to be built. The HttpRequest is exposed as the Request property of the page class.
the server control
<asp:DropDownList runat="server" ID="ddl" AutoPostBack="true" />
renders as the html element, with both the name and value attributes the same(provided not declared in a template like a user control or a master page)
<select name="ddl" id="ddl">
Here is a sample of that code. Here is a video demo
EVERY PAGE NEEDS THE THREAD SET DE NOVO, because the thread dies at the end of the page lifecycle. So it becomes a pain to do this code over and over again. We can inherit from our own page class that overrides this method and never have to see it from code behind. The problem is that OO intimidateas the hell out of newbies. Also the class would be too closely coupled with the form element under question and I myself have a paranoia of coupling business logic. User controls and master pages do not support the InitializeCulture() method.
So System.Globalization is really in the way of code globalization! ;)
Here is a solution how to do a language switch dropdown in a master page with globalized code.
Happy Dotnetting... :)
Labels:
change language,
cultureinfo,
initializeculture,
localization,
uiculture
Subscribe to:
Posts (Atom)