While I was working on one of my more favourite projects called MuchWord, which was basically my version of ‘two pics, one word’ featuring Doge, I came across the challenge of saving and retrieving images as text from a database on Xamarin, from an S3 bucket. After deciding against storing the images as images (too many URLs to track and update), I decided to store them in a flat database file along with the rest of the data that the game would need, such as level information etc. Since the images were fairly small in size, there wouldn’t be a noticeable dent on performance either.

The first part of this exercise is to design a schema and create your choice of database. In my case, I created an SQLite database using SQLite Studio, with a table for the words which included columns for the level number, word, and two columns for the two images that form each word.

Then comes populating the database with the information. In my case, since I wasn’t creating a front-end and the game only had a few levels for demonstration, I populated the database manually by converting the images to base64 strings and adding it to the respective field on the row, using an online service such as Base64Image.

Once done, the database will have to be retrieved from the S3 bucket or internal folder, and the object classes written for the specific table on the database. In the code-behind file for the app’s page that requires the images to be displayed, it’s just a matter of converting the base64 strings back to images and displaying them on the image view, as below.

Browse the source code for the project on Bitbucket.