33 posts
Posted 09 December 2014 - 09:24 PM
Hi, I'm working on an OS right now and I am working on the "configuration Utility" right now, and I would like to print a given image to the center of the screen. This must also work with images LARGER than the screen (that way it works on monitors and on computers with a different size).
Any help would be great.
1852 posts
Location
Sweden
Posted 09 December 2014 - 10:07 PM
Are you using paintutils when drawing the image? Because the only problem I see then is getting the width of the picture
But here's pretty much how you would center it when you've gotten the width of the screen and image.
paintutils.drawImage( image, math.ceil( (screenWidth-imageWidth)/2 ), y )
Where
image is the image itself,
screenWidth is the width of the screen and
imageWidth is the width of the image, it's pretty self-explanatory.
33 posts
Posted 09 December 2014 - 10:11 PM
Are you using paintutils when drawing the image? Because the only problem I see then is getting the width of the picture
But here's pretty much how you would center it when you've gotten the width of the screen and image.
paintutils.drawImage( image, math.ceil( (screenWidth-imageWidth)/2 ), y )
Where
image is the image itself,
screenWidth is the width of the screen and
imageWidth is the width of the image, it's pretty self-explanatory.
Thank you, I was unsure if it would work with negative values or not.
EDIT: also, Is there a function to return the length of an image? If not, how would I go about reading the length of the first line of the image file (it's a paint file so I should be able to do that right?).
Edited on 09 December 2014 - 09:18 PM
7083 posts
Location
Tasmania (AU)
Posted 10 December 2014 - 01:14 AM
Let's say you use paintutils.loadImage() to dump a table into some variable (eg "myImage"). myImage ends up being a pointer to a two-dimensional table with one numeric index per point in the picture.
You can then get the width of the image through #myImage[1], or the height through #myImage.
33 posts
Posted 10 December 2014 - 01:43 AM
Let's say you use paintutils.loadImage() to dump a table into some variable (eg "myImage"). myImage ends up being a pointer to a two-dimensional table with one numeric index per point in the picture.
You can then get the width of the image through #myImage[1], or the height through #myImage.
Thank you, Bomb. 'Twas exactly what I wanted.
Edited on 10 December 2014 - 12:43 AM