如何在c#.net windows应用程序中将图像从数据库检索到ListView? [英] How to Retrieve images from database to ListView in c# .net windows application?

查看:65
本文介绍了如何在c#.net windows应用程序中将图像从数据库检索到ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



C#.net Windows应用程序中的ListView中没有显示图像。



列表视图中只显示 System.Byte []



Hello,

There is not displaying images in ListView in C# .net Windows Application.

There is only displaying System.Byte[] in listview.

            DataTable dt = obj.GetFloorTileName(CmbFloorTiles.Text);
            listFloorTiles.Items.Clear();
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                DataRow drow = dt.Rows[i];
                
//This is a Image field (draw["FloorTexture"].ToString());
//My Image field dataType is Image in sql server.

                ListViewItem lvi = new ListViewItem(drow["FloorTexture1"].ToString());
                lvi.SubItems.Add(drow["FloorTileName"].ToString());
                listFloorTiles.Items.Add(lvi);
            }



请帮帮我,如何以列表格式从数据库检索图像到listview控件。



谢谢。



Ankit Agarwal

软件工程师


Please help me, How can we retrieve images from database to listview control in list format.

Thanks.

Ankit Agarwal
Software Engineer

推荐答案

尝试

http://www.youtube.com/watch?v=LxeM010HLJI [ ^ ]

< a href =http://www.codeproject.com/Questions/177747/Show-Image-in-Listview-retrieve-from-database-in-A>在Listview中显示图像从ASP.net中的数据库中检索 [ ^ ]


尝试以下代码



Try below code

byte[] bytes = (byte[])draw["FloorTexture"];
            string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
            Image1.ImageUrl = "data:image/png;base64," + base64String;





您还可以使用Generic处理程序来显示图像

http://forums.asp.net/t/1372698.aspx [ ^ ]


public byte[] ImageAArray(System.Drawing.Image imagen)
{
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    imagen.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
    return ms.ToArray();
}
public System.Drawing.Image ArrayAImage(byte[] ArrBite)
{
    System.IO.MemoryStream ms = new System.IO.MemoryStream(ArrBite);
    System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
    return returnImage;
}

lvImagenes.Clear();//List View
System.Collections.ArrayList pics = PicturesBO.GetPics();//Get Images DB
ImageList imgList = new ImageList();//Image List
imgList.ImageSize = new Size(120, 120);
foreach (IMAGESDB i in pics)// Entity IMAGEDB (SQL Server Type IMAGE, C# type byte[])
{
    System.Drawing.Image img = ArrayAImage(i.IMAGEFILE);
    imgList.Images.Add(img);
}
lvImagenes.View = View.LargeIcon;
lvImagenes.LargeImageList = imgList;
for (int j = 0; j < imgList.Images.Count; j++)
{
    ListViewItem item = new ListViewItem();
    item.ImageIndex = j;
    lvImagenes.Items.Add(item);
}


这篇关于如何在c#.net windows应用程序中将图像从数据库检索到ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