Reading 61 Bundled Images With Compose Resources
By Nesim Razon, independent mobile developer · 2026-12-04
My space app ships with 61 curated pictures inside the app, so it works without a network. In a Kotlin Multiplatform project the same code must load them on Android and iOS. This post shows the three pieces that make that work: Compose Resources to read the bytes, one expect and actual function to turn bytes into an image, and a tiny cache that keeps the screen from decoding the same picture twice.

Why the pictures live in the files folder
Compose Resources has a special place for images, the drawable folder, with automatic handling of density and theme. My pictures are different. They are photographs of fixed size, chosen one by one, and I want the original JPEG bytes untouched. So they sit in the files folder of the shared resources, as files named after the card id, for example k001.jpg, and are read like any other file.
Whatever is in that folder is packaged into the Android app and into the iOS bundle by the same Gradle setup, so I write the loading code once. The 61 pictures take about five megabytes in total, and range from roughly 640 to 1,000 pixels on the long side. They are not scaled for different screens at build time, which is acceptable for a card that is shown at a similar size everywhere.
Res.readBytes is the shared entry point
Compose generates a Res object for the module. It has a suspend function, readBytes, that takes a path inside the resources and returns a ByteArray. The same function works on both platforms, and because it is suspending, the file work does not block the interface. My cards list, a JSON file with titles and notes for all 61 cards, is read the same way and decoded to text.
The key point is what Res.readBytes does not do: it does not decode images. It gives me bytes. Turning JPEG bytes into something Compose can draw is a platform job, because each platform has its own decoder.
One expect function for decoding
In common code I declare a function that takes bytes and returns an ImageBitmap, or null if the data cannot be decoded. Each platform provides its own actual version.
On Android the actual is one line: BitmapFactory decodes the byte array and the result is converted to a Compose image bitmap. On iOS the actual asks the Skia library to make an image from the encoded bytes and converts it to a Compose image bitmap, wrapped in a try block so a bad file returns null instead of crashing.
Returning null on failure is deliberate. A missing or damaged picture should leave an empty space, not take down the screen, and the rest of the interface keeps working.
A small cache so each card decodes once
Cards appear in several places: the card of the day, the album grid, the detail view. Without a cache, every appearance would read the file and decode it again. So there is one map from card id to decoded image, kept at file level.
The composable that shows a card uses produceState with the cached value as its starting value. If the id is not yet in the map, it reads and decodes the picture inside the producer and stores the result. Because the map remembers a failure as a null entry, a picture that cannot be decoded is not retried on every recomposition.
Showing the cached value as the initial state also means that a card you have seen before appears instantly, with no empty frame while the producer runs.
Reusing the same bytes for sharing
The album can share a card or set it as a wallpaper. Those actions read the same JPEG bytes again with Res.readBytes and hand them to platform code, which writes a file and opens the system share sheet. Using the original bytes rather than a re-encoded bitmap means the shared picture is exactly the one that ships, with no extra compression.
The decoded bitmap is for drawing only. Sharing and saving always go back to the file.
From the card list to a picture on screen
The data and the pictures are separate. At start the app reads the JSON list of 61 cards: id, category, title and a short note, all written by hand. That list is small and loads at once. The pictures are not loaded together with it. A picture is read only when a card that needs it appears on screen, and the first appearance pays the cost of reading and decoding it.
The card of the day is picked from a shuffled order of the 61 cards that uses a fixed seed, by taking the day number modulo 61. Everyone sees the same card on the same day, and over 61 days every card appears once before the cycle repeats. Nothing about that choice needs the network.
Other parts of the app, such as the photo of the day and the station position, do use the network and are cached separately. The bundled set is what guarantees that the home screen always has something good to show, even offline on the first launch.
Limits and what I would change at scale
- The cache has no size limit. For 61 pictures of this size that is fine; for hundreds of large images I would use a bounded cache or decode at a smaller size.
- All decoding happens at full file size. Android could use sampling options in the decoder and iOS could ask Skia for a scaled image if memory became a problem.
- The cache lives for the process only. After the app is killed, the first view of each card decodes again, which is quick for pictures this small.
- Every card needs its own file name in the data. A unit test or a build check that confirms each id in the JSON has a matching file would catch a typo before release.
Uzay Günlüğü (Space Journal) is a free Turkish-language Android app. It shows a card of the day from this set, with a collection album and a daily streak.
Frequently asked questions
Where do I put photos in Compose Resources?
Files you want as raw bytes go in the files folder and are read with Res.readBytes. The drawable folder is for resources that Compose should decode and scale for you.
Does Res.readBytes decode images?
No. It returns the file contents as bytes, and you decode them with a platform function.
Why use expect and actual for decoding?
Android and iOS have different image decoders. The shared code declares the function once and each platform fills it in.
Why cache decoded bitmaps?
The same card appears on several screens. A cache avoids reading and decoding the file again each time.
What happens if a picture is damaged?
The decode function returns null, the card shows nothing and the rest of the app keeps working.
More from the blog
- What Stays Platform-Specific in a Kotlin Multiplatform App
- Declaring a Walking Game's Health Data in Play Console
- Blender From the Command Line: Pale Colours and Boolean Order
- Play Games Saved Games: A Merge That Never Goes Backwards
- From Blender Renders to Compose: Sprite Atlas and Layers
- Local HTML With Images on Android and iOS: Use Data URIs