|
|
|
|
|
|
|
Page Views :
|
21264
|
|
Downloads :
|
0
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
First off, why use PNG instead of GIF? Probably the most important reason is that GIF supports a maximum of 256 colors. The second reason is Unisys has a lockdown on the rights to LZW compression which the GIF format can, and usually does use. PNG overcomes the color depth hurdle by providing up to 48Bpp (bits per pixel). Just as importantly, the PNG format is patent-free and available for use by anyone.
PNG has other advantages over GIF as well:
- Alpha Channels: GIF supports binary transparency, that is a pixel can either be opaque or transparent. PNG allows full variable transparency with 254 levels of partial transparency. I should also say that it is also possible to obtain 65,534 levels of transparency, but that is out scope for web graphics.
- Gamma Correction: This allows authors the ability to correct the differences in an image that arrise from being viewed by different monitors. Most notibly is the difference between PC and Macintosh.
- Two Dimensional Interlacing: Also known as Progressive Scan. While GIF does support this, PNG allows a better representation of the image to displayed as the data is transfered.
So we know PNG offers us plenty of features and flexibility, but how do we use that? It just so happens GDI+ supports PNG, but there are a few extra steps involved in using it.
Let's start by creating a Bitmap and Graphics object, and filling it with red:
Bitmap myBitmap = new Bitmap( 100, 100 ); Graphics myGraphics = Graphics.FromImage( myBitmap ); myGraphics.Clear( Color.Red );
This gives us a simple 100x100 red Bitmap. Now lets focus on saving this as a PNG file. You might think, hey I can just do
myBitmap.Save( "image.png", ImageFormat.Png );
Obviously this is how you save most other image types with GDI. However PNG is a special exception. It requires a seekable stream, such as that offered by System.IO.FileStream. Let's take a look:
FileStream myFileOut = new FileStream( "image.png", FileMode.Create ); myBitmap.Save( myFileOut, ImageFormat.Png ); myFileOut.Close();
As you can see, we merely needed to create a file stream and pass that to the Bitmap Save method.
Stay tuned for part 2 where I discuss how to use those neat features I mentioned in the beginning of the article.
For more information on these topics:
Portable Network Graphic Format
Introduction to GDI+
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|
|