Platforms to show: All Mac Windows Linux Cross-Platform

Back to Picture class.

Picture.CopyRtoMemoryblockMBS(destination as memoryblock, offset as Integer, PixelByteSize as Integer, StartLine as Integer = 0, EndLine as Integer = -1, Yield as Integer = 0, DestRowBytes as Integer = 0) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Graphics & Pictures MBS Picture Plugin 5.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Copies raw image data into a memoryblock.
Example
const kAlphaOffset=0 ' (BigEndian) and 3 (LittleEndian)
dim m as MemoryBlock
dim p as Picture

p=New Picture(100,100,32)
p.Graphics.ForeColor=rgb(255,128,1)
p.Graphics.FillRect 0,0,100,100
p.mask.Graphics.ForeColor=rgb(127,127,127)
p.mask.Graphics.FillRect 0,0,100,100

// Make a new MemoryBlock
m=NewMemoryBlock(100*100*4) // 4 bytes per Pixel

// copy RGB and leave room for alpha
if p.CopyARGBtoMemoryblockMBS(m,0,false,-1) then
MsgBox EncodingToHexMBS(m.StringValue(0,99))
end if

// copy Red channel from mask image into Memoryblock
if p.mask.CopyRtoMemoryblockMBS(m,kAlphaOffset,4) then
MsgBox EncodingToHexMBS(m.StringValue(0,99))
end if

Returns true on success.
destination should not be nil.
offset should be 0 or bigger and is the start position in the memoryblock.
PixelByteSize is normally 4 for 32bit per Pixel.
By using a different offset you can have this function working correctly on non BigEndian platforms.
The function will crash if the memoryblock is too small. Needs picture.width*picture.height*PixelByteSize bytes in the memoryblock.
Mask images in RB are all gray so it does not matter which channel you copy to get the alpha channel. This function takes the red channel from the source image.

This method was written for speed, so the creation of the memoryblock is your part. You can of course reuse memoryblocks for batch processing images as long as the memoryblock is big enough.

StartLine and Endline define the range of source lines from picture. Range is from 0 to picture.height-1. if Endline is -1, we use picture.height-1 internally. Yield specifies how much CPU time is given to other threads. If yield = 0, we give no CPU time away. If yield is > 0, we yield every yield/60th second to other threads. If DestRowBytes is not zero, it specifies the bytes per row in the target memoryblock for each line.

The items on this page are in the following plugins: MBS Picture Plugin.


The biggest plugin in space...