Page 1 of 1

add loaded image to drawimage

Posted: Sat Mar 23, 2019 8:26 pm
by khalidel
hello all, i need your help. i want to add external image to drawing and i want to know what wrong with this code

Code: Select all

UseJPEGImageDecoder() 
LoadImage(0, "bouquet.jpg") ; image existing at the same folder

if CreateImage(1, 600, 600) and StartDrawing(ImageOutput(1))
      DrawingMode(#PB_2DDrawing_Transparent)
      Box(0, 0, 600, 600, RGB(255, 255, 255))
DrawImage(ImageID(0), 500, 500)
      StopDrawing() 
UseJPEGImageEncoder() 
SaveImage(1, GetCurrentDirectory() +"image.jpg", #PB_ImagePlugin_JPEG, 10)
MessageRequester("félicitation","l'Image JPEG est créée à l'emplacement courant", 0)
endif
i want to add loaded image to drawing. text can be added without problem.
thank you in advance

unRegistered version of purebasic 5.70 for win x86

Re: add loaded image to drawimage

Posted: Sat Mar 23, 2019 9:01 pm
by #NULL
It seems to work here. I get a saved image with the other one drawn onto it at some position. But I'm on Linux x64.

<edit>
welcome, btw :)

Re: add loaded image to drawimage

Posted: Sat Mar 23, 2019 9:28 pm
by khalidel
#NULL wrote:It seems to work here. I get a saved image with the other one drawn onto it at some position. But I'm on Linux x64.

<edit>
welcome, btw :)
thank you bro, i really don't know why my saved image cannot be drawn

Re: add loaded image to drawimage

Posted: Sat Mar 23, 2019 9:43 pm
by #NULL
Does the loading succeed? can you see it in the library viewer? (enable the debugger)

Code: Select all

UseJPEGImageDecoder()
LoadImage(0, "bouquet.jpg") ; image existing at the same folder

Debug IsImage(0)
ShowLibraryViewer("image", 0)
CallDebugger

