Custom
 
选择自定义方法的Put图形语句的参数

语法

Put [ target , ] [ STEP ] ( x ,y ), source [ ,( x1 ,y1 )-( x2 ,y2 ) ], Custom, custom_function_ptr [, parameter ]

参数

Custom
需要。
custom_function_ptr
自定义用户定义函数的名称。
parameter
可选Pointer传递给自定义函数;如果省略,默认值为零(0)。

说明

Custom选择自定义用户定义的函数作为图像缓冲区的方法。

Custom方法使用用户定义的函数来计算要绘制到目标缓冲区的最终像素值。该函数将对源图像的每个像素调用一次,并将接收源和目标像素值以及由Put函数传递的数据指针。返回的像素值将是用于绘制到目标缓冲区的值。该函数的形式如下:

Declare Function identifier ( _
ByVal source_pixel As UInteger, _
ByVal destination_pixel As UInteger, _
ByVal parameter As Any Ptr _
) As UInteger


identifier 是该函数的名称。
source_pixel 是源图像的当前像素值。
destination_pixel 是目标图像的当前像素值。
parameter 是由Put命令传递的参数。如果省略,其值将为零。

例子

Function dither ( ByVal source_pixel As UInteger, ByVal destination_pixel As UInteger, ByVal parameter As Any Ptr ) As UInteger
    
    ''或者返回源像素或目标像素,具体取决于rnd的结果
    
    Dim threshold As Single = 0.5
    If parameter <> 0 Then threshold = *CPtr(Single Ptr, parameter)
    
    If Rnd() < threshold Then
        Return source_pixel
    Else
        Return destination_pixel
    End If
    
End Function


Dim img As Any Ptr, threshold As Single

''设置一个屏幕
ScreenRes 320, 200, 16, 2
ScreenSet 0, 1

''创建一个图像
img = ImageCreate(32, 32)
Line img, ( 0,  0)-(15,  15), RGB(255,   0,   0), bf
Line img, (16,  0)-(31,  15), RGB(  0,   0, 255), bf
Line img, ( 0, 16)-(15,  31), RGB(  0, 255,   0), bf
Line img, (16, 16)-(31,  31), RGB(255,   0, 255), bf

''抖动具有不同阈值的图像
Do Until Len(Inkey)
    
    Cls
    
    threshold = 0.2
    Put ( 80 - 16, 100 - 16), img, Custom, @dither, @threshold
    
    ''默认阈值= 0.5
    Put (160 - 16, 100 - 16), img, Custom, @dither
    
    threshold = 0.8
    Put (240 - 16, 100 - 16), img, Custom, @dither, @threshold
    
    ScreenCopy
    Sleep 25
    
Loop

''释放图像内存
ImageDestroy img



方言差异

与QB差别

  • 新的FreeBASIC

参考