PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Drawing with dTransferToImage
dTransferToImage (Example)
Drawing with dTransferToImage
This example is used to create the different arrays of pixels corresponding to the requested type of image and to display them in Image controls.
iImage1 is Image
iImage2 is Image
arrPixels is array of * by * unsigned int on 1
arrPixels_dImageToArray is array of * by * int
nX, nY are int
nConstant is int
 
iImage1..Width = IMG_InitialDrawing..Width
iImage1..Height = IMG_InitialDrawing..Height
nConstant = GetOptionsTransferToImage()
bOpacity is boolean = (nConstant=imgBGRA)
 
dStartDrawing(iImage1, dErase + (bOpacity? dWithOpacity ELSE 0))
IF bOpacity THEN
dBackground(White, 0, 0, 255); dPen(White, 0, 1, 255)
dRectangle(1, 1, iImage1..Width, iImage1..Height)
dBackground(Transparent, 0, 0, 255); dPen(LightRed, 0, 1, 255)
dRectangle(5, 5, iImage1..Width-5, iImage1..Height-5)
dBackground(LightYellow, 0, 0, 128); dPen(LightBlue, 0, 10, 128)
dCircle(20 ,50,iImage1..Width-20, iImage1..Height-50)
dBackground(PastelGreen, 0, 0, 128); dPen(LightRed, 0, 10, 128)
dCircle(45, 75, 95, 125)
ELSE
dBackground(White, 0, 0); dPen(LightBlue, 0, 1)
dRectangle(1, 1, iImage1..Width, iImage1..Height)
dBackground(Transparent, 0, 0); dPen(LightRed, 0, 1)
dRectangle(5, 5, iImage1..Width-5, iImage1..Height-5)
dBackground(LightYellow, 0, 0); dPen(LightBlue, 0, 10)
dCircle(20,50,iImage1..Width-20, iImage1..Height-50)
dBackground(PastelGreen, 0, 0); dPen(LightRed, 0, 10)
dCircle(45, 75, 95, 125)
END
IMG_InitialDrawing = iImage1
 
// Fill the array of pixels
SWITCH nConstant
CASE imgBGRA
Dimension(arrPixels, iImage1..Width, iImage1..Height*4)
CASE imgBGR32
Dimension(arrPixels, iImage1..Width, iImage1..Height*4)
CASE imgBGR
Dimension(arrPixels, iImage1..Width, iImage1..Height*3)
CASE imgRGB32
Dimension(arrPixels, iImage1..Width, iImage1..Height*4)
bufBuffer is Buffer = dSaveImagePNG(iImage1, inMemory)
dImageToArray(bufBuffer, arrPixels_dImageToArray, dComponentRGB)
END
 
FOR nX = 1 _TO_ iImage1..Width
FOR nY = 1 _TO_ iImage1..Height
SWITCH nConstant
CASE imgBGRA
arrPixels[nX,((nY-1)*4)+1] = iImage1.Pixel[nX,nY]..Blue
arrPixels[nX,((nY-1)*4)+2] = iImage1.Pixel[nX,nY]..Green
arrPixels[nX,((nY-1)*4)+3] = iImage1.Pixel[nX,nY]..Red
arrPixels[nX,((nY-1)*4)+4] = iImage1.Pixel[nX,nY]..Opacity
CASE imgBGR32
arrPixels[nX,((nY-1)*4)+1] = iImage1.Pixel[nX,nY]..Blue
arrPixels[nX,((nY-1)*4)+2] = iImage1.Pixel[nX,nY]..Green
arrPixels[nX,((nY-1)*4)+3] = iImage1.Pixel[nX,nY]..Red
arrPixels[nX,((nY-1)*4)+4] = 255
CASE imgBGR
arrPixels[nX,((nY-1)*3)+1] = iImage1.Pixel[nX,nY]..Blue
arrPixels[nX,((nY-1)*3)+2] = iImage1.Pixel[nX,nY]..Green
arrPixels[nX,((nY-1)*3)+3] = iImage1.Pixel[nX,nY]..Red
CASE imgRGB32
arrPixels[nX,((nY-1)*4)+1] = iImage1.Pixel[nX,nY]..Red
arrPixels[nX,((nY-1)*4)+2] = iImage1.Pixel[nX,nY]..Green
arrPixels[nX,((nY-1)*4)+3] = iImage1.Pixel[nX,nY]..Blue
arrPixels[nX,((nY-1)*4)+4] = 255
END
END
END
 
 
// arrPixels array to the Image2 variable
IF nConstant = imgRGB32 THEN
iImage2 = dTransferToImage(&arrPixels_dImageToArray, nConstant, ...
iImage1..Width, iImage1..Height)
ELSE
iImage2 = dTransferToImage(&arrPixels, nConstant, iImage1..Width, ...
iImage1..Height)
END
IMG_TransferToImage = iImage2
Minimum version required
  • Version 17
This page is also available for…
Comments
Click [Add] to post a comment