I want to create preview thumb for my photos like Facebook's preview photo. My plan:
- Sender: generate a scaled thumb (with 30px max dimension) from original photo, strip out all fixed header to send.
- Receiver: From the "minified" byte array, append with the fixed header (hardcode in the client code). Then convert it to
Bitmapto display.
Finally I come up with the solution base on Q42.ImagePreview.
I split these parts as fixed header:
- Start Of Image (
0xFFD8) - App0 (start with
0xFFE0) - Define Quantization Table(s)
- Define Huffman Table(s)
The dynamic parts are:
- Start Of Frame (start with
0xFFC0): because it contains the width/height bytes. - Start Of Scan (start with
0xFFDA). - Compressed image data.
- End Of Image (
0xFFD9)
But it only works on 1 of my devices & not works on others.
So how to generate a fixed, general & standard JPEG header that can use on both Android & iOS devices?
Thank you.
More detail:
Generate minified data flow:
-
Create a scaled bitmap from original image (max dimension 30px, keep aspect ratio) using
BitmapFactory&Matrix -
Compress scaled bitmap with quality
64usingBitmap#compress()and store inbyte[] thumbData. -
Sub-array the
thumbDataabove from0xFFDAto the end. (SOS, image data & EOI) and store inbyte[] body. -
Prepend with the 4 bytes that repsent width & height to
body, convert to Base64 string & send.
In the device that working fine, the size of thumbData is longer than others devices that not work. And the different is in Huffman Table(s), SOS & image data parts, see this: Diff check between 2 image photos
from Create JPEG thumb image with general fixed header
No comments:
Post a Comment