Efficient acquisition of images of different formats

Source: Internet
Author: User
Recently practiced? A Weibo item ?? View, see the figure of Sina Weibo? What is the basis of the image? Slice? Big? Xiaojin? Row preview area? Big? Small settings, if fixed area? Big? Sometimes it will cause a graph? Film deformation? Ratio

Ugly. Google for a long time ,? The answer has never been found. If it is a graph? Slice? Big? Small corresponds separately? If a group of data is returned in the JSON data of Weibo, it can be well solved, but Weibo has not provided such a response? Port. Then I? Also, do you want to request such a request command directly? Slice? Big? Small, so can I? After loading a graph? Can a slice know the image? Slice? Big? Small. Unfortunately, this command was not found.

Later I thought from the original? How do I start to explore? Film is? File ,? Is there a file? File Header ,? Average? File Header? In? All faces? File? Some common information may also include graphs? Slice? Big? Small. So when I request data? One request? Is the data in the file header more accurate? Film? Big? If the data of the corresponding field is small, the entire package may only need a few bytes to get the graph? Slice? Big? Small, with a picture? Film? Big? Small, we can set the preview area? Big? Small. But what else? A question, figure? Slice has many formats, so? Is the file header definitely not? The same. No way to do this? Is it based on the suffix of the URL request? Rows. I tested it later, Weibo? The main formats are jpg and GIF? The PNG format is used. In this demo, I will analyze the three typical images? Slice format. ? First, for the three formats ,? Can anyone use Baidu? A more detailed introduction of the format, when there are a lot of content we do not need, this? As long as we know the graph? Film? Big? The location of the small data segment is acceptable.

I will not describe the specific format of the information here, Baidu is very easy to find. Of course, the JPG format is a bit complicated, because when I was testing the image? Film? Big? The location of a small field is not fixed? What is the problem? See the analysis in the demo. PNG analysis, PNG format chart? Film? Big? The small field is between 16 and 23, so the request only needs 8 bytes (isn't it? Small)

!

{

Nsstring * urlstring = @ "http://img2.3lian.com/

Img2007/13/29/20080409094710646.png ";

Nsmutableurlrequest * request = [[nsmutableurlrequest alloc] initwithurl:

[Nsurl urlwithstring: urlstring];

[Request setvalue: @ "bytes = 16-23" forhttpheaderfield: @ "range"];

[[Nsurlconnection connectionwithrequest: Request delegate: Self] Start];

}

!

Corresponding to each? What do I need to do for a single person? Rows are converted to get specific values.

!

{

Int W1 = 0, W2 = 0, W3 = 0, W4 = 0;

[Data getbytes: & W1 range: nsmakerange (0, 1)]; [data getbytes: & W2 range: nsmakerange (1, 1)]; [data getbytes: & W3 range: nsmakerange (2, 1)]; [data getbytes: & W4 range: nsmakerange (3, 1)];

Int W = (W1 <24) + (W2 <16) + (W3 <8) + W4;

Int H1 = 0, H2 = 0, h3 = 0, h4 = 0;

[Data getbytes: & H1 range: nsmakerange (4, 1)]; [data getbytes: & H2 range: nsmakerange (5, 1)]; [data getbytes: & H3 range: nsmakerange (6, 1)]; [data getbytes: & H4 range: nsmakerange (7, 1)];

Int H = (H1 <24) + (H2 <16) + (H3 <8) + H4;

Return cgsizemake (W, H );

}

Format? Because it is complex, you must first understand the meaning of specific fields? Film? Big? The region where the small field is located is uncertain, so we need to expand? Large request range

This? 209 bytes? In? It should already contain all the data (which? I checked? I also read some information? How many different JPG files? File Header hexadecimal Information)

No? It must be completely correct, but what is the jpg image of Weibo? Film? Big? I have no problem copying the code.

{

}

-(Void) downloadjpgimage

Nsstring * urlstring = @ "http://ww3.sinaimg.cn/thumbnail/

673c0421da-1e9a6au7h5kj21820.rsn23.jpg ";

Nsmutableurlrequest * request = [[nsmutableurlrequest alloc] initwithurl:

[Nsurl urlwithstring: urlstring];

[Request setvalue: @ "bytes = 0-209" forhttpheaderfield: @ "range"]; [[nsurlconnection connectionwithrequest: Request delegate: Self] Start];

!

-(Cgsize) jpgimagesizewithheaderdata :( nsdata *) Data {

If ([Data Length] <= 0x58) {return cgsizezero;

}
If ([Data Length] <210) {// certainly only? A dqt Field

Short W1 = 0, W2 = 0;
[Data getbytes: & W1 range: nsmakerange (0x60, 0x1)]; [data getbytes: & W2 range: nsmakerange (0x61, 0x1)];

Short W = (W1 <8) + W2;
Short H1 = 0, H2 = 0;
[Data getbytes: & H1 range: nsmakerange (0x5e, 0x1)]; [data getbytes: & H2 range: nsmakerange (0x5f, 0x1)]; short H = (H1 <8) + H2;
Return cgsizemake (W, H );

} Else {
Short word = 0x0;
[Data getbytes: & Word range: nsmakerange (0x15, 0x1)]; If (WORD = 0xdb ){

[Data getbytes: & Word range: nsmakerange (0x5a, 0x1)]; If (WORD = 0xdb) {// two dqt Fields

Short W1 = 0, W2 = 0;
[Data getbytes: & W1 range: nsmakerange (0xa5, 0x1)]; [data getbytes: & W2 range: nsmakerange (0xa6, 0x1)]; short W = (W1 <8) + W2;
Short H1 = 0, H2 = 0;
[Data getbytes: & H1 range: nsmakerange (0xa3, 0x1)]; [data getbytes: & H2 range: nsmakerange (0xa4, 0x1)]; short H = (H1 <8) + H2;
Return cgsizemake (W, H );

} Else {//? A dqt Field
Short W1 = 0, W2 = 0;
[Data getbytes: & W1 range: nsmakerange (0x60, 0x1)]; [data getbytes: & W2 range: nsmakerange (0x61, 0x1)]; short W = (W1 <8) + W2;
Short H1 = 0, H2 = 0;
[Data getbytes: & H1 range: nsmakerange (0x5e, 0x1)]; [data getbytes: & H2 range: nsmakerange (0x5f, 0x1)]; short H = (H1 <8) + H2;
Return cgsizemake (W, H );

}
} Else {

Return cgsizezero ;}

}

} The GIF analysis is similar to that of PNG? Is it the first? A picture? Slice? Big? Small

-(Void) downloadgifimage

{

Nsstring * urlstring = @ "http://img4.21tx.com/2009/1116/92/20392.gif ";

Nsmutableurlrequest * request = [[nsmutableurlrequest alloc] initwithurl:

[Nsurl urlwithstring: urlstring];

[Request setvalue: @ "bytes = 6-9" forhttpheaderfield: @ "range"];

[[Nsurlconnection connectionwithrequest: Request delegate: Self] Start];

}

!

-(Cgsize) gifimagesizewithheaderdata :( nsdata *) data

{

Short W1 = 0, W2 = 0;

[Data getbytes: & W1 range: nsmakerange (0, 1)]; [data getbytes: & W2 range: nsmakerange (1, 1)];

Short W = W1 + (W2 <8 );

Short H1 = 0, H2 = 0;

[Data getbytes: & H1 range: nsmakerange (2, 1)]; [data getbytes: & H2 range: nsmakerange (3, 1)];

Short H = H1 + (H2 <8 );

Return cgsizemake (W, H );

}

!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.