如何将图像二进制转换为图像文件(图像缩略图API) [英] How to convert image binary to image file (Image Thumbnail API)

查看:89
本文介绍了如何将图像二进制转换为图像文件(图像缩略图API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Project Oxford缩略图API的示例代码为我的图像创建缩略图。输出是一大块图像二进制代码。如何将此二进制文件转换为实际的图像文件?在此先感谢!

解决方案

如果得到的结果是二进制结果,则可以使用下面的代码。 BinaryWriter类应该将参考System.IO命名空间添加到项目中。


resultFolder是您要将缩略图保存到的文件夹。


thumbnailResult是二进制文件你从响应中得到。

 //将结果写入本地文件
string filePath = string.Format(" {0} \\ thumbnailResult_ {1} .jpg",resultFolder,DateTime.UtcNow.Ticks.ToString());

使用(BinaryWriter binaryWrite = new BinaryWriter(new FileStream(filePath,FileMode.Create,FileAccess.Write)))
{
binaryWrite.Write(thumbnailResult);
}






I used the sample code for the Project Oxford thumbnail API to create a thumbnail for my image. The output was a huge chunk of image binary code. How do I convert this binary into an actual image file? Thanks in advance!

解决方案

If you get the result is binary result, you can use below code. BinaryWriter class should add reference System.IO namespace into project.

resultFolder is the folder you want to save the thumbnail to.

thumbnailResult is the binary you get from the response.

            // Write the result to local file
            string filePath = string.Format("{0}\\thumbnailResult_{1}.jpg", resultFolder, DateTime.UtcNow.Ticks.ToString());

            using (BinaryWriter binaryWrite = new BinaryWriter(new FileStream(filePath, FileMode.Create, FileAccess.Write)))
            {
                binaryWrite.Write(thumbnailResult);
            }




这篇关于如何将图像二进制转换为图像文件(图像缩略图API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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