Example:

Can PB do this through code?
Absolutely.coder14 wrote:Can PB do this through code?
Code: Select all
; Fading reflection effect
; Authors: Lloyd Gallant (netmaestro), Wilbert, #NULL
; January 30, 2017
file$ = GetTemporaryDirectory()+"test_camera.png"
InitNetwork()
If FileSize(file$) = -1
If Not ReceiveHTTPFile("http://www.lloydsplace.com/camera.png", file$)
MessageRequester("oops!","Problem getting image... quitting")
EndIf
EndIf
UsePNGImageDecoder()
LoadImage(0, file$)
Global w=ImageWidth(0)
Global h=ImageHeight(0)
; Create image with reflection
CreateImage(1, w, h << 1, 32, #PB_Image_Transparent)
StartDrawing(ImageOutput(1))
DrawAlphaImage(ImageID(0),0,0)
For y = 0 To h - 1
ClipOutput(0, h + y, w, 1)
ease.d = y / h
ease = 1 - Pow( (1-ease), 5) ; change exponent for fadeout pace
alpha.d = 255 - ease * 255
DrawAlphaImage(ImageID(0), 0, y * 2, Int(alpha))
Next
StopDrawing()
OpenWindow(0,0,0,w,h << 1,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,0,0,ImageID(1))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Code: Select all
Procedure FlipBufferRows(hImg)
Protected *pbuf, *psrc, *ptmp, *pdst, width, height, i
If StartDrawing(ImageOutput(hImg))
*pbuf = DrawingBuffer()
width = DrawingBufferPitch() ;check padding
height = ImageHeight(hImg)
*psrc = *pbuf
*ptmp = AllocateMemory(width*height) ;Temp buffer to write rows in reverse order
If *ptmp
*pdst = *ptmp + (width*height)-width
For i = 0 To height-1
CopyMemory(*psrc, *pdst, width)
*pdst-width
*psrc+width
Next i
CopyMemory(*ptmp, *pbuf, width*height) ;Overwrite existing buffer with flipped buffer
FreeMemory(*ptmp) ;Free temp buffer
EndIf
StopDrawing()
EndIf
EndProcedure
Code: Select all
ease.d = y / h
ease = 1 - Pow( (1-ease), 4) ; change exponent for fadeout pace
alpha.d = 255 - ease * 255
Code: Select all
file$ = GetTemporaryDirectory()+"test_camera.png"
InitNetwork()
If FileSize(file$) = -1
If Not ReceiveHTTPFile("http://www.lloydsplace.com/camera.png", file$)
MessageRequester("oops!","Problem getting image... quitting")
EndIf
EndIf
UsePNGImageDecoder()
LoadImage(0, file$)
Global w=ImageWidth(0)
Global h=ImageHeight(0)
; Create image with reflection
CreateImage(1, w, h << 1, 32, #PB_Image_Transparent)
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_AllChannels)
DrawAlphaImage(ImageID(0),0,0)
For y = 1 To h
GrabDrawingImage(2, 0, h - y, w, 1)
DrawAlphaImage(ImageID(2), 0, h + y - 1, 255 - 255 * y / h)
Next
FreeImage(2)
StopDrawing()
OpenWindow(0,0,0,w,h << 1,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,0,0,ImageID(1))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Code: Select all
file$ = GetTemporaryDirectory()+"test_camera.png"
InitNetwork()
If FileSize(file$) = -1
If Not ReceiveHTTPFile("http://www.lloydsplace.com/camera.png", file$)
MessageRequester("oops!","Problem getting image... quitting")
EndIf
EndIf
UsePNGImageDecoder()
LoadImage(0, file$)
Global w=ImageWidth(0)
Global h=ImageHeight(0)
; Create image with reflection
CreateImage(1, w, h << 1, 32, #PB_Image_Transparent)
StartDrawing(ImageOutput(1))
DrawAlphaImage(ImageID(0),0,0)
For y = 0 To h - 1
ClipOutput(0, h + y, w, 1)
DrawAlphaImage(ImageID(0), 0, y * 2, 255 - 255 * y / h)
Next
StopDrawing()
OpenWindow(0,0,0,w,h << 1,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,0,0,ImageID(1))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
DrabDrawingImage is a little-known and undocumented PureBasic command for rendering boring and uninspiring images. I'm surprised you knew about it. It's faster but it just doesn't care if it works or not. It's profoundly depressed and keeps trying to deprecate itself. Maybe one day it'll succeed.wilbert wrote:using ClipOutput seems to be faster compared to using DrabDrawingImage.
Should have been Grab of coursenetmaestro wrote:DrabDrawingImage
Code: Select all
; Fading reflection effect
; Authors: Lloyd Gallant (netmaestro), Wilbert, #NULL
; January 30, 2017
file$ = GetTemporaryDirectory()+"test_camera.png"
InitNetwork()
If FileSize(file$) = -1
If Not ReceiveHTTPFile("http://www.lloydsplace.com/camera.png", file$)
MessageRequester("oops!","Problem getting image... quitting")
EndIf
EndIf
UsePNGImageDecoder()
LoadImage(0, file$)
Global w=ImageWidth(0)
Global h=ImageHeight(0)
Procedure Image_Rotate(Image,Angle)
nimgw = h*Sin(Angle*#PI/180)+w*Cos(Angle*#PI/180)
nimgh = w*Sin(Angle*#PI/180) + h*Cos(Angle*#PI/180)
temp=CreateImage(#PB_Any,nimgw,nimgh)
Dim p.Point(2)
p(0)\x=0
p(0)\y=nimgh
p(1)\x=nimgw
p(1)\y=nimgh
p(2)\x=0
p(2)\y=0
ImageDc = CreateCompatibleDC_(0)
SelectObject_(ImageDc,ImageID(Image))
dc=StartDrawing(ImageOutput(temp))
PlgBlt_(dc,@p(),ImageDc,0,0,w,h,0,0,0)
StopDrawing()
CopyImage(temp,image)
FreeImage(temp)
EndProcedure
CopyImage(0,10)
Image_Rotate(10,0)
op = 130 ;Change to increease or decrease the reflection size
; Create image with reflection
CreateImage(1, w, h, 32, #PB_Image_Transparent)
StartDrawing(ImageOutput(1))
For y = 0 To h - 1
GrabImage(10,2,0,y,w,1)
DrawAlphaImage(ImageID(2),0,y,op)
op - 1
If op < 0
op = 0
EndIf
Next
StopDrawing()
FreeImage(2)
FreeImage(10)
OpenWindow(0,0,0,w,h << 1,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,w,h,ImageID(0))
ImageGadget(1,0,h,w,h,ImageID(1))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Code: Select all
; Fading reflection effect
; Authors: Lloyd Gallant (netmaestro), Wilbert, #NULL
; January 30, 2017
file$ = GetTemporaryDirectory()+"test_camera.png"
InitNetwork()
If FileSize(file$) = -1
If Not ReceiveHTTPFile("http://www.lloydsplace.com/camera.png", file$)
MessageRequester("oops!","Problem getting image... quitting")
EndIf
EndIf
UsePNGImageDecoder()
LoadImage(0, file$)
Global w=ImageWidth(0)
Global h=ImageHeight(0)
Global trcolor = $FFFFFF
Procedure TransPNG(img,trcolor)
CopyImage(0,1)
StartDrawing(ImageOutput(1))
For x = 0 To w - 1
For y = 0 To h - 1
DrawingMode(#PB_2DDrawing_Default )
If Point(x,y) = trcolor
DrawingMode(#PB_2DDrawing_AllChannels )
Plot(x,y,RGBA(255, 255, 255,0))
EndIf
Next
Next
StopDrawing()
ProcedureReturn 1
EndProcedure
Procedure flipVal(img)
fimg = CreateImage(#PB_Any,w,h,32,trcolor)
StartVectorDrawing(ImageVectorOutput(fimg))
ResetCoordinates()
MovePathCursor(0,h)
FlipCoordinatesY(180)
DrawVectorImage(ImageID(img), 255)
StopVectorDrawing()
ProcedureReturn fimg
EndProcedure
TransPNG(0,#White)
fimg = flipVal(1)
op = 130 ;Change to increease or decrease the reflection size
; Create image with reflection
CreateImage(2, w, h, 32, #PB_Image_Transparent)
StartDrawing(ImageOutput(2))
For y = 0 To h - 1
GrabImage(fimg,3,0,y,w,1)
DrawAlphaImage(ImageID(3),0,y,op)
op - 1
If op < 0
op = 0
EndIf
Next
StopDrawing()
FreeImage(1)
FreeImage(3)
FreeImage(fimg)
OpenWindow(0,0,0,w,h << 1,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,w,h,ImageID(0))
ImageGadget(1,0,h,w,h,ImageID(2))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow