g. Scaling Bitmaps

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 03 - Displaying Bitmaps & Icons >

g. Scaling Bitmaps

This section shows how to scale bitmap files using the BitmapTransform() command.

 

 

Command Prototype

 

uint16_t BitmapTransform(double Scale, double Rotate, double Translate);

 

Parameters

Description

Scale

Scale value to use (for example, 0.50 will scale down bitmap to 50% and 1.50 will scale up bitmap to 50%)

Rotate

angle of rotation (set to zero)

Translate

set to zero

 

 

Code

 

 

void setup()

{

 int centerX = 320 / 2, centerY = 480 / 2;

 

/* Initialize CleO - needs to be done only once */

 CleO.begin();

 

/* Get the handle by loading bitmap */

 int16_t handle = CleO.LoadImageFile("@Pictures/ctg.jpg", 0);

 

/* Start building a screen frame */

 CleO.Start();

 CleO.StringExt(FONT_MEDIUM, centerX, 0, LIGHT_GREEN, TM, 0, 0, "No Scaling");

 CleO.BitmapJustification(TM);

 

 /* Display original bitmap */

 CleO.Bitmap(handle, centerX, 40);

 CleO.BitmapJustification(TL);

 CleO.StringExt(FONT_MEDIUM, 30, 320, LIGHT_GREEN, ML, 0, 0, "25%");

 

/* Scale down to 25% of bitmap */

 CleO.BitmapTransform(0.25, 0);

 CleO.Bitmap(handle, 30, 340);

 CleO.StringExt(FONT_MEDIUM, 175, 320, LIGHT_GREEN, ML, 0, 0, "50%");

 

/* Scale down to 50% of bitmap */

 CleO.BitmapTransform(0.50, 0);

 CleO.Bitmap(handle, 175, 340);

 

/* Display completed screen frame */

 CleO.Show();

}

 

void loop()

{

}

 

 

Description

 

In the above code snippet, the BitmapTransform() command is used to scale down the bitmap.

The StringExt() command is used to draw text to display the scaled down percentage.

The BitmapJustification() command is used for drawing bitmap at appropriate locations on the screen.

The scale values may be changed to see different effects on the bitmap.

Use the @ symbol only when performing the file operation from the eFlash and not from the SD Card.

 

Note: The range is from (minimum) 1/8th of the bitmap size and it is up to (maximum) 256 times of the bitmap size.

 

 

Output

 

Here is the output displayed upon executing the above code snippet -

 

ScaledBitmaps