add loaded image to drawimage

Just starting out? Need help? Post your questions and find answers here.
khalidel
User
User
Posts: 17
Joined: Sat Mar 23, 2019 7:45 pm

add loaded image to drawimage

Post 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
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: add loaded image to drawimage

Post 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 :)
khalidel
User
User
Posts: 17
Joined: Sat Mar 23, 2019 7:45 pm

Re: add loaded image to drawimage

Post 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
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: add loaded image to drawimage

Post 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
khalidel
User
User
Posts: 17
Joined: Sat Mar 23, 2019 7:45 pm

Re: add loaded image to drawimage

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: add loaded image to drawimage

Post 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
Egypt my love
khalidel
User
User
Posts: 17
Joined: Sat Mar 23, 2019 7:45 pm

Re: add loaded image to drawimage

Post 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
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: add loaded image to drawimage

Post 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 ....
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: add loaded image to drawimage

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
khalidel
User
User
Posts: 17
Joined: Sat Mar 23, 2019 7:45 pm

Re: add loaded image to drawimage

Post 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
Post Reply