Eng*_*uad 8 java android image image-loading whatsapp
WhatsApp开发人员最近改进了图像加载,其中立即加载图像的某些部分(获取其尺寸和图像的一些像素),然后在加载整个图像后,用完整图像替换占位符:

我的问题是,他们是如何实现的?他们是通过读取标题(元数据)来读取图像的维度吗?图像内容怎么样?或者他们在服务器端有两个版本的图像,一个较小的图像是先加载的还是一个较大的一个是完整的图像?请注意,如果它是第二种方法,那么一旦从发送方接收图像,它们仍然需要在服务器端提取较小版本的图像.还有其他方法吗?
经过多次实验,我在没有下载整个图像的情况下获得了尺寸:
String address = "image_url";
URL url = new URL(address);
URLConnection urlC = url.openConnection();
urlC.connect();
InputStream is = urlC.getInputStream();
for(int i = 0; i < 92; i++) is.read();
nt byte1 = is.read();
int byte2 = is.read();
int width = (byte1 << 8) + byte2;
for(int i = 0; i < 10; i++) is.read();
byte1 = is.read();
byte2 = is.read();
int height = (byte1 << 8) + byte2;
System.out.println("width = " + width + " | height = " + height);
is.close();
Run Code Online (Sandbox Code Playgroud)