Reading POINTs from an image, to draw on another.

Just starting out? Need help? Post your questions and find answers here.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Reading POINTs from an image, to draw on another.

Post by collectordave »

Mijikai wrote: Tue Aug 31, 2021 12:47 pm Isnt the DrawingBuffer() for images static?
The device context isnt but the buffer should be.
Not a question I would ask.

Just processing a single image seems quick enough for me.

Code: Select all

UseJPEGImageDecoder()

Global SourceImage.i,DisplayImage.i
Global FileName.s

Global PRed.i,PGreen.i,PBlue.i

OpenWindow(0,0,0,1600,560, "ImageCopyCols")
CreateImage(1,800,560)
ImageGadget(0, 0, 0,800, 560,0)
ImageGadget(1, 800, 0,800, 560,0)

Filename = OpenFileRequester("Select Image","*.*","*.*",1)

SourceImage = LoadImage(#PB_Any,Filename)


DisplayImage = CopyImage(SourceImage,#PB_Any)




StartDrawing(ImageOutput(DisplayImage))
For y=0 To ImageHeight(DisplayImage) - 1
  For x=0 To ImageWidth(DisplayImage) - 1
     f=Point(x,y)
     
     ;Process F here
     
     ;Increase red to maximum
     PRed = 255
     PGreen = Green(f)
     PBlue = Blue(f)
     
     f = RGB(PRed,Pgreen,PBlue)
     
     
     Plot(x,y,f)
   Next x
 Next y
   
 StopDrawing()
SetGadgetState(0,ImageID(SourceImage))
SetGadgetState(1,ImageID(DisplayImage))

Repeat
  windowevent=WaitWindowEvent()
  Until windowevent=#PB_Event_CloseWindow
  
  
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.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Reading POINTs from an image, to draw on another.

Post by collectordave »

Another example.

If the user wants to put a smaller greyscale image inside the original image it can be done like this.

Code: Select all

UseJPEGImageDecoder()

Global SourceImage.i,DisplayImage.i,NewImage.i
Global FileName.s

Global PRed.i,PGreen.i,PBlue.i

OpenWindow(0,0,0,1600,560, "ImageCopyCols")
CreateImage(1,800,560)
ImageGadget(0, 0, 0,800, 560,0)
ImageGadget(1, 800, 0,800, 560,0)

Filename = OpenFileRequester("Select Image","*.*","*.*",1)

SourceImage = LoadImage(#PB_Any,Filename)

DisplayImage = CopyImage(SourceImage,#PB_Any)

StartDrawing(ImageOutput(DisplayImage))
For y=0 To ImageHeight(DisplayImage) - 1
  For x=0 To ImageWidth(DisplayImage) - 1
     f=Point(x,y)
     
     ;Process F here

     PRed = Red(f)
     PGreen = Green(f)
     PBlue = Blue(f)
     
     Average = (PRed + PGreen + PBlue)/3

     f = RGB(Average,Average,Average)

     Plot(x,y,f)
   Next x
 Next y
   
 StopDrawing()
 
ResizeImage(DisplayImage,ImageWidth(SourceImage)/4,ImageHeight(SourceImage) / 4)
 
StartDrawing(ImageOutput(SourceImage))
  DrawImage(ImageID(DisplayImage),0,0) 
StopDrawing()

 
SetGadgetState(0,ImageID(SourceImage))
SetGadgetState(1,ImageID(DisplayImage))

Repeat
  windowevent=WaitWindowEvent()
  Until windowevent=#PB_Event_CloseWindow

Note not true greyscale just a quick lump of code so forgive the placing of the image gadgets if you use a big image.
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.
BarryG
Addict
Addict
Posts: 3294
Joined: Thu Apr 18, 2019 8:17 am

Re: Reading POINTs from an image, to draw on another.

Post by BarryG »

matalog wrote: Sat Aug 28, 2021 11:25 pmIs it possible, to say load a previously made image, it does not have to be viewable on screen. Then read POINT colours of that image, and then use that information to draw on another new blank image?
That's what the GrabImage() command does. No need for a For/Next loop with grabbing pixels from the old image and plotting them to the new.
Post Reply