Page 1 of 1

[SOLVED] Copy and paste a graphic patch??

Posted: Tue Mar 11, 2025 12:48 am
by Randy Walker
This block of code works fine until I un-comment that DrawImage line. Trying to copy a patch of the image using GrabImage and paste it using DrawImage. Maybe using the wrong commands.

Code: Select all

#MainImage = 0
If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If CreateImage(#MainImage, 200, 200) And StartDrawing(ImageOutput(#MainImage))
      Box(0, 0, 200, 200, RGB(255, 255, 255))
      For Width = 1 To 200 Step 5
        Line(10, 10, Width, 180, RGB(Random(255), Random(255), Random(255)))
      Next Width
      For height = 1 To 200 Step 5
        Line(10, 10, 200, height, RGB(Random(255), Random(255), Random(255)))
      Next height
      patch = GrabImage(#MainImage,1,10,10,100,35)
  ;    DrawImage(1,100,10)
      StopDrawing() 
      ImageGadget(0, 0, 0, 200, 200, ImageID(#MainImage))
    EndIf
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
What am I doing wrong? Anyone?

Re: Copy and paste a graphic patch??

Posted: Tue Mar 11, 2025 12:58 am
by Mijikai
Try this:

Code: Select all

 DrawImage(ImageID(1),100,10);<- added ImageID()

Re: Copy and paste a graphic patch??

Posted: Tue Mar 11, 2025 1:13 am
by Randy Walker
Mijikai wrote: Tue Mar 11, 2025 12:58 am Try this:

Code: Select all

 DrawImage(ImageID(1),100,10);<- added ImageID()
Ok the error is gone now but paste is all black -- not what I tried to copy using GrabImage().
Thanks Mijikai

Re: Copy and paste a graphic patch??

Posted: Tue Mar 11, 2025 1:58 am
by RASHAD
OK :)

Code: Select all

#MainImage = 0
If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If CreateImage(#MainImage, 200, 200) 
      StartDrawing(ImageOutput(#MainImage))
      Box(0, 0, 200, 200, RGB(255, 255, 255))
      For Width = 1 To 200 Step 5
        Line(10, 10, Width, 180, RGB(Random(255), Random(255), Random(255)))
      Next Width
      For height = 1 To 200 Step 5
        Line(10, 10, 200, height, RGB(Random(255), Random(255), Random(255)))
      Next height           
      StopDrawing() 
      GrabImage(#MainImage,1,10,10,100,35) 
      StartDrawing(ImageOutput(#MainImage))
        DrawImage(ImageID(1),100,10)
      StopDrawing()
      FreeImage(1) 
      ImageGadget(0, 0, 0, 200, 200, ImageID(#MainImage))
    EndIf
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
OR :

Code: Select all

#MainImage = 0
If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If CreateImage(#MainImage, 200, 200) 
      StartDrawing(ImageOutput(#MainImage))
      Box(0, 0, 200, 200, RGB(255, 255, 255))
      For Width = 1 To 200 Step 5
        Line(10, 10, Width, 180, RGB(Random(255), Random(255), Random(255)))
      Next Width
      For height = 1 To 200 Step 5
        Line(10, 10, 200, height, RGB(Random(255), Random(255), Random(255)))
      Next height 
      GrabDrawingImage(1,10,10,100,35) 
      DrawImage(ImageID(1),100,10)    
      StopDrawing() 

      ImageGadget(0, 0, 0, 200, 200, ImageID(#MainImage))
    EndIf
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf

Re: Copy and paste a graphic patch??

Posted: Tue Mar 11, 2025 2:22 am
by Randy Walker
RASHAD wrote: Tue Mar 11, 2025 1:58 am OK :)
So the trick is to stop drawing before you grab, and start new drawing to paste. Tricky stuff.

RASHAD, You did it again. If only I had even half your brain capacity, these things you teach me might be more obvious.
THANKS AGAIN!!!! wow!

Re: [SOLVED] Copy and paste a graphic patch??

Posted: Tue Mar 11, 2025 2:36 am
by RASHAD
Hi Randy
I don't think I have a brain different from yours :)
Only I memories PB commands
You have 2 alternatives
1- GrabImage(#Image1, #Image2, x, y, Width, Height)
To create an image from another image
2 - GrabDrawingImage(#Image, x, y, Width, Height)
To create an image from another drawing buffer (the device context area)

Have fun

Re: [SOLVED] Copy and paste a graphic patch??

Posted: Tue Mar 11, 2025 6:58 am
by Randy Walker
Hi RASHAD,

Yeah I tried both, but best I could get before you saved me was a black block when I pasted my image.
Coding was always a challenge for me. Didn't help any to have them extract "a mass" from my brain, leaving a cavity about the size of the average doorknob (5 cm). Yeah, it's different.