- smartjobmanager.zip
- Code
- Bin
- App.config
- cachingconfiguration.config
- ClientApplication.exe
- EntLibHelper.dll
- exceptionhandlingconfiguration.config
- install.bat
- InvokerSample.exe.config
- log
- exceptions
- SmartJobManager.log
- loggingconfiguration.config
- loggingdistributorconfiguration.config
- Microsoft.Practices.EnterpriseLibrary.Caching.dll
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.EnterpriseLibrary.Configuration.dll
- Microsoft.Practices.EnterpriseLibrary.Data.dll
- Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
- Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
- Microsoft.Practices.EnterpriseLibrary.Logging.dll
- Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
- Microsoft.Practices.EnterpriseLibrary.Security.dll
- Providers.dll
- SampleProviders.dll
- ScreencaptureJobManagerProvider.dll
- SimpleJobManagerProvider.dll
- SmartJobManager.BusinessLogicLayer.dll
- SmartJobManagerService.exe
- SmartJobManagerService.exe.config
- uninstall.bat
- ClientApplication
- EntLibHelper
- Library
- Microsoft.Practices.EnterpriseLibrary.Caching.dll
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.EnterpriseLibrary.Configuration.dll
- Microsoft.Practices.EnterpriseLibrary.Data.dll
- Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
- Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
- Microsoft.Practices.EnterpriseLibrary.Logging.dll
- Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
- Microsoft.Practices.EnterpriseLibrary.Security.dll
- Objects
- Providers
- bin
- Configuration
- Providers.csproj
- Providers.csproj.user
- System
- Configuration
- Providers
- Providers
- Readme.txt
- SampleProviders
- ScreencaptureJobManagerProvider
- SimpleJobManagerProvider
- SmartJobManager.sln
- SmartJobManagerService
|
// =====================================================================================
// Copyright � 2005 by . All rights are reserved.
//
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
//
// website , email shahed.khan@gmail.com
// =====================================================================================
using System;
using System.Collections.Specialized;
using System.Data.SqlClient;
using SmartJobManager.Providers;
using SmartJobManager;
using System.IO;
using System.Drawing;
using System.Drawing.Text;
namespace SmartJobManager {
public class TextToImageJobManagerProvider : JobManagerProvider {
public TextToImageJobManagerProvider ()
{
}
#region JobManager specific behaviors
string OutputFilePath = @"c:\tmp\";
public override bool DoJob(Job job)
{
//DoJob
//Write to file
try
{
foreach(JobDetail jobDetail in job.JobDetailCollection)
{
if (jobDetail.ElementDesc == "TextToWrite")
GenerateImage(jobDetail.ElementData.ToString());
}
return true;
}
catch{}
return false;
}
#endregion
#region Provider specific behaviors
public override void Initialize(string name, NameValueCollection configValue) {
}
public override string Name {
get {
return null;
}
}
#endregion
#region Image Generation from Text
//Code originally written by http://www.thecodebehind.com/code/dotnet/aspnet/creating-an-image-from-text-with-c-and.aspx
//I modified it to fit my purpose
protected void GenerateImage(string imageText)
{
// we initialise these here because it's needed to calculate the width
// and height of the provided text. the 1,1 is only a temporary
// measurement
Bitmap bmp = new Bitmap(1, 1);
Graphics graphic = System.Drawing.Graphics.FromImage(bmp);
// our font for the writing
Font font = new Font("Arial", 14, FontStyle.Bold);
// measure the text
StringFormat stringformat = new StringFormat(StringFormat.GenericTypographic);
int height = Convert.ToInt32(graphic.MeasureString(imageText, font, new PointF(0,0), stringformat).Height) + 6;
int width = Convert.ToInt32(graphic.MeasureString(imageText, font, new PointF(0,0), stringformat).Width);
// add some padding for the width - i think the kerning is throwing
// it off by a little. 5% seems to work well, and the +10 is necessary
// if the string is only a few letters
width += Convert.ToInt32(0.05 * width) + 10;
// recreate our bmp and graphic objects with the new measurements
bmp = new Bitmap(width, height);
graphic = System.Drawing.Graphics.FromImage(bmp);
// our background colour
graphic.Clear(Color.FromArgb(153, 204, 229));
// aliasing mode
graphic.TextRenderingHint = TextRenderingHint.SystemDefault;
/*
the different aliasing modes:
---------------------------------------------------------------------------------
graphic.TextRenderingHint = TextRenderingHint.SystemDefault;
- each character is drawn using its glyph bitmap, with the system default rendering hint
graphic.TextRenderingHint = TextRenderingHint.AntiAlias;
- each character is drawn using its antialiased glyph bitmap without hinting
graphic.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
- each character is drawn using its antialiased glyph bitmap with hinting
graphic.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- each character is drawn using its glyph CT bitmap with hinting
graphic.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
- each character is drawn using its glyph bitmap
graphic.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
- each character is drawn using its glyph bitmap
*/
// our brush which is the writing colour
SolidBrush brush = new SolidBrush(Color.White);
/*
alternate brushes
-------------------------------------------------------------------------------
System.Drawing.Drawing2D.HatchBrush
System.Drawing.Drawing2D.LinearGradientBrush
System.Drawing.Drawing2D.PathGradientBrush
System.Drawing.SolidBrush
System.Drawing.TextureBrush
*/
// create our graphic
graphic.DrawString(imageText, font, brush, new Rectangle(0, 0, width, height));
// Set the content type and return the image
bmp.Save(string.Format("{0}{1}{2}{3}", OutputFilePath, "TransferImageJob",DateTime.Now.Ticks.ToString(), ".jpg"),System.Drawing.Imaging.ImageFormat.Jpeg);
// dispose of our objects
font.Dispose();
stringformat.Dispose();
graphic.Dispose();
bmp.Dispose();
}
#endregion Image Generation from Text
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.