Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



Draw Logos in your images with GdiPlusX - Part 2

Here are 5 new samples derived from the ones that I showed in a previous post.

 

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
Requires VFP9 and GdiPlusX to run. 
Please make sure that you have the latest version!
http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home

 

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, lcLogoPict
LOCAL loMainBmp as xfcBitmap
LOCAL loLogoBmp as xfcBitmap
LOCAL 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 background
loLogoBmp.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 ClrMatrix
LOCAL 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 logo
LOCAL loRect as xfcRectangle
loRect = .Rectangle.New()
loRect.X = 0
loRect.Y = 0
loRect.
Width = loLogoBmp.Width
loRect.Height = loLogoBmp.Height

* Draw the transformed image using the rectangle and ImgAttributes/ClrMatrix
loGfx.DrawImage(loLogoBmp, loRect, loLogoBmp.GetBounds(), .GraphicsUnit.Pixel, loAttr)
loMainBmp.
Save("c:\logo5.jpg", .Imaging.ImageFormat.Jpeg)
RUN /N explorer.exe c:\logo5.jpg
ENDWITH
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, lcLogoPict
LOCAL loMainBmp as xfcBitmap
LOCAL loLogoBmp as xfcBitmap
LOCAL 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 background
loLogoBmp.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 ClrMatrix
LOCAL 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 logo
LOCAL 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/ClrMatrix
loGfx.DrawImage(loLogoBmp, loRect, loLogoBmp.GetBounds(), .GraphicsUnit.Pixel, loAttr)
loMainBmp.
Save("c:\logo6.jpg", .Imaging.ImageFormat.Jpeg)

RUN /N explorer.exe c:\logo6.jpg
ENDWITH
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, lcLogoPict
LOCAL loMainBmp as xfcBitmap
LOCAL loLogoBmp as xfcBitmap
LOCAL 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 background
loLogoBmp.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 ClrMatrix
LOCAL 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 logo
LOCAL 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/ClrMatrix
loGfx.DrawImage(loLogoBmp, loRect, loLogoBmp.GetBounds(), .GraphicsUnit.Pixel, loAttr)
loMainBmp.
Save("c:\logo7.jpg", .Imaging.ImageFormat.Jpeg)
RUN /N explorer.exe c:\logo7.jpg
ENDWITH
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, lcLogoPict
LOCAL loMainBmp as xfcBitmap
LOCAL loLogoBmp as xfcBitmap
LOCAL 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 transparencies
LOCAL lcString
LOCAL loFont as xfcFont
loFont = .
Font.New("Verdana", 22, .FontStyle.BoldItalic)
LOCAL loColor as xfcColor
loColor = .
Color.White
LOCAL lnXString
lnXString = 0 + loLogoBmp.
Width
 
* First step: eliminate the white background
loLogoBmp.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 ClrMatrix
LOCAL loAttr AS xfcImageAttributes
loAttr = .Imaging.ImageAttributes.New()

* We need to create a rectangle that will contain the coordinates and size of the transformed logo
LOCAL loRect as xfcRectangle
loRect = .Rectangle.New()
loRect.
Width = loLogoBmp.Width
loRect.Height = loLogoBmp.Height
LOCAL
loBrush as xfcSolidBrush
loBrush = .SolidBrush.New(loColor)
 
* Step 1
* Draw image and text 100% opaque
lnOpaqueRatio = 1 && 100%
loClrMatrix.Matrix33 = lnOpaqueRatio
loAttr.SetColorMatrix(loClrMatrix)
loRect.X = 0
loRect.Y = ( loMainBmp.
Height / 5 * 1) - loLogoBmp.Height

loGfx.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% opaque
lnOpaqueRatio = .80
loClrMatrix.Matrix33 = lnOpaqueRatio
loAttr.SetColorMatrix(loClrMatrix)
loRect.X = 0
loRect.Y = ( loMainBmp.
Height / 5 * 2) - loLogoBmp.Height
loColor.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% opaque
lnOpaqueRatio = .60
loClrMatrix.Matrix33 = lnOpaqueRatio
loAttr.SetColorMatrix(loClrMatrix)
loRect.X = 0
loRect.Y = ( loMainBmp.
Height / 5 * 3) - loLogoBmp.Height

