For all the samples that I'll provide the vfpx logo will be drawn in some bigger pictures. to show all the flexibility that Gdi+ can offer to us, some effects will be aplied to the logo.
Important
Please make sure that you have the latest version!
https://github.com/VFPX/GDIPlusX
sample 5:
aply 100% transparency to the white color, to eliminate the background
draw the logo aplying predefined colormatrix that will the following transformation: convert to greyscale 50% transparency to the whole image
position: top left
do locfile("system.app") with _screen.system.drawing as xfcdrawing
local lcmainpict, lclogopictlocal lomainbmp as xfcbitmaplocal lologobmp as xfcbitmaplocal logfx as xfcgraphics
lcmainpict = getpict()
lclogopict = getpict()
lomainbmp = .bitmap.fromfile(lcmainpict)
lologobmp = .bitmap.fromfile(lclogopict)
logfx = .graphics.fromimage(lomainbmp)
*!* sample 5
*!* aply 100% transparency to the white color, to eliminate the background
*!* draw the logo aplying predefined colormatrix that will
*!* the following transformation: convert to greyscale 50% transparency to the whole image
*!* position: top left
* first step: eliminate the white backgroundlologobmp.maketransparent(.color.white)
* define the transparency ratio that will be aplied
* this parameter ranges from 0 (totally transparent) to 1 (totally opaque)local lntranspratio
lntranspratio = 0.50 && 50%
* create a colormatrix that will have the transformations information
* the position (4,4) of the matrix is responsible for the opacity local loclrmatrix as xfccolormatrix
loclrmatrix = .imaging.colormatrix.new( ;
0.33, 0.33, 0.33, 0 , 0, ;
0.33, 0.33, 0.33, 0 , 0, ;
0.33, 0.33, 0.33, 0 , 0, ;
0, 0, 0, lntranspratio, 0, ;
0, 0, 0, 0 , 0)
* create an image attributes object to create the effects based in our clrmatrixlocal loattr as xfcimageattributes
loattr = .imaging.imageattributes.new()
loattr.setcolormatrix(loclrmatrix)
* we need to create a rectangle that will contain the coordinates and size of the transformed logolocal lorect as xfcrectangle
lorect = .rectangle.new()
lorect.x = 0
lorect.y = 0
lorect.width = lologobmp.widthlorect.height = lologobmp.height * draw the transformed image using the rectangle and imgattributes/clrmatrixlogfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
lomainbmp.save("c:\logo5.jpg", .imaging.imageformat.jpeg)run /n explorer.exe c:\logo5.jpgendwith
return
sample 6:
aply 100% transparency to the white color, to eliminate the background
draw the logo aplying predefined colormatrix that will convert to greyscale and 50% transparency to the whole image
position: center
size: expanded 4 times
do locfile("system.app")
with _screen.system.drawing as xfcdrawing
local lcmainpict, lclogopictlocal lomainbmp as xfcbitmaplocal lologobmp as xfcbitmaplocal logfx as xfcgraphics
lcmainpict = getpict()
lclogopict = getpict()
lomainbmp = .bitmap.fromfile(lcmainpict)
lologobmp = .bitmap.fromfile(lclogopict)
logfx = .graphics.fromimage(lomainbmp)
*!* sample 6
*!* aply 100% transparency to the white color, to eliminate the background
*!* draw the logo aplying predefined colormatrix that will
*!* the following transformation: convert to greyscale 50% transparency to the whole image
*!* position: center
*!* size: expanded 4 times
* first step: eliminate the white backgroundlologobmp.maketransparent(.color.white)
* define the transparency ratio that will be aplied
* this parameter ranges from 0 (totally transparent) to 1 (totally opaque)local lntranspratio
lntranspratio = 0.25 && 25%
* create a colormatrix that will have the transformations information
* the position (4,4) of the matrix is responsible for the opacity local loclrmatrix as xfccolormatrix
loclrmatrix = .imaging.colormatrix.new( ;
0.33, 0.33, 0.33, 0 , 0, ;
0.33, 0.33, 0.33, 0 , 0, ;
0.33, 0.33, 0.33, 0 , 0, ;
0, 0, 0, lntranspratio, 0, ;
0, 0, 0, 0 , 0)
* create an image attributes object to create the effects based in our clrmatrixlocal loattr as xfcimageattributes
loattr = .imaging.imageattributes.new()
loattr.setcolormatrix(loclrmatrix)
* we need to create a rectangle that will contain the coordinates and size of the transformed logolocal lorect as xfcrectangle
lorect = .rectangle.new()
lorect.x = (lomainbmp.width - lologobmp.width*4) / 2
lorect.y = (lomainbmp.height - lologobmp.height*4) / 2
lorect.width = lologobmp.width * 4
lorect.height = lologobmp.height * 4* draw the transformed image using the rectangle and imgattributes/clrmatrixlogfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
lomainbmp.save("c:\logo6.jpg", .imaging.imageformat.jpeg)
run /n explorer.exe c:\logo6.jpgendwith
return
sample 7:
aply 100% transparency to the white color, to eliminate the background
draw the logo aplying 25% opacity to the whole image
position: center
size: expanded 4 times
do locfile("system.app")
with _screen.system.drawing as xfcdrawing
local lcmainpict, lclogopictlocal lomainbmp as xfcbitmaplocal lologobmp as xfcbitmaplocal logfx as xfcgraphics
lcmainpict = getpict()
lclogopict = getpict()
lomainbmp = .bitmap.fromfile(lcmainpict)
lologobmp = .bitmap.fromfile(lclogopict)
logfx = .graphics.fromimage(lomainbmp)
*!* sample 7
*!* aply 100% transparency to the white color, to eliminate the background
*!* draw the logo aplying 25% opacity to the whole image
*!* position: center
*!* size: expanded 4 times
* first step: eliminate the white backgroundlologobmp.maketransparent(.color.white)
* define the transparency ratio that will be aplied
* this parameter ranges from 0 (totally transparent) to 1 (totally opaque)local lntranspratio
lntranspratio = 0.25 && 25%
* create a colormatrix that will have the transformations information
* the position (4,4) of the matrix is responsible for the opacity local loclrmatrix as xfccolormatrix
loclrmatrix = .imaging.colormatrix.new( ;
1, 0, 0, 0 , 0, ;
0, 1, 0, 0 , 0, ;
0, 0, 1, 0 , 0, ;
0, 0, 0, lntranspratio, 0, ;
0, 0, 0, 0 , 0)
* create an image attributes object to create the effects based in our clrmatrixlocal loattr as xfcimageattributes
loattr = .imaging.imageattributes.new()
loattr.setcolormatrix(loclrmatrix)
* we need to create a rectangle that will contain the coordinates and size of the transformed logolocal lorect as xfcrectangle
lorect = .rectangle.new()
lorect.x = (lomainbmp.width - lologobmp.width*4) / 2
lorect.y = (lomainbmp.height - lologobmp.height*4) / 2
lorect.width = lologobmp.width * 4
lorect.height = lologobmp.height * 4* draw the transformed image using the rectangle and imgattributes/clrmatrixlogfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
lomainbmp.save("c:\logo7.jpg", .imaging.imageformat.jpeg)run /n explorer.exe c:\logo7.jpgendwith
return
sample 8:
using the techniques shown before, draw logos and text aplying variable transparencies
the code below is not optimized, and is intended only to show some possibilities
do locfile("system.app")
with _screen.system.drawing as xfcdrawing
local lcmainpict, lclogopictlocal lomainbmp as xfcbitmaplocal lologobmp as xfcbitmaplocal logfx as xfcgraphics
lcmainpict = getpict()
lclogopict = getpict()
lomainbmp = .bitmap.fromfile(lcmainpict)
lologobmp = .bitmap.fromfile(lclogopict)
logfx = .graphics.fromimage(lomainbmp)
*!* sample 8
*!* draw image and text in different transparencieslocal lcstringlocal lofont as xfcfont
lofont = .font.new("verdana", 22, .fontstyle.bolditalic)local locolor as xfccolor
locolor = .color.whitelocal lnxstring
lnxstring = 0 + lologobmp.width
* first step: eliminate the white backgroundlologobmp.maketransparent(.color.white)
* define the transparency ratio that will be aplied
* this parameter ranges from 0 (totally transparent) to 1 (totally opaque)local lntranspratio
* create a colormatrix that will have the transformations information
* the position (4,4) of the matrix is responsible for the opacity local loclrmatrix as xfccolormatrix
loclrmatrix = .imaging.colormatrix.new()
* create an image attributes object to create the effects based in our clrmatrixlocal loattr as xfcimageattributes
loattr = .imaging.imageattributes.new()
* we need to create a rectangle that will contain the coordinates and size of the transformed logolocal lorect as xfcrectangle
lorect = .rectangle.new()
lorect.width = lologobmp.widthlorect.height = lologobmp.height
local lobrush as xfcsolidbrush
lobrush = .solidbrush.new(locolor)
* step 1
* draw image and text 100% opaquelnopaqueratio = 1 && 100%loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 1) - lologobmp.heightlogfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered - 100% opaque", lofont, lobrush, lnxstring, lorect.y)
* step 2
* draw image and text 80% opaquelnopaqueratio = .80
loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 2) - lologobmp.heightlocolor.a = lnopaqueratio * 255
lobrush.color = locolor
logfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered - 80% opaque", lofont, lobrush, lnxstring, lorect.y)
* step 3
* draw image and text 60% opaquelnopaqueratio = .60
loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 3) - lologobmp.heightlocolor.a = lnopaqueratio * 255
lobrush.color = locolor
logfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered - 60% opaque", lofont, lobrush, lnxstring, lorect.y)
* step 4
* draw image and text 40% opaquelnopaqueratio = .40
loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 4) - lologobmp.heightlocolor.a = lnopaqueratio * 255
lobrush.color = locolor
logfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered - 40% opaque", lofont, lobrush, lnxstring, lorect.y)
* step 4
* draw image and text 20% opaquelnopaqueratio = .20
loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 5) - lologobmp.heightlocolor.a = lnopaqueratio * 255
lobrush.color = locolor
logfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered - 20% opaque", lofont, lobrush, lnxstring, lorect.y)
lomainbmp.save("c:\logo8.jpg", .imaging.imageformat.jpeg)run /n explorer.exe c:\logo8.jpgendwith
return
sample 9:
same as previous sample, using the techniques shown before, draw logos and text aplying variable transparencies, using a monochrome logo.
the code below is not optimized, and is intended only to show some possibilities
do locfile("system.app")
with _screen.system.drawing as xfcdrawing
local lcmainpict, lclogopictlocal lomainbmp as xfcbitmaplocal lologobmp as xfcbitmaplocal logfx as xfcgraphics
lcmainpict = getpict()
lclogopict = getpict()
lomainbmp = .bitmap.fromfile(lcmainpict)
lologobmp = .bitmap.fromfile(lclogopict)
logfx = .graphics.fromimage(lomainbmp)
*!* sample 9
*!* draw image and text in different transparencieslocal lcstringlocal lofont as xfcfont
lofont = .font.new("verdana", 30, .fontstyle.bolditalic)local locolor as xfccolor
locolor = .color.whitelocal lobrush as xfcsolidbrush
lobrush = .solidbrush.new(locolor)
local lnxstring
lnxstring = 0 + 10 + lologobmp.width
* first step: eliminate the white backgroundlologobmp.maketransparent(.color.white)
* define the transparency ratio that will be aplied
* this parameter ranges from 0 (totally transparent) to 1 (totally opaque)local lntranspratio* create a colormatrix that will have the transformations information
* the position (4,4) of the matrix is responsible for the opacity
local loclrmatrix as xfccolormatrix
loclrmatrix = .imaging.colormatrix.new( ;
0.33, 0.33, 0.33, 0 , 0, ;
0.33, 0.33, 0.33, 0 , 0, ;
0.33, 0.33, 0.33, 0 , 0, ;
0, 0, 0, 1 , 0, ;
0, 0, 0, 0 , 0)
* create an image attributes object to create the effects based in our clrmatrixlocal loattr as xfcimageattributes
loattr = .imaging.imageattributes.new() * we need to create a rectangle that will contain the coordinates and size of the transformed logolocal lorect as xfcrectangle
lorect = .rectangle.new()
lorect.width = lologobmp.widthlorect.height = lologobmp.height
* step 1
* draw image and text 100% opaquelnopaqueratio = 1 && 100%loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
locolor.a = lnopaqueratio * 255
lobrush.color = locolor
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 1) - lologobmp.heightlogfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered", lofont, lobrush, lnxstring, lorect.y)
* step 2
* draw image and text 80% opaquelnopaqueratio = .80
loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 2) - lologobmp.heightlocolor.a = lnopaqueratio * 255
lobrush.color = locolor
logfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered", lofont, lobrush, lnxstring, lorect.y)
* step 3
* draw image and text 60% opaquelnopaqueratio = .60
loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 3) - lologobmp.heightlocolor.a = lnopaqueratio * 255
lobrush.color = locolor
logfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered", lofont, lobrush, lnxstring, lorect.y)
* step 4
* draw image and text 40% opaquelnopaqueratio = .40
loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 4) - lologobmp.heightlocolor.a = lnopaqueratio * 255
lobrush.color = locolor
logfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered", lofont, lobrush, lnxstring, lorect.y)
* step 5
* draw image and text 20% opaquelnopaqueratio = .20
loclrmatrix.matrix33 = lnopaqueratio
loattr.setcolormatrix(loclrmatrix)
lorect.x = 0
lorect.y = ( lomainbmp.height / 5 * 5) - lologobmp.heightlocolor.a = lnopaqueratio * 255
lobrush.color = locolor
logfx.drawimage(lologobmp, lorect, lologobmp.getbounds(), .graphicsunit.pixel, loattr)
logfx.drawstring("gdiplusx powered", lofont, lobrush, lnxstring, lorect.y)
* finished drawing, now save the image and show it !lomainbmp.save("c:\logo9.jpg", .imaging.imageformat.jpeg)run /n explorer.exe c:\logo9.jpgendwith
return
Este artículo se encuentra traducido al español en PortalFox en el siguiente enlace:
ReplyDelete-- Dibujar Logos en sus imágenes con GdiPlusX - Parte 2 --
http://www.portalfox.com/article.php?sid=2482