I am trying to display a 128px * 128px image on Pebble, sent from Android over AppMessage.
In Android app, I have a BitmapFactory ARGB_8888
bmp, and I do:
byte pbi[] = new byte[16*128];
for(int i = 0; i < 128; i++) {
for(int j = 0; j < 128; j++) {
if(bmp.getPixel(i, j) >= 0x7FFFFFFF) {
pbi[i*16] |= 1 << (j % 8); //set pixel (white)
}
pbi[i*16] &= ~(1 << (j % 8)); //explicitly set = 0 (black)
}
}
PebbleDictionary data;
byte send[];
for (int k = 0; k < 128; k++){
data = new PebbleDictionary();
send = new byte[16];
send = Arrays.copyOfRange(pbi, k*16, (k+1)*16-1);
data.addBytes(KEY_IMG, send);
data.addInt16(KEY_ROW, (byte)k);
PebbleKit.sendDataToPebble(getApplicationContext(), PEBBLE_APP_UUID, data);
}
Pebble has:
static int transNum;
static uint8_t received[128][16] = {0};
static void in_received_handler(DictionaryIterator *iter, void *context) {
Tuple *img_tuple = dict_find(iter, KEY_IMG);
Tuple *row_tuple = dict_find(iter, KEY_ROW);
if (img_tuple && row_tuple) {
memcpy(img_data[(int)(row_tuple->value->cstring)], img_tuple->value->data, 16);
}
}
Which should be displayed by:
static void window_load(Window *window) {
static Window *window;
static BitmapLayer *img_layer;
static GBitmap img;
static void window_load(Window *window) {
L img_layer = bitmap_layer_create( (GRect) {
.origin = {8, 20},
.size = {128, 128}
});
img = (GBitmap) {
.addr = img_data,
.bounds = GRect(8, 20, 128, 128),
.row_size_bytes = 16,
};
bitmap_layer_set_bitmap(img_layer, &img);
bitmap_layer_set_alignment(img_layer, GAlignCenter);
layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(img_layer));
display_no_img();
}
But on window_load
, I get the expected black square, but I can't figure how to make it load the received data.
Edit:
It's hard for me to keep the code above updated, but it's pretty representative. I'm hoping someone can tell me what to do to make it load the received bytes. I thought the secret was in .addr = img_data
, alas.. Thanks.