Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从JSON编码的二进制数据还原图像_C#_Json_Image_Windows Phone 8_Azure Mobile Services - Fatal编程技术网

C# 从JSON编码的二进制数据还原图像

C# 从JSON编码的二进制数据还原图像,c#,json,image,windows-phone-8,azure-mobile-services,C#,Json,Image,Windows Phone 8,Azure Mobile Services,我正在开发一个通过WindowsAzure移动服务接收数据的WindowsPhone应用程序 我试图从数据库中获取图像,并在应用程序中显示它们。目前,我通过WindowsAzure移动服务API中的嵌入式SQL语句接收图像。这里可以找到一个例子。所有结果都以JSON字符串格式返回 如何将结果中的Image字段的值转换为可以在应用程序中显示的图像 我假设我需要一个图像数组,然后将每个值转换成一个图像,并以这种方式显示图像 如果有任何提示或建议,我将不胜感激。谢谢 编辑: 下面是我用来从SQL数据库

我正在开发一个通过WindowsAzure移动服务接收数据的WindowsPhone应用程序

我试图从数据库中获取图像,并在应用程序中显示它们。目前,我通过WindowsAzure移动服务API中的嵌入式SQL语句接收图像。这里可以找到一个例子。所有结果都以JSON字符串格式返回

如何将结果中的
Image
字段的值转换为可以在应用程序中显示的图像

我假设我需要一个图像数组,然后将每个值转换成一个图像,并以这种方式显示图像

如果有任何提示或建议,我将不胜感激。谢谢

编辑: 下面是我用来从SQL数据库获取结果的API

exports.get = function(request, response) {

if (request.query.phoneID && request.query.phoneName)
{
    response.send("ERROR #1: too many paramaters");
}
else
{
    var sql = "SELECT wptracker.Photos.* " +
              "FROM wptracker.PhonePhotos " +
              "INNER JOIN wptracker.Phones ON PhonePhotos.PhoneID = Phones.id " + 
              "INNER JOIN wptracker.Photos ON PhonePhotos.PhotoID = Photos.id ";

    var params = [];

    if (request.query.phoneName)
    {
        sql += 'WHERE wptracker.Phones.FullName = ?'
        params.push(request.query.phoneName);            
    }
    if (request.query.phoneID)
    {
        sql += 'WHERE wptracker.Phones.ID = ?'
        params.push(request.query.phoneID);            
    }        

    request.service.mssql.query(sql, params,
    {
        success: function (results)
        {
            response.json(statusCodes.OK, results);
        },
        error : function()
            {
                response.send("ERROR 2: query returned no results found.")
            }
    }
    );
}

}

假设您已经查询了表,并且该字段的值位于名为
imageField的变量中

string base64 = Convert.ToBase64String(imageField);
string htmlString="<img src=\"data:image/png;base64,"+base64+"\">";
string base64=Convert.tobase64字符串(imageField);
字符串htmlString=“”;

但是您需要将
png
更改为任何实际格式

图像存储在SQL数据库中的VARBINARY(MAX)列中。然后以JSON字符串格式返回数据,我假设它仍然被视为VARBINARY(MAX)列。您建议我将问题重命名为什么?您的读取操作中有脚本吗?如果是的话,你能把它贴在这里吗?你能确认图像存储在
varbinary(max)
列中吗?azure mobile services中的
mssql
对象使用的从
varbinary
列中检索数据,作为
缓冲区
对象。缓冲区对象没有序列化为字符串(它们有一个奇怪的转换,请参阅)。如果您的数据存储为字符串(nvarchar),它是如何编码的?它们存储在数据库中的列是varbinary(max)。我使用dbforgestudioforsqlserver将图像上传到数据库中。在数据库中存储图像链接并根据链接下载图像会更容易吗?