现在的位置: 首页 > 综合 > 正文

asp.net图片处理

2014年02月10日 ⁄ 综合 ⁄ 共 1150字 ⁄ 字号 评论关闭
   /// <summary>
    
/// 获取100*100缩略图像(不存在则返回默认图像,或者null)
    
/// </summary>
    
/// <param name="fileName">图片文件名</param>
    
/// <returns></returns>

    public static Bitmap getMicroImage(string fileName)
    
{
        Bitmap bmp 
= getImage(fileName);
        bmp 
= ResizeImage(bmp, 100100);

        
return bmp;
    }


    
/// <summary>
    
/// Resize图片(不成功返回null)
    
/// </summary>
    
/// <param name="bmp">原始Bitmap</param>
    
/// <param name="newW">新的宽度</param>
    
/// <param name="newH">新的高度</param>
    
/// <returns>处理以后的图片</returns>

    public static Bitmap ResizeImage(Bitmap bmp, int newW, int newH)
    
{
        
try
        
{
            
if (bmp.Width == newW && bmp.Height == newH)
                
return bmp;

            Bitmap b 
= new Bitmap(newW, newH);
            Graphics g 
= Graphics.FromImage(b);

            
// 插值算法的质量
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(bmp, 
new Rectangle(00, newW, newH), new Rectangle(00, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
            g.Dispose();

            
return b;
        }

        
catch
        
{
            
return null;
        }

    }
 

 

抱歉!评论已关闭.