Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Converting Graphics to HD Photo (WDP / HDP)

Learn how to convert popular graphic files such as JPEG, GIF or PNG to the new HD Photo format from Microsoft. HD Photo debuted in Windows Vista, with the file extension WDP and recently HDP.

On Sunday, May 27th 2007 at 11:13 PM
By Andrew Pociu (View Profile)
****-   (Rated 4 with 5 votes)
Contextual Ads
More C# Resources
Advertisement
Download this Visual Studio 2005 project Download this project (Visual Studio 2005)

The new HD Photo file format from Microsoft is available in Windows Vista and included in .NET Framework 3.0. It offers better quality than JPEG at (most of the time) half the file size.
The file format has recently had its name changed from Windows Media Photo to HD Photo. Also, aside from WDP which we will be using in this tutorial, a new file extension will be handled by HD Photo: HDP. We are sticking to WDP in this tutorial since the HDP extension was introduced only recently and its thus not recognized by most of the software that handles HD Photos, such as the initial release of Windows Vista. WDP and HDP are one and the same, the only different is in the name of the final extension.
For more information on HD Photo, see Bill Crow's HD Photo Blog at MSDN.com. He talks about the purpose of the new HD Photo format:

We've very specifically targeted printing with support for CMYK and n-Channel pixel formats.  In fact, Windows Media Photo is the preferred image format for XML Paper Specification (XPS), the new printer spool file and portable document format being launched with Windows Vista.  Windows Media Photo is also designed to be a great web image format, with support for excellent compression, alpha channels, region decode, progressive decode and high performance compressed domain operations.  Of course, any data format for the web requires very broad support from a variety of client and server components.  As a brand new format, it will take a little time for this support to develop for Windows Media Photo.  However, it's already in development for several important "behind the scenes" web tasks from both Microsoft and our partners.

- Bill Crow, Program Manager for Windows Media Photo

In order to get this tutorial and the source-code attached to it working, you will need to run Windows Vista or install .NET Framework 3.0 on your Windows XP or Windows Server 2003 machine. This will give you access to two DLLs that are crucial for the application to do its job.

Splitter Form

Start by creating a new project in Visual Studio 2005 and adding the following as a reference: PresentationCore and WindowsBase. You'll need a little help in adding these, so here it goes: in the Add Reference window, go to the Browse tab and navigate to C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\ - there you will see PresentationCore.dll which you need to add as a reference. The next DLL you need to add as a reference is in the same path - C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\ - and its name is WindowsBase.dll

Add Reference

Now that you added the PresentationCore.dll and WindowsBase.dll references to your Visual Studio 2005 Windows Project, don't forget the two extra using statements:


using System.IO;
using System.Windows.Media.Imaging;


On the form add a button named btnConvert, an OpenFileDialog openPicture and a SaveFileDialog saveWdp. Now double-click btnConvert and you'll get to its click event. Inside it we will open the proper dialogs:


private void btnConvert_Click(object sender, EventArgs e)

{

    // Prompt to open the file

    if (openPicture.ShowDialog() == DialogResult.OK)

    {

        // Prompt to save the file

        if (saveWdp.ShowDialog() == DialogResult.OK)

        {

            // Call the method that does all the work

            FileToWmp(openPicture.FileName, saveWdp.FileName);

        }

    }

}


Obviously, next comes the FileToWmp() method:


public static void FileToWmp(string inFile, string outFile)

{

    // Container for bitmap frames

    BitmapDecoder bdFile = null;

    // Read the source file into a FileStream object

    FileStream readFile = File.OpenRead(inFile);

    // Set the BitmapDecoder object from the source file

    bdFile = BitmapDecoder.Create(readFile, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);

    // Prepare the output file

    FileStream writeFile = File.OpenWrite(outFile);

    // All the magic done by WmpBitmapEncoder

    WmpBitmapEncoder wbeFile = new WmpBitmapEncoder();

    // Set the quality level to... pretty good

    wbeFile.ImageQualityLevel = 0.9f;

    // Add the bitmap frame to the encoder object

    wbeFile.Frames.Add(bdFile.Frames[0]);

    // Write the output file

    wbeFile.Save(writeFile);

    writeFile.Close();

    readFile.Close();

}


Believe or not, that's all you need to convert pretty much every popular file format - such as JPEG, GIF and PNG - to the brand new HD Photo format. And in most cases it will reduce the file size by over 50% too.
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by Stelabouras on Sunday, August 5th 2007 at 06:14 AM

Attached project zip file seems corrupted :(

by Andrei Pociu on Sunday, August 5th 2007 at 11:03 AM

Try downloading it again. I verified the ZIP and it worked.

by Gotencs on Sunday, October 4th 2009 at 05:39 AM

this works on windows 7...please tell me??

by gullu on Friday, October 30th 2009 at 09:35 AM

superb

by gullu on Friday, October 30th 2009 at 09:35 AM

superb

by Hadron on Sunday, February 21st 2010 at 10:41 PM

I follow the instruction but it
every time I convert, it seems to
direct printing option. Can you help me?
thanks

by P on Tuesday, August 10th 2010 at 12:06 PM

i am a total noob. cannot, for life of me find the .uckin! add ref. window. HELP!

by P on Tuesday, August 10th 2010 at 02:17 PM

where do the two using states go!"not in words" any visuals? this sucks!? .uck!

by P on Tuesday, August 10th 2010 at 02:22 PM

lost... this program sucks. what do you have to do get hd!? .uck!


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs C# Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia

Other Resources