本文介绍了当从asp.net中的数据库中检索图标图像以在树视图中显示时,图标图像宽度是如此之大。那么,如何减少图标图像的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从asp.net中的数据库中检索图标图像以在树视图中显示leftside时,图标图像显示得如此之大。那么,如何减少图标图像的宽度?
while retrieving icon image from database in asp.net to show leftside in treeview , the icon image is showing so large . so, how to reduce width of icon image?
推荐答案
public static Bitmap CreateThumbnail(Bitmap source, int thumbWidth, int thumbHeight, bool maintainAspect)
{
if (source.Width < thumbWidth && source.Height < thumbHeight) return source;
Bitmap image = null;
try
{
int width = thumbWidth;
int height = thumbHeight;
if (maintainAspect)
{
if (source.Width > source.Height)
{
width = thumbWidth;
height = (int)(source.Height * ((decimal)thumbWidth / source.Width));
}
else
{
height = thumbHeight;
width = (int)(source.Width * ((decimal)thumbHeight / source.Height));
}
}
image = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(image))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.White, 0, 0, width, height);
g.DrawImage(source, 0, 0, width, height);
}
return image;
}
catch
{
image = null;
}
finally
{
if (image != null)
{
image.Dispose();
}
}
return null;
}
这篇关于当从asp.net中的数据库中检索图标图像以在树视图中显示时,图标图像宽度是如此之大。那么,如何减少图标图像的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!