Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to GdiPlusX watermark jpg?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01581537
Message ID:
01581558
Vues:
94
>Anybody have any working code for watermarking jpg images with text using gdiplusx? I've never been able to figure much out with gdiplusx short of copying others code.

Adapted from this example:
http://weblogs.foxite.com/vfpimaging/2012/03/16/draw-rotated-strings-with-gdiplusx/

Here's the basic code to watermark an image with transparent text for anyone else looking:
* Initialize GdiPlus-X library 
DO LOCFILE("System.App")

* Load the image
LOCAL loBmp as xfcBitmap 
loBmp = _screen.system.Drawing.Bitmap.FromFile("C:\original.jpg")

* Create a Graphics object associated to the bitmap 
LOCAL loGfx as xfcGraphics 
loGfx = _screen.system.Drawing.Graphics.FromImage(loBmp)

* Create a SolidBrush with Red Color using alpha for transparency
LOCAL loBrush AS xfcBrush 
*loBrush = _screen.system.Drawing.SolidBrush.New( _screen.system.Drawing.COLOR.FromRgb(255,0,0)) 
 loBrush = _screen.system.Drawing.SolidBrush.New( _screen.system.Drawing.COLOR.FromARgb(100,255,0,0)) 
* loBrush = _screen.system.Drawing.SolidBrush.New( _screen.system.Drawing.COLOR.Red)

* Create a Rectangle in which the rotated text will be drawn 
LOCAL loRect AS xfcRectangle 
loRect = _screen.system.Drawing.Rectangle.New(0, 0, loBmp.Width, loBmp.Height)

* Get a basic string format object, then set properties 
LOCAL loStringFormat AS xfcStringFormat 
loStringFormat = _screen.system.Drawing.StringFormat.New() 
loStringFormat.ALIGNMENT = _screen.system.Drawing.StringAlignment.CENTER 
loStringFormat.LineAlignment = _screen.system.Drawing.StringAlignment.CENTER

* Create a Font object 
LOCAL loFont AS xfcFont 
loFont = _screen.system.Drawing.FONT.New("Verdana",16, _screen.system.Drawing.FontStyle.Regular, _screen.system.Drawing.GraphicsUnit.POINT)

* After creating all needed objects, we can apply the rotation 
* and draw the text

* Translate and Rotate 
loGfx.TranslateTransform(loBmp.Width /2, loBmp.Height /2) 
loGfx.RotateTransform(-15) && angle of 15 degrees 
loGfx.TranslateTransform(-loBmp.Width /2, -loBmp.Height /2)

* Finally, draw the string 
loGfx.DrawString("Rotated Text" + CHR(13) + CHR(10) + "GDIPlus-X is COOL !!!", ; 
loFont, loBrush, loRect, loStringFormat)

* Reset Rotation 
loGfx.ResetTransform()

* Save watermarked image to File 
loBmp.Save("c:\watermarked.jpg", _screen.system.Drawing.Imaging.ImageFormat.Jpeg)


* Show created image 
RUN /N explorer.exe c:\watermarked.jpg
Brandon Harker
Sebae Data Solutions
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform