loading images and mixing

Just starting out? Need help? Post your questions and find answers here.
infratec
Always Here
Always Here
Posts: 7599
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: loading images and mixing

Post by infratec »

Hi,

try this:

Code: Select all

EnableExplicit

Enumeration
  #CanvasGadget1
  #CanvasGadget2
EndEnumeration


Procedure ShowColourInfo(Gadget.i)
  
  Protected.i x, y, Colour
  
  
  x = GetGadgetAttribute(Gadget, #PB_Canvas_MouseX)
  y = GetGadgetAttribute(Gadget, #PB_Canvas_MouseY)             
  Colour = Point(x, y)
  Debug Str(Gadget) + " " + Str(x) + "/" + Str(y) + " : R " + Str(Red(Colour)) + "  G " + Str(Green(Colour)) + "  B " + Str(Blue(Colour))
  
EndProcedure



Define.i im, Exit, Event

UseJPEGImageDecoder() ; <--- Remember decoder

OpenWindow(0, 0, 0, 1024, 768, "Draw", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

im = LoadImage(#PB_Any, "E:\1.jpg")
CanvasGadget(#CanvasGadget1, 0, 0, ImageWidth(im), ImageHeight(im))
StartDrawing(CanvasOutput(#CanvasGadget1))
DrawImage(ImageID(im), 0, 0)
StopDrawing()
FreeImage(im)

im = LoadImage(#PB_Any, "E:\2.jpg")
CanvasGadget(#CanvasGadget2, 500, 0, ImageWidth(im), ImageHeight(im))
StartDrawing(CanvasOutput(#CanvasGadget2))
DrawImage(ImageID(im), 0, 0)
StopDrawing()
FreeImage(im)

Exit = #False
Repeat
 
 Event = WaitWindowEvent()
 
 Select Event
   Case #PB_Event_Gadget
     Select EventGadget()
       Case #CanvasGadget1
         Select EventType()
           Case #PB_EventType_MouseEnter
             StartDrawing(CanvasOutput(#CanvasGadget1))
           Case #PB_EventType_MouseMove
            ShowColourInfo(#CanvasGadget1)
           Case #PB_EventType_MouseLeave
             StopDrawing()
         EndSelect
       Case #CanvasGadget2
         Select EventType()
           Case #PB_EventType_MouseEnter
             StartDrawing(CanvasOutput(#CanvasGadget2))
           Case #PB_EventType_MouseMove
             ShowColourInfo(#CanvasGadget2)
           Case #PB_EventType_MouseLeave
             StopDrawing()
         EndSelect
     EndSelect
   Case #PB_Event_CloseWindow
     Exit = #True
 EndSelect
 
Until Exit
Bernd
Last edited by infratec on Tue May 13, 2014 9:13 am, edited 2 times in total.
heaven6502
User
User
Posts: 20
Joined: Mon Jan 26, 2009 1:43 pm

Re: loading images and mixing

Post by heaven6502 »

thx Bernd... got it... :)

good thing is that when inserting plot or line that the coordinates are based on the active canvas.
infratec
Always Here
Always Here
Posts: 7599
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: loading images and mixing

Post by infratec »

heaven6502 wrote:good thing is that when inserting plot or line that the coordinates are based on the active canvas.
But not as default, only because I programmed it this way. :wink:
Study the code carefully.

Bernd
infratec
Always Here
Always Here
Posts: 7599
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: loading images and mixing

Post by infratec »

Hi,

the code above was a 'quick hack'.
To show you how it should be, I modified the code from above.

It uses now EnableExplizit
It uses Enumeration
It frees the loaded images as soon as possible
It uses a Procedure for showing the result

Hope it helps you a bit for coding.

Bernd
Post Reply