When using flex's jpegencoder to compress the picture, the exif information will be lost, that is, the author of the picture, the camera used by Shenma, and all the ones are gone. What should I do?
After studying jpeg's documentation, this problem was finally solved
The file format is divided into frames, each frame starts with 0xFF, and then followed by an identification without. For example, 0xFFD8 represents the beginning of the file, 0xFFD9 represents the end of the file, and the identification bit is the length of the frame. The length does not include 0xFF and the identification bit, but includes the length of the 2 bytes. For example, a frame starts, first a 0xFF followed by 0xXX, and then two 0x0010, indicating that the length of this 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 picture, and its identification bit is 0xE1
Moreover, there are two situations in this 0xE1. The first is to follow the file header, which is 0xE1. The second is to have a 0xE0 before 0xE1.
So before using this byteArray as shown in the image object, you must first obtain all the data of this 0xE1 frame. The code is as follows:
//Get 0xFFE1 app1 that is exif information
var tempData:ByteArray = new ByteArray();
// Here is the original byteArray of the picture
(,0,);
= 3; //Read the fourth byte
var exif:Number = ();
if(exif == 0xE1) { //See if this byte is 0xE1
("Exif information");
//Read a length
var exifLength:Number = ();
file_item.(tempData,-2,exifLength); //If yes, read exif information into a file object
} else if(exif == 0xE0) { //It is e0, then skip this frame and look at the following
= 4;
var e0Length:Number = ();
= 4+e0Length;//Skip e0
+= 1;//Skip 0xff
var isEx:Number = ();
if(isEx==0xE1) {
var len:Number = ();
file_item.(tempData,-2,len);
}
}
After processing these, we need to insert this frame into the compressed byteArray
The logic of the code should be clear at a glance, hey
if(file_item.>0) { //Write exif information
var desData:ByteArray = new ByteArray();
(oldData,0,2);//0xffd8
(0xff);
(0xe1);
(file_item.exifArray,0,file_item.);
(oldData,2,);
= 0;
(desData,file_item);
} else {
(,file_item);
}
After studying jpeg's documentation, this problem was finally solved
The file format is divided into frames, each frame starts with 0xFF, and then followed by an identification without. For example, 0xFFD8 represents the beginning of the file, 0xFFD9 represents the end of the file, and the identification bit is the length of the frame. The length does not include 0xFF and the identification bit, but includes the length of the 2 bytes. For example, a frame starts, first a 0xFF followed by 0xXX, and then two 0x0010, indicating that the length of this 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 picture, and its identification bit is 0xE1
Moreover, there are two situations in this 0xE1. The first is to follow the file header, which is 0xE1. The second is to have a 0xE0 before 0xE1.
So before using this byteArray as shown in the image object, you must first obtain all the data of this 0xE1 frame. The code is as follows:
Copy the codeThe code is as follows:
//Get 0xFFE1 app1 that is exif information
var tempData:ByteArray = new ByteArray();
// Here is the original byteArray of the picture
(,0,);
= 3; //Read the fourth byte
var exif:Number = ();
if(exif == 0xE1) { //See if this byte is 0xE1
("Exif information");
//Read a length
var exifLength:Number = ();
file_item.(tempData,-2,exifLength); //If yes, read exif information into a file object
} else if(exif == 0xE0) { //It is e0, then skip this frame and look at the following
= 4;
var e0Length:Number = ();
= 4+e0Length;//Skip e0
+= 1;//Skip 0xff
var isEx:Number = ();
if(isEx==0xE1) {
var len:Number = ();
file_item.(tempData,-2,len);
}
}
After processing these, we need to insert this frame into the compressed byteArray
The logic of the code should be clear at a glance, hey
Copy the codeThe code is as follows:
if(file_item.>0) { //Write exif information
var desData:ByteArray = new ByteArray();
(oldData,0,2);//0xffd8
(0xff);
(0xe1);
(file_item.exifArray,0,file_item.);
(oldData,2,);
= 0;
(desData,file_item);
} else {
(,file_item);
}