Page 1 of 1
Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 2:15 am
by chris319
What's the best way to do this?
I am working with an image which is 1920 x 1080. At the same time, I need to be able to see this image on a monitor of lower resolution: 1365x768. I can draw directly to the image, but can I copy the image directly to the screen, and will a straight copy scale the image to the screen resolution or do I need to resize the image to the lower screen resolution? Do I use ScreenOutput() for this? At the moment I am drawing into a windowed screen. Ultimately the image in memorey will be saved to a .bmp file at 1920 x 1280.
OS is Windows 7.
Thanks in advance.
Re: Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 7:12 am
by netmaestro
Good choice, the windowed screen. With a windowed screen set to AutoStretch, you can forget about the fiddly details of scaling. Here's a sample where I create an image 1920x1080, the native size of your image, and I display it in a windowed screen 320x240. Because the AutoStretch flag for the windowedscreen is set, the image is automatically scaled for me. Quality is excellent and so is speed. It's a resizable window, so play with the size a bit to see the results. Using a sprite as an alternative may provide better performance, not sure.
Code: Select all
InitSprite()
OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget)
OpenWindowedScreen(WindowID(0),0,0,1920,1080,1,0,0,#PB_Screen_WaitSynchronization)
CreateImage(0,1920,1080)
StartDrawing(ImageOutput(0))
Box(0,0,1920,1080,RGB(200,200,200))
Box(0,0,40,40,#Red)
Box(1880,0,40,40,#Red)
Box(1880,1040,40,40,#Red)
Box(0,1040,40,40,#Red)
StopDrawing()
Repeat
Repeat
ev=WindowEvent()
If ev=#PB_Event_CloseWindow
End
EndIf
Until ev=0
StartDrawing(ScreenOutput())
DrawImage(ImageID(0),0,0)
StopDrawing()
FlipBuffers()
ForEver
Re: Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 7:27 am
by chris319
Thanks for the advice. I will try it forthwith.
Fortunately, for my immediate needs, speed and performance aren't really a consideration.
Re: Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 10:51 am
by chris319
Your code works. My code fails when I try to draw to the screen.
The above line gives "[ERROR] The specified output is NULL (0 value)
Re: Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 4:11 pm
by heaven6502
I was struggling yesterday with similar problem...
try InitSprite() before opening screen...
InitSprite()
CreateImage(0, 800, 480)
OpenWindow(0,0,0,800,480,"Fractal Lines",#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0),0,0,800,480)
Re: Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 4:31 pm
by chris319
I don't know exactly what I did or why it works, but I finally got it to run without errors.
Thanks again.
Re: Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 6:19 pm
by chris319
Code: Select all
With a windowed screen set to AutoStretch, you can forget about the fiddly details of scaling. Here's a sample where I create an image 1920x1080, the native size of your image, and I display it in a windowed screen 320x240. Because the AutoStretch flag for the windowedscreen is set, the image is automatically scaled for me.
No joy. It doesn't scale the image at all; it crops it.
If I use resize image, it resets the image handle and the program thinks the image is not initialized.
Re: Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 6:32 pm
by netmaestro
Remember you have to create the windowed screen at the native size of your image. This is going to be larger than the window. Refer to my sample code, it doesn't get cropped. All four corners are always visible.
Re: Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 7:35 pm
by chris319
Ah, OK, that did it. Thank you very much for your help.
Re: Working with Images and Screen Graphics
Posted: Fri Jul 25, 2014 9:14 pm
by graph100
very nice tips netmaestro ! Didn't though this way (openwindow < openwindowedscreen ) was a way to go !