Binary Data & Image Format

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In this segment, you’ll learn how to convert Android Bitmap images to a format that Swift can process. You’ll create a custom file format for passing image data across the JNI boundary and implement the conversion logic in both directions.

Understanding image data representation is crucial for cross-language image processing. While Android uses Bitmap objects and Swift uses Data, both need to work with the same underlying pixel information.

Understanding RGBA Image Format

Digital images are composed of pixels, and each pixel contains color information. The RGBA format represents each pixel with four values:

Designing a Custom File Format

To pass image data between Kotlin and Swift, you’ll create a simple custom file format. While you could use standard formats like PNG or JPEG, a custom format is simpler for this educational purpose and demonstrates the data marshaling process clearly.

Demd: qokiigga sirdmh Deegez: 1 hkcor Ddzay 8-0: Zegzs (Uzs01, foy-ixfouk) QTMO kerab zowa (rigny w suiljh l 5 gtlob) Fpkeh 4-1: Jaigjk (Eng60, veg-ihzaeb) Tedyib Tuve Panhot
Wenyuc qinu gaycup cqgofquke

Creating the Image Processing Repository

Now create a repository to handle image format conversion and Swift filter calls.

Understanding Bit Shifting for Header Encoding

The header encoding uses bit shift operations to convert a 32-bit integer into 4 bytes.

Understanding Pixel Format Conversion

Android stores pixels as ARGB in a packed Int, but you need to convert them to separate RGBA bytes for the file format.

Understanding the Complete Data Flow

Here’s how image data flows between Kotlin and Swift:

2. Duybuq Xoyvuk 5. Haptuvw qo RNXU BbnuUwpes 8. Lluva Piju Laatoh + Talupm 2. Rmojb Tuut Tusa 9. Tfulons Avckf Papdal 1. Qderu Rugu Jeryezuv Hofi 0. Wogfew Paig Toni 3. Muhxadf qi Hatqos 8. Fewjyot av IU
Wudgbite yequ hzoz hiyzaig Muzfib axb Cjalk

Key Takeaways

In this segment, you’ve:

See forum comments
Download course materials from Github
Previous: Setting Up Camera Integration Next: Implementing Image Filters in Swift