Skip to content

Commit 8df097d

Browse files
committed
bitmaptools rotate example
1 parent 5dec0e3 commit 8df097d

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

bitmaptools/Billie.bmp

4.26 KB
Binary file not shown.

bitmaptools/Billie.bmp.license

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2018 Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT

bitmaptools/bitmaptools_rotate_bmp.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Tim Cocks
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Use bitmaptools.rotozoom() to rotate a bmp image.
6+
"""
7+
import math
8+
import bitmaptools
9+
import board
10+
import displayio
11+
import adafruit_imageload
12+
13+
# use the builtin display
14+
display = board.DISPLAY
15+
16+
# load bmp image into a Bitmap and Palette objects
17+
source_bitmap, source_palette = adafruit_imageload.load("Billie.bmp",
18+
bitmap=displayio.Bitmap,
19+
palette=displayio.Palette)
20+
# Create a TileGrid to show the bitmap
21+
source_tile_grid = displayio.TileGrid(source_bitmap, pixel_shader=source_palette)
22+
23+
# Create destination Bitmap object to hold the rotated image
24+
dest_bitmap = displayio.Bitmap(source_bitmap.height, source_bitmap.height, len(source_palette))
25+
26+
# Create a TileGrid to show the destination Bitmap with the rotated image in it
27+
dest_tile_grid = displayio.TileGrid(dest_bitmap, pixel_shader=source_palette)
28+
29+
# take from source bitmap, put into destination bitmap.
30+
# default values for x,y locations and clipping so whole image is used
31+
# angle argument accepts radians. You can use math module to convert from degrees
32+
bitmaptools.rotozoom(dest_bitmap, source_bitmap, angle=math.radians(270))
33+
34+
# move the rotated image tilegrid over to the right some
35+
dest_tile_grid.x = 100
36+
37+
# Create a Group to show the TileGrids
38+
group = displayio.Group()
39+
40+
# Add the TileGrids to the Group
41+
group.append(source_tile_grid)
42+
group.append(dest_tile_grid)
43+
44+
# Add the Group to the Display
45+
display.show(group)
46+
47+
# Loop forever so you can enjoy your image
48+
while True:
49+
pass

0 commit comments

Comments
 (0)