Click here to Skip to main content
15,922,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,



I my current requirement i need to convert (*.tif,*.png,*.bitmap and *.gif)pictures type while uploading need to convert to JPEG type using the asp.net with C# technologies..



Can any body share the code or links for the subjected matter.


Kindly help on this..


Thanks in advance,
Subbu
Posted

1 solution

You cannot convert them during the upload. You have to let the user upload the image file, then you can try to load it into a Bitmap object and resave the image in a new format.

I'ved used code similar to this to do what you're describing before:
public static class ImageExtensions
{

    public static byte[] ToByteArray(this Bitmap sourceImage, ImageFormat format)
    {
        if (sourceImage == null)
            return null;

        using (MemoryStream targetStream = new MemoryStream())
        {
            sourceImage.Save(targetStream, format);
            targetStream.Close();

            return targetStream.ToArray();
        }
    }

    public static Bitmap ToBitmap(this byte[] bytes)
    {
        if (bytes == null)
            return (Bitmap)null;

        using (MemoryStream targetStream = new MemoryStream(bytes))
        {
            return new Bitmap(targetStream);
        }
    }

}

You can convert a Bitmap to an array of bytes in any image format you want. Then it's a simple matter to convert the array back to a Bitmap.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Dec-13 18:18pm    
Correct, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900