[SOLVED] Copy and paste a graphic patch??

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

[SOLVED] Copy and paste a graphic patch??

Post 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?
Last edited by Randy Walker on Tue Mar 11, 2025 2:23 am, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: Copy and paste a graphic patch??

Post by Mijikai »

Try this:

Code: Select all

 DrawImage(ImageID(1),100,10);<- added ImageID()
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Copy and paste a graphic patch??

Post 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
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Copy and paste a graphic patch??

Post 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
Egypt my love
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Copy and paste a graphic patch??

Post 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!
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

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

Post 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
Egypt my love
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

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

Post 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.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply