🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    How to scale a bitmap drawn with M5.Display.drawBitmap() on M5Stack?

    Scheduled Pinned Locked Moved PRODUCTS
    1 Posts 1 Posters 438 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • MorleM Offline
      Morle
      last edited by

      I am working with an M5Stack Core S3 using the <M5Unified.h> library. I successfully display a 32×32 bitmap stored as a uint16_t array (RGB565 format) using M5.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:
      20251221_122614.jpg

      My main.cpp code:

      #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
      1 Reply Last reply Reply Quote 0

      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
      • First post
        Last post