Rotating bitmaps
I'm trying to rotate a bitmap based on code from here but everytime I rotate the image at all I end up with a black box with some wierd graphics in it. If i set rotation to 0 it works fine:
s_white_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ONE_WHITE);
s_black_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ONE_BLACK);
GRect layer_frame = layer_get_frame(window_layer);
int angle = 0x1000 * 45 / 60;
s_white_layer = rot_bitmap_layer_create(s_white_bitmap);
s_black_layer = rot_bitmap_layer_create(s_black_bitmap);
layer_set_frame((Layer*)s_white_layer,layer_frame);
layer_set_frame((Layer*)s_black_layer,layer_frame);
rot_bitmap_set_compositing_mode(s_white_layer, GCompOpOr);
rot_bitmap_set_compositing_mode(s_black_layer, GCompOpClear);
rot_bitmap_layer_set_angle(s_white_layer, angle);
rot_bitmap_layer_set_angle(s_black_layer, angle);
layer_add_child(window_layer, (Layer*)s_white_layer);
layer_add_child(window_layer, (Layer*)s_black_layer);
Any ideas why it would be black? Its a simple png with a transparent background.
Posted Aug 1, 2015, 6:27 AM UTC
35
Should be
Or, alternatively, use the included macro definition:
That does change the angle. However I still just end up with a black box instead of the image rotated.
I think you're trying to draw a transparent png, but
rot_bitmap_layeris deprecated and I don't think it supports setting the compositing mode. You should try using graphics_draw_rotated_bitmap or converting what look like your watchface's hands intoGPathsand drawing them each time (which would use a somewhat considerable amount less of battery).Thanks for the tips. I'll try the GPaths method.
another option, if you don't need to perform the rotation in real time, is simply rotate the image with a paint program and draw it on your pebble as you would any other image. for an example see my watchface "digital 90 flip" https://apps.getpebble.com/applications/5409756b950b217a0f000106