MetroMail Responsive Email Template
 
 
icon 2    January 17th, 2014
 
 
 
UPDATES & NEWS FOR THE LIVECODE COMMUNITY
 
 
 
 
 
 
 
Article 4: How to Create a Thumbnail Image
 
 

This is a handy lesson I came across recently. You might often have a need to create a thumbnail image for use in an app or even a set of such images, this is a neat way to do it. You will create a 32 x 32 pixel thumbnail image of a control.

Select the thumbnail source

In this case I want to create a thumbnail image of a knob control on my stack.
The source will be the id of the knob group.

Select an image name

Here I want to pick a unique name for the new image. I'm going to call it "tmp" followed by a number.
I want to make sure there's no image by that name already, so I'm going to cycle through numbers until I find an available slot.

 

put "tmp 1" into tImageName
repeat while there is an image tImageName
     add 1 to word 2 of tImageName
end repeat

 

Create a new image

 

create image tImageName
set the visible of image tImageName to true
set the resizequality of image tImageName to "best"

 

Take a snapshot of the source control

This is what does the work of making the image. Here pControlID is the id of the control I want to make a thumbnail from (the knob control group).

 

export snapshot from control id pControlID to image tImageName as PNG

 

Size the image to 32 x 32 pixels

Obviously you can use any size you want, but here I want a 32 x 32 pixel thumbnail image.

set the width of image tImageName to 32
set the height of image tImageName to 32

 

Make the new image size permanent

This step is somewhat nonintuitive. If you don't do this step then the width and height you just set will not stick, and the image will stay the original size. The next time you open the image it will spring back from the thumbnail size. You don't want this. Setting the imagedata makes the new size for the thumbnail permanent.

set the imagedata of image tImageName to the imagedata of image tImageName

Put the thumbnail in the clipboard for pasting

We don't really need to do this, but we might as well.

copy image tImageName

So here's a complete handler, ready to go. Pass the id of the control to the CreateThumbnail handler.

on mouseUp
    CreateThumbnail the id of group "knob"
end mouseUp

on CreateThumbnail pControlID
    local tImageName
    
    -- pick a unique name for the image
    put "tmp 1" into tImageName
    repeat while there is an image tImageName
        add 1 to word 2 of tImageName
    end repeat
    -- create an image for the thumbnail
    create image tImageName
    set the visible of image tImageName to true
    set the resizequality of image tImageName to "best"
    export snapshot from control id pControlID to image tImageName as PNG
    set the width of image tImageName to 32
    set the height of image tImageName to 32
    -- make the new size permanent
    set the imagedata of image tImageName to the imagedata of image tImageName
    -- put in the clipboard for pasting
    copy image tImageName
end CreateThumbnail

LiveCode Lessons

 

This article comes from our extensive Lessons repository, see more here.

 
 
section image
 
New Year Roadmap
 
Last year was exciting, this year will be even better!
 
read more
 
 
section image
 
Excel Library
 
Get your hands on the newest LiveCode Extensions release
 
read more
 
 
section image
 
MobGUI Updated
 
MobGUI supports themes, iOS7, resolution independence and more
 
read more
 
 
section image
 
Thumbnail Image
 
A hands on tutorial showing you how to create thumbnails from images
 
read more
 
 
 
Join Us in San Diego
 

Next 20 tickets for RunRevLive.14 sold save $200 with this coupon:

SANDIEGO

Check out runrevlive.com for more!

 
download
 
 
Featured Extensions
 
 
Excel Library
 
Take control of MS Excel with this library of over 170 commands and functions for LiveCode. Import/export data from MS Excel to LiveCode. Automate tasks, convert worksheets and more.
 
read more
 
 
 
Matrix Recoded
 
Matrix ReCoded offers 30 functions and 12 handlers to manipulate matrices. Develop mathematical or engineering solutions, or even vector-based drawing packages. Included in the Megabundle.
 
read more
 
Connect With Us
 
 
RunRev © Copyright 2013 . All Rights Reserved
 
 
 
RunRev © Copyright 2013 . All Rights Reserved