scaling an image according to screen resolution
Blitz3D Forums/Blitz3D Beginners Area/scaling an image according to screen resolution
| ||
I need to scale multiple images according to the screen resolution. I have a variable declared in the place of resolutions, and need to scale it by the variable. I just need an expression to scale it with. Any help is appreciated |
| ||
Assuming your images were originally designed to work on a 800x600 resolution and you are keeping the same aspect ratio .. e.g. 4:3 then something like this .. Scale# = GraphicsWidth() / 800.0 then scaleimage Image, Scale , Scale or resiseimage Image, ImageWidth(image) * Scale , ImageHeight(image) * Scale |
| ||
scaleimage and resizeimage are faster when you disable imagefiltering. also you might better use 3d mode and put it as a texture on a sprite. |
| ||
I'm using the starter resolution 1280 x 1024, but since many computers can't handle that, it goes down a ladder check to ensure the highest, best looking graphics mode for that computer. it goes all the way down to 640,480. The original image is scaled to perfection for the 1280 x 1024 without rescaling or resizing it (the actual pixel res on it is set to perfectly fit it ). would the "graphicswidth/800" still work on this? Also, would not there be a need for a scale on graphicsheight/600? |
| ||
The example I gave assumed the aspect ratio remained unchanged so in this case you would have to amend the y scale. ScaleX# = Graphicswidth() / 1280.0 ScaleY# = graphicsheight() / 1024.0 If you're keeping the same aspect ratio, as I said above the scale is correct for both x and y. e.g. An image is 128 x 128 @ 1280 x 1024 res and you want to scale to a appear the same size relative to 640x480 screen res .. ScaleX# = 640.0 / 1280.0 = .5 ScaleY# = 480.0 / 1024.0 = .46875 scaleimage Image, ScaleX, ScaleY would reduce the image to 64 x 60 pixels. For best results I would still stick to one aspect ratio though. Stevie |
| ||
would this work?: ScaleX# = Graphicswidth() / displaywidth ScaleY# = graphicsheight() / displayheight (displaywidth and height are variables used globally for graphics so that the same display check isn't preformed each time a new window is created) |
| ||
Im not sure if that works. You might wanna try: ScaleX# = (1.0*GraphicsWidth()) / displaywidth ScaleY# = (1.0*GraphicsHeight()) / displayheight To be sure Blitz calculates the division correctly in the variable. |
| ||
Why post exactly what's been posted already?ScaleX# = Graphicswidth() / 1280.0 ScaleY# = graphicsheight() / 1024.0 The ".0" ensures divisions are calculated correctly. |
| ||
Then be sure that the variables displaywidth and displayheight are floats. |
| ||
The ".0" ensures divisions are calculated correctly. ;) |
| ||
would this work?: ScaleX# = Graphicswidth() / displaywidth ScaleY# = graphicsheight() / displayheight (displaywidth and height are variables used globally for graphics so that the same display check isn't preformed each time a new window is created) I understand that, by you comment above, you have something like this somewhere earlier in you code: displaywidth=GraphicsWidth() displayheight=GraphicsHeight() Therefore, the code you have would basically be: ScaleX#=GraphicsWidth()/GraphicsWidth() ScaleY#=GraphicsHeight()/GraphicsHeight() What you are looking for is: ScaleX#=displaywidth/1280.0 ScaleY#=displayheight/1024.0 Since I do not know the purpose of the image, I cannot be sure whether you wish to stretch it to fit or scale it so that it maintains its proportions. The example above stretches the image to fit; if you want to maintain proportions, use the following example: tempscalex#=displaywidth/1280.0 tempscaley#=displayheight/1024.0 Scale#=tempscalex# If tempscaley#<tempscalex# then Scale#=tempscaley# ScaleImage image, Scale#, Scale# This should make the image appear the same size on any resolution with the same width/height pixel ratio. Note: you should use the former example for most circumstances. This latter example should be used if the monitor is not a 5:4 ratio (as in widescreen or like the old standard of 4:3) |