使用.Net C#压缩一个字节数组图像,无需缩放 [英] Compress a Byte Array Image without Scaling using .Net C#

查看:920
本文介绍了使用.Net C#压缩一个字节数组图像,无需缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个AngularJS应用程序,为服务我使用.NET C#编码的目的。我从SQL Server检索图像作为字节数组,我发送字节数组到AngularJS,它显示在HTML中的图像。

I'm building an AngularJS Application, for Service I'm using .NET C# for coding purpose. I'm retrieving Images from SQL Server as Byte Array and I'm sending the Byte Array to AngularJS and it displays the Image in the HTML.

我遵循相同的喜欢在后从C#字节数组加载图像并使用AngularJS将图像放在html标签中

I followed the same as like in the post Load image from C# Byte array and place image in html tag using AngularJS

但我面临着我的数据中的性能问题。我的数据库包含的字节数组大小约为。 2至3 MB。所以,基于互联网带宽它努力加载。 因此,请帮助我如何压缩字节数组而不缩放图片?

But I'm facing the performance issue in my data. My database contains the byte array size is approx. 2 to 3 MB. So, based on Internet Bandwidth its struggling to load. So, kindly assist me how to compress the Byte Array without Scaling the Image ?

我在网上搜索了很多,但是他们压缩的每个帖子在缩放图像方面。但是我需要压缩字节数组而不缩放。

I searched a lot in web, but every post they compressed in terms of Scaling the Image. But I need to compress the Byte Array without Scaling.

推荐答案

如果你使用一些标准的图像格式,如 jpeg png 您的图片已经压缩,没有太多可以减少他们的大小,除非你缩小它们。

If you are using some of the standard image formats such as jpeg or png your images are already compressed and there's not much you could do in order to reduce their size further unless of course you scale them down.

这就是说,在您链接到的文章中,图像似乎是通过 Base64 字符串导致一个可怕的开销,因为它膨胀他们的大小。而图像越大,开销越大,如果你Base64他们。所以如果你遵循本文中的建议,你不应该有。相反,您应该将来自服务器的图像作为原始字节流入响应正文,而不使用任何Base64编码。然后只需使用标准的< img> 标签,其中 src 属性直接指向您的服务器url。所以基本上在你的Angular应用程序中,你的模型不应该包含多个base64字符串,你下载为AJAX请求,而是一个url数组,将被分配给相应的图像标签src属性。

This being said, in the article you have linked to, the images seem to be sent over the wire from the server as Base64 strings which incurs a terrible overhead as it bloats their size. And the bigger the images, the bigger the overhead if you Base64 them. So if you have followed the advice in this article you shouldn't have. Instead you should stream the images from your server as raw bytes in the response body and don't use any Base64 encoding. Then simply use standard <img> tags whose src property is directly pointing to your server url. So basically in your Angular application your model should not consist of multiple base64 strings which you downloaded as AJAX requests, but rather an array of urls which will be assigned to the corresponding image tags src property.

这篇关于使用.Net C#压缩一个字节数组图像,无需缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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