ASP.NET 展示多数据库byte[]图片
ASP.NET 显示多数据库byte[]图片
图片都存在数据库中,取出的都是byte[]格式。
显示单个图片,网上查资料是:
建一个新网站xxx,后台窗体加载写 Response.BinaryWrite((byte[])img);
然后可以直接调用 this.Image1.ImageUrl = "xxx.aspx";
现在问一下,假如要显示多图片怎么办?有更好的额解决方案吗?不会是每张图片的获取都要走 一遍xxx.aspx页面吧,求教。
------解决方案--------------------
有种做法是合并图片
/// <summary>
/// 合并图片
/// </summary>
/// <param name="maps">图片集</param>
/// <param name="RepeatDirection">合并方向</param>
/// <returns></returns>
public static Bitmap MergerImg(Bitmap[] maps, System.Web.UI.WebControls.RepeatDirection RepeatDirection)
{
if (maps.Length == 0)
throw new Exception("图片数不能够为0");
int _width = 0;
int _height = 0;
for (int i = 0; i < maps.Length; i++)
{
if (RepeatDirection == System.Web.UI.WebControls.RepeatDirection.Horizontal)
{
_width += maps[i].Width;
if (maps[i].Height > _height)
{
_height = maps[i].Height;
}
}
else
{
_height += maps[i].Height;
if (maps[i].Width > _width)
{
_width = maps[i].Width;
}
}
}
//创建要显示的图片对象,根据参数的个数设置宽度
Bitmap backgroudImg = new Bitmap(_width, _height);
Graphics g = Graphics.FromImage(backgroudImg);
//清除画布,背景设置为白色
int len = maps.Length;
g.Clear(System.Drawing.Color.White);
int x = 0;
for (int j = 0; j < len; j++)
{
图片都存在数据库中,取出的都是byte[]格式。
显示单个图片,网上查资料是:
建一个新网站xxx,后台窗体加载写 Response.BinaryWrite((byte[])img);
然后可以直接调用 this.Image1.ImageUrl = "xxx.aspx";
现在问一下,假如要显示多图片怎么办?有更好的额解决方案吗?不会是每张图片的获取都要走 一遍xxx.aspx页面吧,求教。
------解决方案--------------------
有种做法是合并图片
/// <summary>
/// 合并图片
/// </summary>
/// <param name="maps">图片集</param>
/// <param name="RepeatDirection">合并方向</param>
/// <returns></returns>
public static Bitmap MergerImg(Bitmap[] maps, System.Web.UI.WebControls.RepeatDirection RepeatDirection)
{
if (maps.Length == 0)
throw new Exception("图片数不能够为0");
int _width = 0;
int _height = 0;
for (int i = 0; i < maps.Length; i++)
{
if (RepeatDirection == System.Web.UI.WebControls.RepeatDirection.Horizontal)
{
_width += maps[i].Width;
if (maps[i].Height > _height)
{
_height = maps[i].Height;
}
}
else
{
_height += maps[i].Height;
if (maps[i].Width > _width)
{
_width = maps[i].Width;
}
}
}
//创建要显示的图片对象,根据参数的个数设置宽度
Bitmap backgroudImg = new Bitmap(_width, _height);
Graphics g = Graphics.FromImage(backgroudImg);
//清除画布,背景设置为白色
int len = maps.Length;
g.Clear(System.Drawing.Color.White);
int x = 0;
for (int j = 0; j < len; j++)
{