Author: techfox9
Converting jpg to png in C# (CSharp) ..
Monday, January 12th, 2009 @ 2:08 am
using System.Drawing; using System.Drawing.Imaging; // apt-get install libgdiplus class CGTest1 { public static void Main() { /* Image bmpImageToConvert = System.Drawing.Image.FromFile( Server.MapPath(strUploadImagePath)); */ Image bmpImageToConvert = Image.FromFile("images/sample3.jpg"); Image bmpNewImage = new Bitmap(bmpImageToConvert.Width, bmpImageToConvert.Height); Graphics gfxNewImage = Graphics.FromImage(bmpNewImage); gfxNewImage.DrawImage(bmpImageToConvert, new Rectangle(0, 0, bmpNewImage.Width, bmpNewImage.Height), 0, 0, bmpImageToConvert. Width,bmpImageToConvert.Height, GraphicsUnit.Pixel); gfxNewImage.Dispose(); bmpImageToConvert.Dispose(); /*bmpNewImage.Save(Server.MapPath("userData/" & Request.QueryString("ID") & "/" & e.Item.Cells(2).Text & ".jpg"),ImageFormat.Jpeg) */ bmpNewImage.Save("images/sample3t.png", ImageFormat.Png); } }
Thanks to :
http://www.codeverge.net/ng.asp-net-forum.getting_started/converting-a-png-or-gif-to-a-jpeg