How to take a screenshot in C#

The subsequent code snippet can be used to take screenshots in C#.Net. The screenshots, you capture with the following snippet, equal to the screenshots you take by pressing the print-key on your keyboard. (Certainly aside from the fact that the screenshot won’t be in your clipboard, but you will get a bitmap object, which can be used to manipulte in anyway you like in C#.)
Because the the source code is very short, I’ll let it speak for itself.

private Bitmap Screenshot()
{
//Create a bitmap with the same dimensions like the screen
Bitmap screen = new Bitmap(SystemInformation.VirtualScreen.Width,
SystemInformation.VirtualScreen.Height);

//Create graphics object from bitmap
[…]

How to normalize mp3-files in C#

Who doesn’t know the following situation? You create a playlist with your favorite songs, looking forward to a leisurely afternoon on the couch and nevertheless the right mood won’t be there.
The first song roars at you, so you take your remote and turn down your music. The next song is so quiet, that it’s really hard to understand anything. So you turn you volume up again. And so on…
The magic word for this problem is normalization. Goal of normalization is that every song has the same maximum volume level. So you can still hear the difference between quiet and loud parts of a song, but the volume level of the songs to each other is adjusted.
Today I’ll show you how to write a program in C# which can normalize your music files.
What do you need?

The mp3gain.exe, which can be downloaded from my blog
The following snippet of C#-code

private void mp3Normalization()
{
[…]

Create different/unique random numbers in C#

After I’ve shown you (in this post) how to generate unique random numbers in PHP, I’ll show you now how to do the same thing in C#. If you’re wondering, for what you need different unique random numbers, you really should have a gander at the PHP-based article. Otherwise go on and take a look at the following snippet.

//Define the range of random numbers, from which
//the routine should choose
int smallestNumber = 1;
int biggestNumber = 10;

//Determine the amount of random numbers
int amountOfRandomNumbers = 5;

//Create a list of numbers from which the routine
//shall choose the result numbers
List possibleNumbers = new List();
for (int i = smallestNumber; i <= biggestNumber; i++)
possibleNumbers.Add(i);

//Create a list, which shall hold the result numbers
List resultList = new List();

//Initialize a random number generator
Random rand = new Random();

//For-loop which picks each round a unique random number
for (int i = 0; i < amountOfRandomNumbers; i++)
{
[…]

Free german spellchecker from Duden

The following post maybe is a little bit more directed on the german readers over at code-bude.net, but correctly I add a translation also for my international readers. Spelling correction is everywhere. Not matter if you use Microsofts Word, your smartphone, your mobile or your webbrowser of choice. Each of it brings its own spellchecker with it.

The problem is, that the German language, especially the German grammar, is more or less complex compared to a lot of other languages. So the most of the correction software doesn’t work quite well. However one, which works really good, is the one from Duden, the german standard reference spelling directory.
So if you maybe are learning the German language or want to be on the safe side, you could use the Duden spellchecker. The amazing thing about the Duden software is, that they provide […]

Generate array of different/unique random numbers in PHP

Sometime it is necessary to generate a list of different random numbers. A possible usage scenario therefore could be a raffle where the winners should be choosen by chance, but every single user shouldn’t get more than one prize.
So in the following snippet, I’ll show you how to generate a list of different randoms in PHP.

<?php
//Create an array of numbers from which the randoms
//should be choosen. (For raffle: the list of user id’s)
$array = range($minimum, $maximum);

//Initialize the random generator
srand ((double)microtime()*1000000);

//A for-loop which selects every run a different random number
for($x = 0; $x < $numberOfRandoms; $x++)
{
//Generate a random number
$i = rand(1, count($array))-1;

//Take the random number as index for the array
$result[] = $array[$i];

//The chosen number will be removed from the array
//so it […]