使用HTTP请求仅下载JPG的一部分 [英] Download Only A Part of a JPG with HTTP request

查看:105
本文介绍了使用HTTP请求仅下载JPG的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用HTTP标头Range,客户端只能从服务器请求一定范围的字节.

With the HTTP header Range clients can request only a certain range of bytes from a server.

GET myfile.jpg HTTP/1.1
"http://myhost"
Range=bytes=1000-1200

如果服务器支持此响应功能,甚至可能通过Accept-Range标头显示该信息,则上述请求将仅从字节1000开始返回200字节.

If the server supports this response feature and maybe even shows that by a Accept-Range header, the above request will return only the 200 bytes from byte 1000 onwards.

是否可以通过这种方法从JPG图像中获得可用的零件?假设实际的JPG尺寸为800x1197像素.为了只请求200x200和400x400像素之间的子图像,该怎么办?

Is it possible to get usable parts from an JPG image with this method? Say the actual JPG measures 800x1197 pixels. What would have to be done in order to request only a sub image between the pixels 200x200 and 400x400?

对我来说,似乎只能接收水平切割的图像切片.但这已经比获取完整的图像文件更好.因此,在上面的示例中,我想说可以尝试下载:将切片从200(y轴)扩展到400(y轴),然后在客户端相应地裁剪结果.

To me it looks like it's only possible receive horizontally cut slices of the image. But this would already be better than getting the full image file. So in the example above I'd say one could try to download: the slice from 200 (y-axis) to 400 (y-axis) and then crop the result on the client side accordingly.

假设我们已经知道文件的内容长度及其实际图像大小,这可能是由先前的HTTP请求确定的:

Assume we already know the content-length of the file as well as its actual image size, which may have been determined by a preceding HTTP request:

内容长度(以字节为单位):88073 jpg尺寸:800x1197

content length in bytes: 88073 jpg size: 800x1197

该图像我需要请求哪个字节范围?我认为JPG具有一些元数据,也必须考虑这些元数据.还是压缩jpg会使这种尝试变得不可能?如果最终剪切出的片段中不包含原始的任何元数据,那没关系.

Which byte range would I have to request for this image? I assume that JPG has some meta data, which has to be taken in account as well. Or does the compression of jpg render this attempt impossible? It would be ok if the final cut out does not contain any metadata from the original.

但是仍然可能有一个初始请求,该请求从开始就占用了一些字节,以希望获取元数据.并以此为基础确定实际的字节范围.

But still it might be necessary to have an initial request, which takes some bytes from the beginning hoping to fetch the metadata. and based on this the actual byte range might be determined.

如果有人可以给我提示如何解决这个问题,那将非常好.

Would be very nice if someone could give me a hint how to approach this.

推荐答案

JPEG在一次或多次扫描中对压缩数据进行编码.扫描不指示其长度.您必须实际解码才能结束扫描.扫描将扫描整个图像.

JPEG encodes compressed data in one or more scans. The scans do not indicate their length. You have to actually decode to get to the end of the scan. The scans span the entire image.

如果JPEG流是渐进编码的,则您可以一次读取流块,解码扫描,更新输出图像并获得图像的连续细化视图.

If the JPEG stream is progressively encoded you can read the stream blocks at at a time, decode the scans, update the output image, and get successively refined views of the image.

这篇关于使用HTTP请求仅下载JPG的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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