Flex Compressed picture Exif information (author/camera) lost problem resolution _flex

Source: Internet
Author: User
In the use of Flex Jpegencoder image compression, EXIF information will be lost, that is, the picture of the author, with the camera, God horse, all have no, how to do?

After studying the JPEG document, the final solution to this problem
1.jpeg file format, divided into a frame, each frame with a 0xFF start, followed by a logo not, such as 0xffd8 to represent the beginning of the file, 0xffd9 indicates the end of the file, followed by the identity of the length of the frame, the length does not include 0xFF and identity bit , but includes the length of this 2 byte, such as a frame started, first a 0xFF then a 0xXX, then two 0x0010, indicating that the frame length is 16, the length of the frame is actually 18,

2. We want to study is the image of EXIF information, his identification bit is 0XE1
And this 0xe1 has two kinds of situation, the first kind, is follows the file head, is 0xe1, the second kind, is before 0xe1 also has a 0xe0,
So before you take this bytearray to a picture object, you get all the data for this 0xe1 frame, and the code reads as follows:
Copy Code code as follows:

Get 0xffe1 App1 that is EXIF information
var tempdata:bytearray = new ByteArray ();
The e.target.data here is the original bytearray of the picture
Tempdata.writebytes (e.target.data,0,e.target.data.bytesavailable);
Tempdata.position = 3; Read Fourth Byte
var exif:number = Tempdata.readunsignedbyte ();
if (exif = = 0xe1) {//See this byte is not 0xe1
This. Debug ("Have EXIF information");
Read a length
var exiflength:number = Tempdata.readunsignedshort ();
File_item.exifArray.writeBytes (tempdata,tempdata.position-2,exiflength); If yes, the EXIF information is read into a file object
else if (exif = = 0xe0) {//Is E0, then skip this frame and look below
Tempdata.position = 4;
var e0length:number = Tempdata.readunsignedshort ();
Tempdata.position = 4+e0length;//Skip E0
Tempdata.position + + 1;//Skip 0xFF
var isex:number = Tempdata.readunsignedbyte ();
if (isex==0xe1) {
var len:number = Tempdata.readunsignedshort ();
File_item.exifArray.writeBytes (Tempdata,tempdata.position-2,len);
}
}

And then we're done with this, and we need to plug this frame into the compressed bytearray.
The logic of the code should be at a glance, hehe
Copy Code code as follows:

if (file_item.exifarray.length>0) {//write EXIF information
var Desdata:bytearray = new ByteArray ();
Desdata.writebytes (olddata,0,2);//0xffd8
Desdata.writebyte (0xff);
Desdata.writebyte (0XE1);
Desdata.writebytes (file_item.exifarray,0,file_item.exifarray.bytesavailable);
Desdata.writebytes (olddata,2,olddata.bytesavailable);
Desdata.position = 0;
This.uploadfiletest (Desdata,file_item);
} else {
This.uploadfiletest (e.target.ba,file_item);
}

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.