Jump to content




Print an Image to the center of the screen?


  • You cannot reply to this topic
4 replies to this topic

#1 Endergreen117

  • Members
  • 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.

#2 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

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.

#3 Endergreen117

  • Members
  • 33 posts

Posted 09 December 2014 - 10:11 PM

View PostTheOddByte, on 09 December 2014 - 10:07 PM, said:

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 by Endergreen117, 09 December 2014 - 10:18 PM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (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.

#5 Endergreen117

  • Members
  • 33 posts

Posted 10 December 2014 - 01:43 AM

View PostBomb Bloke, on 10 December 2014 - 01:14 AM, said:

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 by Endergreen117, 10 December 2014 - 01:43 AM.






3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users