The following code reads a artdrawing bmp file and you can color the picture, thanks to Kale and Paul.
But if you select a new file and already filled a color the whole screen is painted as the selected color.
I cannot find the problem, can someone help !
You can use the following file
http://www.chordplanet.com/purebasic/auto.gif
Please convert it to an bmp file
Code: Select all
Global ratio.f,himage.f,vimage.f,CurrentWidth.l,CurrentHeight.l,CurrentColor.l
Global appdir$
Global fotogeladen.b
fotogeladen=0
CurrentColor=RGB(255,255,255)
;- Gadget Constants
;
#btnFileOpen = 0
#btnBlack = 1
#btnWhite = 2
#imgPicture = 10
;- Image Globals
Global Image0
Global Image1
;- Catch Images
Image0 = CatchImage(0, ?Image0)
Image1 = CatchImage(1, ?Image1)
;- Images
DataSection
Image0:
IncludeBinary "P:\cor\purebasic\ontwikkel\colorbook\black.bmp"
Image1:
IncludeBinary "P:\cor\purebasic\ontwikkel\colorbook\blue.bmp"
EndDataSection
;Get app's directory.
appdir$=Space(255)
GetCurrentDirectory_(255,appdir$)
If Right(appdir$,1)"\"
appdir$=appdir$+"\"
EndIf
;LoadImage(100,"barbie.bmp")
;LoadImage(2,"bg.bmp")
Procedure WindowCallback(WindowID, Message, lParam, wParam)
If Message = #WM_PAINT And fotogeladen=1
StartDrawing(WindowOutput())
Line (0,40,WindowWidth(),0, RGB(0,0,0) )
; DrawImage(UseImage(100), 0, 45)
StopDrawing()
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(1,0,0,ImageWidth(),ImageHeight()+45,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"")
ShowWindow_(WindowID(),#SW_MAXIMIZE)
SetWindowCallback(@WindowCallback())
If CreateGadgetList(WindowID())
ButtonGadget(#btnFileOpen, 5, 5, 55, 30, "File Open")
ButtonImageGadget(#btnBlack, 75, 5, 55, 30, Image0)
ButtonImageGadget(#btnWhite, 140, 5, 55, 30, Image1)
ImageGadget(#imgPicture,0,MenuHeight()+45,-1,-1,Image1)
EndIf
Repeat
EventId=WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case #btnFileOpen
FileName$ = OpenFileRequester("Laad tekening", appdir$, "Texte file | *.bmp", "0")
If FileName$ ""
LoadImage(100,FileName$)
SetGadgetState(#imgPicture, UseImage(100))
ResizeGadget(#imgPicture, -1, -1, ImageWidth(), ImageHeight() )
fotogeladen=1
EndIf
Case #btnBlack
CurrentColor=RGB(0,0,0)
Case #btnWhite
CurrentColor=RGB(0,0,255)
EndSelect
EndIf
If EventId=#WM_LBUTTONUP And fotogeladen=1
StartDrawing(WindowOutput())
FillArea(WindowMouseX(),WindowMouseY()-MenuHeight(),RGB(0,0,0),CurrentColor)
StopDrawing()
EndIf
Until eventid=#PB_Event_CloseWindow
EndIf
End
; ExecutableFormat=Windows
; EOF
Registered Purebasic
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
http://www.chordplanet.com