loColor.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% opaque
lnOpaqueRatio = .40
loClrMatrix.Matrix33 = lnOpaqueRatio
loAttr.SetColorMatrix(loClrMatrix)
loRect.X = 0
loRect.Y = ( loMainBmp.
Height / 5 * 4) - loLogoBmp.Height

loColor.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% opaque
lnOpaqueRatio = .20
loClrMatrix.Matrix33 = lnOpaqueRatio
loAttr.SetColorMatrix(loClrMatrix)
loRect.X = 0
loRect.Y = ( loMainBmp.
Height / 5 * 5) - loLogoBmp.Height

loColor.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.jpg
ENDWITH
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, lcLogoPict
LOCAL loMainBmp as xfcBitmap
LOCAL loLogoBmp as xfcBitmap
LOCAL 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 transparencies
LOCAL lcString
LOCAL loFont as xfcFont
loFont = .
Font.New("Verdana", 30, .FontStyle.BoldItalic)
LOCAL loColor as xfcColor
loColor = .
Color.White
LOCAL loBrush as xfcSolidBrush
loBrush = .SolidBrush.New(loColor)
 
LOCAL lnXString
lnXString = 0 + 10 + loLogoBmp.
Width
 
* First step: eliminate the white background
loLogoBmp.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 ClrMatrix
LOCAL loAttr AS xfcImageAttributes
loAttr = .Imaging.ImageAttributes.New()
* We need to create a rectangle that will contain the coordinates and size of the transformed logo
LOCAL loRect as xfcRectangle
loRect = .Rectangle.New()
loRect.
Width = loLogoBmp.Width
loRect.Height = loLogoBmp.Height
 
 
 
 
* Step 1
* Draw image and text 100% opaque
lnOpaqueRatio = 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.Height

loGfx.DrawImage(loLogoBmp, loRect, loLogoBmp.GetBounds(), .GraphicsUnit.Pixel, loAttr)
loGfx.DrawString("GdiPlusX Powered", loFont, loBrush, lnXString, loRect.Y)
 
 
* Step 2
* Draw image and text 80% opaque
lnOpaqueRatio = .80
loClrMatrix.Matrix33 = lnOpaqueRatio
loAttr.SetColorMatrix(loClrMatrix)
loRect.X = 0
loRect.Y = ( loMainBmp.
Height / 5 * 2) - loLogoBmp.Height
loColor.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% opaque
lnOpaqueRatio = .60
loClrMatrix.Matrix33 = lnOpaqueRatio
loAttr.SetColorMatrix(loClrMatrix)
loRect.X = 0
loRect.Y = ( loMainBmp.
Height / 5 * 3) - loLogoBmp.Height

loColor.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% opaque
lnOpaqueRatio = .40
loClrMatrix.Matrix33 = lnOpaqueRatio
loAttr.SetColorMatrix(loClrMatrix)
loRect.X = 0
loRect.Y = ( loMainBmp.
Height / 5 * 4) - loLogoBmp.Height

loColor.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% opaque
lnOpaqueRatio = .20
loClrMatrix.Matrix33 = lnOpaqueRatio
loAttr.SetColorMatrix(loClrMatrix)
loRect.X = 0
loRect.Y = ( loMainBmp.
Height / 5 * 5) - loLogoBmp.Height

loColor.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.jpg
ENDWITH
RETURN

Published Friday, July 27, 2007 10:51 PM by cesarchalom
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

LuisMaria said:

Este artículo se encuentra traducido al español en PortalFox en el siguiente enlace:

-- Dibujar Logos en sus imágenes con GdiPlusX - Parte 2 --
http://www.portalfox.com/article.php?sid=2482



July 31, 2007 4:15 AM

What do you think?

(required) 
(optional)
(required)