If CreateImage(1, 600, 600) And StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0, 0, 600, 600, RGB(255, 255, 255))
  DrawImage(ImageID(0), 500, 500)
  StopDrawing()
  UseJPEGImageEncoder()
  SaveImage(1, GetCurrentDirectory() +"image.jpg", #PB_ImagePlugin_JPEG, 10)
  MessageRequester("félicitation","l'Image JPEG est créée à l'emplacement courant", 0)
EndIf

Re: add loaded image to drawimage

Posted: Sat Mar 23, 2019 10:22 pm
by khalidel
#NULL wrote:Does the loading succeed? can you see it in the library viewer? (enable the debugger)

Code: Select all

UseJPEGImageDecoder()
LoadImage(0, "bouquet.jpg") ; image existing at the same folder

Debug IsImage(0)
ShowLibraryViewer("image", 0)
CallDebugger

If CreateImage(1, 600, 600) And StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0, 0, 600, 600, RGB(255, 255, 255))
  DrawImage(ImageID(0), 500, 500)
  StopDrawing()
  UseJPEGImageEncoder()
  SaveImage(1, GetCurrentDirectory() +"image.jpg", #PB_ImagePlugin_JPEG, 10)
  MessageRequester("félicitation","l'Image JPEG est créée à l'emplacement courant", 0)
EndIf
i get the image identification code in memory which shows that the image is loaded correctly. thank you

Re: add loaded image to drawimage

Posted: Sat Mar 23, 2019 11:40 pm
by RASHAD
@khalidel
Try the next snippet
Your image will be saved into your Home Directory because maybe you are not authorized to Save in your Current Directory

Code: Select all

UseJPEGImageDecoder()
UseJPEGImageEncoder()
LoadImage(0, "bouquet.jpg")

If CreateImage(1, 600, 600,24,$FFFFFF)
  StartDrawing(ImageOutput(1))
    DrawImage(ImageID(0), 470, 480)
  StopDrawing()
  
  SaveImage(1, GetHomeDirectory() +"image.jpg", #PB_ImagePlugin_JPEG, 10)
  MessageRequester("félicitation","l'Image JPEG est créée à l'emplacement courant", 0)
EndIf

Re: add loaded image to drawimage

Posted: Sun Mar 24, 2019 12:52 am
by khalidel
RASHAD wrote:@khalidel
Try the next snippet
Your image will be saved into your Home Directory because maybe you are not authorized to Save in your Current Directory

Code: Select all

UseJPEGImageDecoder()
UseJPEGImageEncoder()
LoadImage(0, "bouquet.jpg")

If CreateImage(1, 600, 600,24,$FFFFFF)
  StartDrawing(ImageOutput(1))
    DrawImage(ImageID(0), 470, 480)
  StopDrawing()
  
  SaveImage(1, GetHomeDirectory() +"image.jpg", #PB_ImagePlugin_JPEG, 10)
  MessageRequester("félicitation","l'Image JPEG est créée à l'emplacement courant", 0)
EndIf
hello bro, i tested it but no working. working code is

Code: Select all

drawimage(imageid(0), 0, 0)
maybe there is a technical issue with my pb software

Re: add loaded image to drawimage

Posted: Sun Mar 24, 2019 1:18 am
by Bisonte
khalidel wrote:working code is

Code: Select all

drawimage(imageid(0), 0, 0)
maybe there is a technical issue with my pb software
No technical issue ;)

Syntax of DrawImage() ...

Code: Select all

DrawImage(ImageID, x, y [, NewWidth, NewHeight]) 
If you create an image with 600x600 px and you start drawing at 600.600 ... you draw out of the visible range ....

Re: add loaded image to drawimage

Posted: Sun Mar 24, 2019 6:23 am
by collectordave
When playing with images or drawings I allways prefer to see what is going on.

Create a window with an image gadget to load your created image. Allways run the code with debugger enabled.

This code creates a window loads bouquet.jpg shows what you have drawn then saves into the same folder as the original.

Code: Select all

UseJPEGImageDecoder()
UseJPEGImageEncoder()

Global Window_0

Global Image_0



  Window_0 = OpenWindow(#PB_Any, 0, 0, 650, 650, "", #PB_Window_SystemMenu)
  Image_0 = ImageGadget(#PB_Any, 5, 5, 600, 600, 0)
  
  
LoadImage(0, "bouquet.jpg") ; image existing at the same folder

;Image 0 is the bouquet

If CreateImage(1, 600, 600) And StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0, 0, 600, 600, RGB(0, 255, 0))
  
  ;Choose either of the two below
  
  ;Draw Bouquet image at original size in bottom right hand corner
  ;  DrawImage(ImageID(0), 500, 500)
  
  ;Draw Bouquet image resized in bottom right hand corner
  DrawImage(ImageID(0), 500, 500,100,100) 
  
  
  StopDrawing()
  
  
EndIf

SetGadgetState(Image_0,ImageID(1))


SaveImage(1, "Bouquet2.jpg")


Repeat
    
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
  EndSelect
  
  ForEver
I changed your box to green to see what is happening to the box.

Remember to create a folder for your programme as well then if you can edit the programme you can save there.

CD

Re: add loaded image to drawimage

Posted: Sun Mar 24, 2019 11:33 am
by khalidel
collectordave wrote:When playing with images or drawings I allways prefer to see what is going on.

Create a window with an image gadget to load your created image. Allways run the code with debugger enabled.

This code creates a window loads bouquet.jpg shows what you have drawn then saves into the same folder as the original.

Code: Select all

UseJPEGImageDecoder()
UseJPEGImageEncoder()

Global Window_0

Global Image_0



  Window_0 = OpenWindow(#PB_Any, 0, 0, 650, 650, "", #PB_Window_SystemMenu)
  Image_0 = ImageGadget(#PB_Any, 5, 5, 600, 600, 0)
  
  
LoadImage(0, "bouquet.jpg") ; image existing at the same folder

;Image 0 is the bouquet

If CreateImage(1, 600, 600) And StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0, 0, 600, 600, RGB(0, 255, 0))
  
  ;Choose either of the two below
  
  ;Draw Bouquet image at original size in bottom right hand corner
  ;  DrawImage(ImageID(0), 500, 500)
  
  ;Draw Bouquet image resized in bottom right hand corner
  DrawImage(ImageID(0), 500, 500,100,100) 
  
  
  StopDrawing()
  
  
EndIf

SetGadgetState(Image_0,ImageID(1))


SaveImage(1, "Bouquet2.jpg")


Repeat
    
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
  EndSelect
  
  ForEver
I changed your box to green to see what is happening to the box.

Remember to create a folder for your programme as well then if you can edit the programme you can save there.

CD
thank you all, problem solved

Code: Select all

drawimage(imageid(0), 0, 0, 500, 500)
all the best