c# - 从 varbinary 数据转换的图像显示空白图像如下图 1 所示

标签 c# sql asp.net-mvc

这是显示转换后图像的页面 This is the Page which displays the converted image.

这是我的二进制图像数据 ScreenPic 表的数据 this is the data of my table for binary image data ScreenPic.

请帮忙... 让我知道从数据库中获取图像有什么问题。
将二进制转换为图像逻辑的代码。:

namespace OverHR.Common
{
    public class Common
    {
        public static Image byteArrayToImage(byte[] ba)
        {
            MemoryStream ms = new MemoryStream(ba);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }


    }
}

显示数据库图片的代码:

@model List<OverHR.DAL.ScreenLog>

<table class="table table-striped">
    <tr>
        <th>Pic</th>

    </tr>

    <tbody>
        @foreach (var item in Model)
        {           
            var image=@item.ScreenPic;

            <tr>
                <td>
                    <img src="@OverHR.Common.Common.byteArrayToImage(image.ToArray())" width="320" height="240">
                </td>       
            </tr>
        }
    </tbody>
</table>

从数据库中获取图片的逻辑:

public List<ScreenLog> GetScreen()
{
    using (OverSeasHRDbDataContext ctx1 = new OverSeasHRDbDataContext())
    {
        var lstScr = ctx1.ScreenLogs.Where(p => p.AttendanceId == 193).ToList();
        return lstScr;
    }
}

最佳答案

我已经搜索过了,我找到了解决方案,因为数据库表中有很多图像,通过查询获取它需要很长时间,所以图像无法从数据库中获取数据并超时,所以对于我使用的解决方案linq 查询只获取 10 张图像,它对我有用....

关于c# - 从 varbinary 数据转换的图像显示空白图像如下图 1 所示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38717949/

相关文章:

MVC3 中的 Javascript 处理

c# - 在 C# 中的字符串中添加换行符

c# - Unity3D 从磁盘流式传输音频文件

sql - 使用标识而不是顺序时的随机数

asp.net-mvc - 为什么 Razor 添加另一个 value 属性以及如何删除它?

ASP.NET Web API 私有(private) Controller

c# - 更新 Entity Framework 中的计算列

c# - XML 占据一个元素的位置,下次使用时直接去那里

SQL Management Studio 2008 R2 双显示器支持吗?

mysql - 如何在 SQL 中对时间(在 AM/PM 中)进行排序?