Yes you can, using the drawDot command and a memblock image / bitmap.
I wrote a short example of doing just a viewport canvas that displays the screen (bitmap 0).
Set your program to run in a 640x480 window if you run this:
` Short example demonstrating canvas display of the screen
` Written by Rudolpho
` Note: requires blueGui
` Note2: While this indeed does work, it is unfortunately just too terribly slow to
` actually be useful :-(
` Declarations
#constant true 1
#constant false 0
#constant _n chr$(13) + chr$(10)
type screenType
width as dword
height as dword
endtype
type windows
main as dword
desktop as dword
canvas as dword
endtype
type canvases
viewport as dword
endtype
global win as windows
global screen as screentype
global canvas as canvases
startBlue "user", "key"
sync on
` Get desktop size
win.desktop = createGadgetFromWindow(desktopWindow())
screen.width = gadgetWidth(win.desktop)
screen.height = gadgetHeight(win.desktop)
win.main = createGadgetFromWindow(mainWindow())
` Set up an external window to hold the canvas gadget
win.canvas = createWindow((screen.width - 640) / 2, (screen.height - 480) / 2, 640, 480, "External viewport", 13565952, 128, true, 0)
` Create the viewport canvas
canvas.viewport = createCanvas(0, 0, 640, 480, win.canvas)
` How about the standard spinning cube demo?
make object cube 1, 50
while not escapekey()
yrotate object 1, wrapvalue(object angle y(1) + 0.5)
sync
` Draw the screen contents to the canvas viewport as well
drawBitmap(canvas.viewport, 0) ` The default screen is bitmap 0
paintGadget canvas.viewport
endwhile
end
` This function will draw the specified bitmap to the specified canvas gadget
function drawBitmap(canvas as dword, bitmap as dword)
local mem as dword : mem = findFreeMemblock()
` Construct a memblock from the bitmap to access its pixel data
make memblock from bitmap mem, bitmap
` Paste the bitmap contents onto the canvas gadget
` Note: if the bitmap and canvas dimensions differ, the image will be cut off
w = memblock dword(mem, 0)
h = memblock dword(mem, 4)
` Note: assuming a 32 bit bitmap; will not work with any other format
if memblock dword(mem, 8) <> 32
setDrawingColor canvas, 0, 0, 0x006700
drawRect canvas, 0, 0, gadgetClientWidth(canvas), gadgetClientHeight(canvas)
drawText canvas, 0, 0, "Invalid bitmap depth." + _n + "Please retry in 32-bit colour mode."
exitfunction
endif
` Draw the bitmap to the canvas
for x = 0 to (w - 1)
for y = 0 to (h - 1)
drawPoint canvas, x, y, memblock dword(mem, 12 + (((y * w) + x) * 4))
next y
next x
` Release the memblock
delete memblock mem
endfunction
` Replace with the matrix1utilities version if you have it; it would be a bit faster
function findFreeMemblock()
i = 0
m = rnd(254) + 1
while i < 255
if not memblock exist(m)
exitfunction m
else
m = _wrap(m + 1, 1, 255)
inc i
endif
endwhile
endfunction 0
` Replace with the matrix1utilities version if you have it; it would be a bit faster
function _wrap(value as integer, minValue as integer, maxValue as integer)
if value > maxValue
repeat
dec value, maxValue
until value <= maxValue
exitfunction value
else
if value < minValue
repeat
inc value, minValue
until value >= minValue
exitfunction value
endif
exitfunction value
endif
endfunction 0 ` We should never get here anyway
As you see though, it takes far too long to be useful.
It could possibly be used to display a small 128x128 display of motion though, but that's about it.
And hey, why don't we have access to the bitmap data by default; making the memblock takes half the time needed to do this procedure