Working with Images and Screen Graphics
Working with Images and Screen Graphics
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.
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.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Working with Images and Screen Graphics
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
BERESHEIT
Re: Working with Images and Screen Graphics
Thanks for the advice. I will try it forthwith.
Fortunately, for my immediate needs, speed and performance aren't really a consideration.
Fortunately, for my immediate needs, speed and performance aren't really a consideration.
Re: Working with Images and Screen Graphics
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)
Code: Select all
StartDrawing(ScreenOutput())
-
- User
- Posts: 20
- Joined: Mon Jan 26, 2009 1:43 pm
Re: Working with Images and Screen Graphics
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)
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
I don't know exactly what I did or why it works, but I finally got it to run without errors.
Thanks again.
Thanks again.
Re: Working with Images and Screen Graphics
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.
If I use resize image, it resets the image handle and the program thinks the image is not initialized.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Working with Images and Screen Graphics
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.
BERESHEIT
Re: Working with Images and Screen Graphics
Ah, OK, that did it. Thank you very much for your help.
Re: Working with Images and Screen Graphics
very nice tips netmaestro ! Didn't though this way (openwindow < openwindowedscreen ) was a way to go !
_________________________________________________
My Website : CeriseCode (Warning : perpetual changes & not completed
)
My Website : CeriseCode (Warning : perpetual changes & not completed
