注意:轉換為ICO後效果不好
源代碼:
using System;
using System
using System
using System
using System
using System
namespace paomiangege
{
public class ImageConvert
{
private int ICON_W =
private int ICON_H =
public ImageConvert()
{
}
//fileinpath
public string Convert(string fileinpath
{
try
{
Bitmap bitmap = new Bitmap(fileinpath);
index = index
switch (index)
{
case
case
case
case
case
case
case
case
case
{
Stream stream = File
bitmap
stream
} break;
case
{
Icon ico;
Stream stream = File
ico = BitmapToIcon(bitmap
ico
stream
}; break;
default: return
}
return
}
catch(Exception ex)
{
return ex
}
}
public string Convert(string fileinpath
{
if (width <=
return
try
{
Bitmap mybitmap = new Bitmap(fileinpath);
Bitmap bitmap = new Bitmap(mybitmap
index = index
switch (index)
{
case
case
case
case
case
case
case
case
case
{
Stream stream = File
bitmap
stream
} break;
case
{
if (height >
return
Icon ico;
ICON_H = height;
ICON_W = width;
Stream stream = File
ico = BitmapToIcon(mybitmap
ico
stream
}; break;
default: return
}
return
}
catch (Exception ex)
{
return ex
}
}
private Icon BitmapToIcon(Bitmap obm
{
Bitmap bm;
// if not preserving aspect
if (!preserve) // if not preserving aspect
bm = new Bitmap(obm
// if preserving aspect drop excess significance in least significant direction
else // if preserving aspect
{
Rectangle rc = new Rectangle(
if (obm
{ // rescale with width based on max icon height
bm = new Bitmap(obm
rc
if (rc
}
else // if height least significant
{ // rescale with height based on max icon width
bm = new Bitmap(obm
rc
if (rc
}
bm = bm
}
// create icon from bitmap
Icon icon = Icon
bm
return icon; // return icon
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12504.html