Scale window or zoomed out view option?

Just starting out? Need help? Post your questions and find answers here.
matalog
Enthusiast
Enthusiast
Posts: 165
Joined: Tue Sep 05, 2017 10:07 am

Scale window or zoomed out view option?

Post by matalog »

Is there a way to have a program draw on a window, of say, 1000x1000px, so that it can be previewed on screen, but it is actually generating an image of 4000x4000px, of which the view is merely being zoomed out to view 4 times smaller?
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Scale window or zoomed out view option?

Post by Caronte3D »

Check: ResizeImage()
matalog
Enthusiast
Enthusiast
Posts: 165
Joined: Tue Sep 05, 2017 10:07 am

Re: Scale window or zoomed out view option?

Post by matalog »

Thanks!!! I will try that!!!!!!!!
matalog
Enthusiast
Enthusiast
Posts: 165
Joined: Tue Sep 05, 2017 10:07 am

Re: Scale window or zoomed out view option?

Post by matalog »

I'm not sure that Resizeimage() does what I want actually.

I want to be able to continuously draw to screen and have what the screen sees as 1/4 the size of the actual being generated.

Resizeimage() seems to just change the size of an already prepared image.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Scale window or zoomed out view option?

Post by mk-soft »

Working with a copy of the image
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Scale window or zoomed out view option?

Post by Caronte3D »

matalog wrote: Thu Jul 22, 2021 9:18 pm I want to be able to continuously draw to screen...
You must "continuously" use Resizeimage() if your source image (a copy as mk-soft said) changes.
matalog
Enthusiast
Enthusiast
Posts: 165
Joined: Tue Sep 05, 2017 10:07 am

Re: Scale window or zoomed out view option?

Post by matalog »

Okay, I think I get it now, I have tried multiple ways and always get an error, usually that I have not initialised a window at the correct time.

Could someone please show me how I might do it with this small program, that is, to have a preview window of say, 500x500px, that shows what is being generated in the larger window?

I assume that I will have to create a second window, possibly a second image, then copy the big image to the second, resize it, and send that image to the second window, I have been using Copyimage(), Resizeimage(), Setactivewindow(), and I always get some error stopping it from running. The truth is, I don't fully understand the procedure for working with a window and image etc.

I suppose that I do not even need to have the larger image drawn to a window, as I will only ever save it, and not try to view it live. I will need to have the scaled window show the output so that I can see a point when it is worth saving.

There is a reason that I have been using the Openwindowedscreen() though, as it then allows me to use keyboard controls to input to the program.

Code: Select all


InitKeyboard()   
InitSprite()
UseJPEGImageEncoder()



#width=3000
#height=3000
#ImgGadget=0

