Solve the Problem of exif information (Author/camera) loss in flex Compressed Images

Source: Internet
Author: User

When flex encoder is used to compress an image, the exif information will be lost, that is, the author of The image. The camera and Shenma will all be lost. What should I do?

After studying jpeg documents, we finally solve this problem.
1.jpeg file format, divided into one frame, each frame starts with 0xFF, followed by a non-logo, for example, 0xFFD8 indicates the start of the file, 0xFFD9 indicates the end of the file, the marker is the length of the frame. The length does not include 0xFF and the marker, but includes the length of the two bytes. For example, if a frame starts, it is a 0xFF and then a 0xXX, then there are two 0x0010, indicating that the length of the frame is 16, and the length of the entire frame is actually 18,

2. What we want to study is the exif information of the image, whose identification space is 0xE1
In addition, there are two cases for 0xE1. The first one is followed by the file header, namely 0xE1, and the second one is 0xE0 before 0xE1,
Therefore, before getting this byteArray as an image object, you must first obtain all the data of this 0xE1 frame. The Code is as follows:Copy codeThe Code is as follows: // obtain 0xFFE1 app1, that is, exif information.
Var tempData: ByteArray = new ByteArray ();
// Here, e.tar get. data is the original byteArray of the image.
TempData.writeBytes(e.target.data,0,e.tar get. data. bytesAvailable );
TempData. position = 3; // read the fourth byte
Var exif: Number = tempData. readUnsignedByte ();
If (exif = 0xE1) {// check whether this byte is 0xE1
This. Debug ("exif information is available ");
// Read a length
Var exifLength: Number = tempData. readUnsignedShort ();
File_item.exifArray.writeBytes (tempData, tempData. position-2, exifLength); // If yes, read the exif information into a file object
} Else if (exif = 0xE0) {// e0, skip this frame and check the following
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 );
}
}

After processing this, we need to insert the frame into the compressed byteArray.
The logic of the Code should be clear at a glance.Copy codeThe Code is 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.tar get. 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.