Note: converted to ICO does not work well.
Source code:
Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Drawing;
Using System. Drawing. Imaging;
Using System. IO;
Namespace paomiangege
{
Public class ImageConvert
{
Private int ICON_W = 64;
Private int ICON_H = 64;
Public ImageConvert ()
{
}
// Fileinpath, origaly picture file path, fileoutpath save filepath, index the ImageFormat you want to convert
Public string Convert (string fileinpath, string fileoutpath, string index)
{
Try
{
Bitmap bitmap = new Bitmap (fileinpath );
Index = index. ToLower ();
Switch (index)
{
Case "jpg": bitmap. Save (fileoutpath, ImageFormat. Jpeg); break;
Case "jpeg": bitmap. Save (fileoutpath, ImageFormat. Jpeg); break;
Case "bmp": bitmap. Save (fileoutpath, ImageFormat. Bmp); break;
Case "png": bitmap. Save (fileoutpath, ImageFormat. Png); break;
Case "emf": bitmap. Save (fileoutpath, ImageFormat. Emf); break;
Case "gif": bitmap. Save (fileoutpath, ImageFormat. Gif); break;
Case "wmf": bitmap. Save (fileoutpath, ImageFormat. Wmf); break;
Case "exif": bitmap. Save (fileoutpath, ImageFormat. Exif); break;
Case "tiff ":
{
Stream stream = File. Create (fileoutpath );
Bitmap. Save (stream, ImageFormat. Tiff );
Stream. Close ();
} Break;
Case "ico ":
{
Icon ico;
Stream stream = File. Create (fileoutpath );
Ico = BitmapToIcon (bitmap, false );
Ico. Save (stream); // save the icon
Stream. Close ();
}; Break;
Default: return "Error! ";
}
Return "Success! ";
}
Catch (Exception ex)
{
Return ex. Message;
}
}
Public string Convert (string fileinpath, string fileoutpath, string index, int width, int height)
{
If (width <= 0 | height <= 0)
Return "error! Size illegal! ";
Try
{
Bitmap mybitmap = new Bitmap (fileinpath );
Bitmap bitmap = new Bitmap (mybitmap, width, height );
Index = index. ToLower ();
Switch (index)
{
Case "jp