Global.i x,y,xo,yo,ti,c,h,col
Global.i c=1,re=1,gr=1,bl=1
Global.i reo=1,gro=1,blo=1
x=#width/2:y=#height/2
Global.i h=1:ti=1
Global main=OpenWindow(#PB_Any,10,10,#width,#height,"Drawing")
Global wmain=OpenWindowedScreen(WindowID(main),0,0,#width,#height)
Global image=CreateImage(#PB_Any, #width,#height) 
ImageGadget(#ImgGadget, 0, 0, #width, #height, ImageID(image))


Procedure SDRAW()

  StartDrawing(ImageOutput(image))
  Circle(Random(1800,200),Random(1800,200),Random(200,1),Random(16777216,1))
  
 StopDrawing()
 
EndProcedure
Repeat
  
     ExamineKeyboard()
Event = WindowEvent()


    SDRAW()
 SetGadgetState(#ImgGadget, ImageID(image))
 ;Delay(100)

           If Event = #PB_Event_CloseWindow
             End
           EndIf
    
     If KeyboardPushed(#PB_Key_Escape)
    quit=#True
  EndIf
  
  If KeyboardPushed(#PB_Key_Space)
  Delay(800)  
  EndIf
  
  If KeyboardPushed(#PB_Key_W)
    SaveImage(image,"Randraw - "+FormatDate("%yyyy%mm%dd_%hh%ii%ss", Date())+Str(Random(9999,1))+".bmp", #PB_ImagePlugin_BMP)
  Delay(500)  
  EndIf
  
  If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
    Quit=#True
  ElseIf Event = #PB_Event_Gadget
    EventGadget = EventGadget()
    Select EventGadget        
    EndSelect
  EndIf
  
    Until quit=#True
    
    
matalog
Enthusiast
Enthusiast
Posts: 165
Joined: Tue Sep 05, 2017 10:07 am

Re: Scale window or zoomed out view option?

Post by matalog »

I got it working here, although, I'm not sure it is as fast as it could be.

Does anyone know why there is a point where the screen flickers black at the beginning of each running of the program?

Code: Select all


InitKeyboard()   
InitSprite()
UseJPEGImageEncoder()



#width=1000
#height=1000
#height1=4000
#width1=4000
#ImgGadget=0

Global.i x,y,xo,yo,ti,c,h,col
Global.i c=1,re=1,gr=1,bl=1
Global.i reo=1,gro=1,blo=1
x=#width/2:y=#height/2
Global.i h=1:ti=1
Global main=OpenWindow(#PB_Any,10,10,#width,#height,"Drawing")
Global wmain=OpenWindowedScreen(WindowID(main),0,0,#width,#height)
Global image=CreateImage(#PB_Any, #width1,#height1) 
ImageGadget(#ImgGadget, 0, 0, #width1, #height1, ImageID(image))
Global imagesc=CreateImage(#PB_Any, #width,#height)
ImageGadget(#ImgGadget, 0, 0, #width, #height, ImageID(imagesc))

Procedure SDRAW()

  StartDrawing(ImageOutput(image))
  Circle(Random(3800,200),Random(3800,200),Random(200,1),Random(16777216,1))
  
 StopDrawing()
 
EndProcedure
Repeat
  
     ExamineKeyboard()
Event = WindowEvent()

    SDRAW()

     CopyImage(image,copy)
    ResizeImage(copy,1000,1000)
    StartDrawing(ImageOutput(imagesc))
    DrawImage(ImageID(scaled),0,0)
    StopDrawing()
    SetGadgetState(#ImgGadget, ImageID(imagesc))
    ;FlipBuffers()
 ;Delay(100)

           If Event = #PB_Event_CloseWindow
             End
           EndIf
    
     If KeyboardPushed(#PB_Key_Escape)
    quit=#True
  EndIf
  If KeyboardPushed(#PB_Key_Space)
  
  Delay(800)  
  EndIf
  If KeyboardPushed(#PB_Key_W)
    SaveImage(image,"Randraw - "+FormatDate("%yyyy%mm%dd_%hh%ii%ss", Date())+Str(Random(9999,1))+".bmp", #PB_ImagePlugin_BMP)
  Delay(500)  
  EndIf
  If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
    Quit=#True
  ElseIf Event = #PB_Event_Gadget
    EventGadget = EventGadget()
    Select EventGadget        
    EndSelect
  EndIf
    Until quit=#True
    
    
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Scale window or zoomed out view option?

Post by RASHAD »

Hi

Code: Select all

If OpenWindow(0, 0, 0, 1000, 800, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  CanvasGadget(0, 10, 10, 980, 780, #PB_Canvas_Container)
  CanvasGadget(1, 720, 5, 250, 200,#PB_Canvas_Border)
  ButtonGadget(2, 10, 740, 80, 30, "Show")
  CloseGadgetList()
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Gadget
      Select EventGadget() 
        Case 0
          If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
            If StartDrawing(CanvasOutput(0))
              x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
              y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
              Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
              GrabDrawingImage(1,0,0,OutputWidth(),OutputHeight())
              StopDrawing()
              ResizeImage(1,245, 195)
              SetGadgetAttribute(1,#PB_Canvas_Image ,ImageID(1))
            EndIf
          EndIf
          
        Case 2
          Run ! 1
          If Run = 1
            HideGadget(1,1)
          Else
            HideGadget(1,0)
          EndIf 
      EndSelect
    EndIf
    
  Until Event = #PB_Event_CloseWindow
EndIf

Egypt my love
matalog
Enthusiast
Enthusiast
Posts: 165
Joined: Tue Sep 05, 2017 10:07 am

Re: Scale window or zoomed out view option?

Post by matalog »

RASHAD wrote: Sat Jul 24, 2021 4:12 am Hi

Code: Select all

If OpenWindow(0, 0, 0, 1000, 800, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  CanvasGadget(0, 10, 10, 980, 780, #PB_Canvas_Container)
  CanvasGadget(1, 720, 5, 250, 200,#PB_Canvas_Border)
  ButtonGadget(2, 10, 740, 80, 30, "Show")
  CloseGadgetList()
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Gadget
      Select EventGadget() 
        Case 0
          If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
            If StartDrawing(CanvasOutput(0))
              x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
              y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
              Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
              GrabDrawingImage(1,0,0,OutputWidth(),OutputHeight())
              StopDrawing()
              ResizeImage(1,245, 195)
              SetGadgetAttribute(1,#PB_Canvas_Image ,ImageID(1))
            EndIf
          EndIf
          
        Case 2
          Run ! 1
          If Run = 1
            HideGadget(1,1)
          Else
            HideGadget(1,0)
          EndIf 
      EndSelect
    EndIf
    
  Until Event = #PB_Event_CloseWindow
EndIf

Thanks Rashad, that is a good example.
Post Reply