How to scale a bitmap drawn with M5.Display.drawBitmap() on M5Stack?
-
I am working with an M5Stack Core S3 using the
<M5Unified.h>library. I successfully display a 32×32 bitmap stored as auint16_tarray (RGB565 format) usingM5.Display.drawBitmap()(see my code below). The bitmap represents a small animal, but at its native resolution it appears too small on the display (see the result below). At the moment,M5.Display.drawBitmap()draws the image at a 1:1 pixel ratio, and I don’t see an obvious way to apply scaling. How to scale the image by an integer factor (for example, 2 or 3) so that it appears larger on the display?My result:

My
main.cppcode:#include <M5Unified.h> constexpr int IMG_W = 32; constexpr int IMG_H = 32; const uint16_t myBitmap[IMG_W * IMG_H] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xffff, 0x0823, 0x0000, 0x0000, 0x0000, 0x0823, 0xffff, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xffff, 0xffff, 0x0823, 0x0823, 0x0823, 0xffff, 0xffff, 0x0823, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xff39, 0x0823, 0x0823, 0xff39, 0xff39, 0xff39, 0x0823, 0x0823, 0xff39, 0xff39, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xff39, 0xf653, 0x0823, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0x0823, 0xff39, 0xf653, 0xff39, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xff39, 0x0823, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0x0823, 0xff39, 0xff39, 0xf653, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xff39, 0x0823, 0xff39, 0x0823, 0xff39, 0xff39, 0x0823, 0xff39, 0xff39, 0x0823, 0xff39, 0xf653, 0x0823, 0x0823, 0x0823, 0x0823, 0x0823, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0x0823, 0xff39, 0x0823, 0xff39, 0xff39, 0x0823, 0xff39, 0xff39, 0xf653, 0x0823, 0x0823, 0x0823, 0xf653, 0xff39, 0xff39, 0xff39, 0xff39, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0xf653, 0xf653, 0xf653, 0xf653, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xfd35, 0xfd35, 0xfd35, 0xfd35, 0xff39, 0xff39, 0xff39, 0xf653, 0xf653, 0xf653, 0xf653, 0xf653, 0xf653, 0xff39, 0xff39, 0xff39, 0xff39, 0xff39, 0x0823, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xf410, 0xfd35, 0xf410, 0xfd35, 0xfd35, 0xf653, 0xf653, 0xf653, 0x0823, 0xf653, 0xf653, 0xf653, 0xf653, 0xf653, 0xf653, 0xff39, 0xff39, 0xf653, 0x0823, 0xf653, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xfd35, 0xfd35, 0xfd35, 0xfd35, 0xfd35, 0xf653, 0x0823, 0x0823, 0xe4ed, 0xf653, 0xf653, 0xff39, 0xff39, 0xf653, 0xf653, 0xf653, 0xf653, 0xf653, 0x0823, 0xe4ed, 0xf653, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0x0823, 0x0823, 0x0823, 0x0823, 0x0823, 0xe4ed, 0xe4ed, 0xf653, 0xf653, 0xff39, 0xff39, 0xff39, 0xff39, 0xf653, 0xf653, 0xf653, 0xe4ed, 0x0823, 0x0823, 0xe4ed, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xf653, 0xf653, 0xf653, 0xf653, 0xff39, 0xff39, 0xff39, 0xe4ed, 0xf653, 0xe4ed, 0xe4ed, 0x0823, 0x0000, 0x0823, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0xe4ed, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xf653, 0xe4ed, 0x0823, 0x0823, 0x0823, 0xe4ed, 0xe4ed, 0xe4ed, 0x0823, 0x0823, 0x0823, 0x0823, 0xe4ed, 0xe4ed, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xf653, 0xe4ed, 0x0823, 0x0000, 0x0823, 0xe4ed, 0xe4ed, 0x0823, 0x0000, 0x0000, 0x0000, 0x0823, 0xe4ed, 0xe4ed, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0xf653, 0xe4ed, 0x0823, 0x0000, 0x0823, 0xe4ed, 0xe4ed, 0x0823, 0x0000, 0x0000, 0x0000, 0x0823, 0xe4ed, 0xe4ed, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0x0823, 0x0000, 0x0000, 0x0000, 0x0823, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0823, 0x0823, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, }; void setup() { auto cfg = M5.config(); M5.begin(cfg); M5.Display.clear(TFT_BLACK); M5.Display.drawBitmap(50,50,IMG_W,IMG_H,myBitmap); } void loop() { }My development enviroment:
- Windows 10 Pro 22H2
- Visual Studio Code 1.99.1 with PlatformIO 3.3.4
- M5Stack Core S3
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login