我正在尝试在Pebble上显示128px * 128px图像,通过AppMessage从Android发送。
在Android应用中,我有一个BitmapFactory ARGB_8888
bmp,我这样做:
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有:
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);
}
}
应该通过以下方式显示:
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();
}
但在window_load
上,我得到了预期的黑色方块,但我无法确定如何加载接收到的数据。
编辑:
我很难保持上面的代码更新,但它很有代表性。我希望有人可以告诉我该怎么做才能加载收到的字节。我以为秘密在.addr = img_data
,唉......谢谢。