Saturday, December 29, 2007

Survey - The Software Industry Inside Egypt

This survey is one of the first initiatives aims to formulate accurate indicators about the software development industry inside Egypt. The survey will give important information about the current professional level of the software companies. It will try to measure different aspects in the industry like the companies technical level, management, process, salaries and the work environments. The target is to give informative details for the IT stuff to get a clear and transparent information regarding their career.

Please be accurate in your answers as much as you can. Your answer is definitely affect the overall results and the others attitude. The final results will be published here in this blog.

* We don't collect any identity information in this survey.

ANSWER THE SURVEY NOW!

[Update]

[03/2/2008] The survey results have been published. Click here
[31/1/2008] The survey results will be published on Sunday, 3rd February, 2008
[12/1/2008] The survey participation period is extended to 19th Jaunary, 2007


Thursday, December 27, 2007

Vote Results: Do you apply design patterns in your software projects?

This is the result of a vote I made later: Do you apply design patterns in your software projects? The question is to illustrate if the developers really care about learning solutions for already predefined problems. Do you really care about using the best solution to solve a problem?

37 people contributed in the vote. The following is a chart representing people votes.





Design Patterns are a collection of patterns documenting successful solutions for specific problems. The term introduced from a long time. Most of the developers uses the patterns in there daily work, but don't really know that it's a predefined design pattern until they read about it. For more information about the topic, I highly recommend this book: "Design Patterns - Elements of Reusable Object-Oriented Software" by "Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides". For a brief summary about the book, check the Wikipedia Version


Saturday, December 22, 2007

Image Resizing

Sometimes you need to process the users' uploaded images in your web application so that it doesn't take too much space. This can be done either by resizing the uploaded image, saving it in a specific format or may be both.

The following is a code snippet for resizing images and saving it in *.jpeg format. The method take the image file to be resized as a stream, the destination path, the file name to save the image as and the maximum side size of the image (i.e the output image should fit a square of this maximum side size).


public static void ResizeImage(Stream originalImageStream, string destinationFilePath,
string destinationFileName, ImageEncoding saveEncoding, int maxSideSize)
{
int intNewWidth;
int intNewHeight;

Bitmap original = new Bitmap(originalImageStream); // your original image

//Set the image format
ImageFormat fmtImageFormat = original.RawFormat;

//Get the image original width and height
int intOldWidth = original.Width;
int intOldHeight = original.Height;

//Determine if Landscape or Portrait
int intMaxSide;

if (intOldWidth >= intOldHeight)
{
intMaxSide = intOldWidth;
}
else
{
intMaxSide = intOldHeight;
}


if (intMaxSide > maxSideSize)
{
//set new width and height
double dblCoef = maxSideSize / (double)intMaxSide;

intNewWidth = Convert.ToInt32(dblCoef * intOldWidth);
intNewHeight = Convert.ToInt32(dblCoef * intOldHeight);
}
else
{
intNewWidth = intOldWidth;
intNewHeight = intOldHeight;
}


Size resolution = new Size(intNewWidth, intNewHeight); // size of your thumbnail

Image thumbnail = new Bitmap(original, resolution);

Graphics g = Graphics.FromImage(thumbnail);

// The InterpolationMode was the catalyst to eliminate pixelation.
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;

g.DrawImage(original, new Rectangle(0, 0, thumbnail.Size.Width, thumbnail.Size.Height));


// Prepare for a controlled-quality JPEG export
ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
Encoder jpegEncoder = Encoder.Quality;
EncoderParameters jpegEncoderParameters = new EncoderParameters(1);
EncoderParameter jpegEncoderQuality = new EncoderParameter(jpegEncoder, 100L /*jpegQuality*/);

jpegEncoderParameters.Param[0] = jpegEncoderQuality;

thumbnail.Save(destinationFilePath + destinationFileName + ".jpg", jpegCodec, jpegEncoderParameters);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

You will have to get the appropriate codec information to save the image.

ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
1

The following is the implementation of GetEncoderInfo.
private static ImageCodecInfo GetEncoderInfo(string encoderString)
{
foreach (ImageCodecInfo info in ImageCodecInfo.GetImageEncoders())
{
if (info.MimeType == encoderString)
return info;
}

return null;
}
1
2
3
4
5
6
7
8
9
10


Simply you loop through all the encoders in ImageCodecInfo to find JPEG codec info. Other codecs info can also be retrieved for other image types like PNG, JIF and BMP.

The interesting point is in specifying the quality of your output image so that you avoid the pixelation problem and make your output image looks smooth. You declare a new Encoder Parameter with the required quality of your output image. Then you pass the encoding parameters when saving the final resized image.

// Prepare for a controlled-quality JPEG export
ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
Encoder jpegEncoder = Encoder.Quality;
EncoderParameters jpegEncoderParameters = new EncoderParameters(1);
EncoderParameter jpegEncoderQuality = new EncoderParameter(jpegEncoder, 100L /*jpegQuality*/);

jpegEncoderParameters.Param[0] = jpegEncoderQuality;
1
2
3
4
5
6
7

The quality encoder parameter may have varying values (i.e. 25L, 50L, 75L and 100L). You will have to tune it to balance the quality with the output image size.

Another point to mention that there are many other interesting encoders you can make use of like Encoder.Transformation - which allowing you to rotate or swap your images. You can find more information here.


Thursday, December 20, 2007

Language-specific Code Compilation in App_Code

App_Code folder is the default location to add your code files for your ASP.NET project. You may have the situation when you want to add mixed code files written in different languages i.e C# or VB.Net and you need to include these mixed files in the project compilation. The question: Can I have mixed files some written in C# and others in VB.NET in the App_Code folder? Yes, you can but in limitation. First, you will have to add different folders for each language-specific code. Then, in web.config add an entry for each folder inside CodeSubDirectories tag.

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true">
<codeSubDirectories>
<add directoryName="CSharpFolder"/>
<add directoryName="VBFolder"/>
</codeSubDirectories>
</compilation>
</system.web>
</configuration>
If the folder you added to codeSubDirectories tag doesn't physically exist, you will have a compilation error.
The code subdirectory '/MyProject/App_Code/CSharpFolder/' does not exist. E:\Projects\MyProject\web.config 


Monday, December 10, 2007

ASP.NET MVC Framework CTP is Finally Released.

ASP.NET MVC CTP is finally released. The framework is released as a part of new ASP.NET 3.5 Extensions package. The extensions includes some new stuff beside the MVC framewok like: The Entity Framework, new additions for ASP.NET AJAX and others.

Download ASP.NET 3.5 Extensions

Scott Guthrie published a series of articles about MVC. Here is the full list:

ASP.NET MVC Framework: Introduction
ASP.NET MVC Framework (Part2): URL Routing
ASP.NET MVC Framework (Part3): Passing ViewData From Controllers to Views
ASP.NET MVC Framework (Part4): Handling Form Edit and Post Scenarios