Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Interface implementation in to my project
- public interface IElementCreator
- {
- int posX { get; set; }
- int posY { get; set; }
- StringFormat format { get; set; }
- string value { get; set; }
- Font font { get; set; }
- bool caption { get; set; }
- Font captionFont { get; set; }
- }
- public class ElementBase : IElementCreator, IImageUpdater
- {
- #region IElementCreator Variables
- private int _posX;
- private int _posY;
- private StringFormat _format;
- private string _value;
- private Font _font;
- private bool _caption;
- private Font _captionFont;
- #endregion
- #region IElementCreator Members
- public int posX
- {
- get { return _posX; }
- set { _posX = value; }
- }
- public int posY
- {
- get { return _posY; }
- set { _posY = value; }
- }
- public StringFormat format
- {
- get { return _format; }
- set { _format = value; }
- }
- public string value
- {
- get { return _value; }
- set { _value = value; }
- }
- public Font font
- {
- get { return _font; }
- set { _font = value; }
- }
- public bool caption
- {
- get { return _caption; }
- set { _caption = value; }
- }
- public Font captionFont
- {
- get { return _captionFont; }
- set { _captionFont = value; }
- }
- #endregion
- #region Constructor
- public ElementBase(int posX, int posY, StringFormat format, string value, Font font, bool caption, Font captionFont)
- {
- this.posX = posX;
- this.posY = posY;
- this.format = format;
- this.value = value;
- this.font = font;
- this.caption = caption;
- this.captionFont = captionFont;
- }
- #endregion
- public Image updatePreview(IElementCreator element, Image img)
- {
- }
- }
- public interface IImageUpdater
- {
- Image updatePreview(IElementCreator element, Image img);
- }
- public class ImageCreator : IImageCreator
- {
- public Image CreatePreviewImg(string value, int fontSize, int x, int y)
- {
- //Your code goes here...
- }
- }
- IImageCreator imageCreator = new ImageCreator;
- var preview = imageCreator.CreatePreviewImg(...);
- public interface IImageCreator
- {
- public Image CreatePreviewImg(string value, int fontSize, int x, int y);
- }
- public class ImageSettings : IImageSettings
- {
- public int posX { get; set; }
- public int posY { get; set; }
- public StringFormat format { get; set; }
- public string value { get; set; }
- public Font font { get; set; }
- public bool caption { get; set; }
- public Font captionFont { get; set; }
- }
- public interface IImageSettings
- {
- int posX { get; set; }
- int posY { get; set; }
- StringFormat format { get; set; }
- string value { get; set; }
- Font font { get; set; }
- bool caption { get; set; }
- Font captionFont { get; set; }
- }
- public class ImageCreator : IImageCreator
- {
- public Image CreatePreviewImg(IImageSettings imageSettings)
- {
- //ALL THE MAGIC HAPPENS HERE
- }
- //Image size A4 at 300dpi
- Bitmap bm = new Bitmap(width, height);
- bm.SetResolution(300, 300);
- // Create rectangle for the canvas
- RectangleF rectBg = new RectangleF(0, 0, width, height);
- // Load fonts
- Font bcFont = new Font(private_fonts.Families[0], fontSize, FontStyle.Regular, GraphicsUnit.Point);
- Font valueFont = new Font("Tahoma", 12, FontStyle.Regular, GraphicsUnit.Point);
- // Set StringFormat for the text value
- StringFormat sfValue = new StringFormat();
- sfValue.LineAlignment = StringAlignment.Far;
- sfValue.Alignment = StringAlignment.Center;
- // Set StringFormat for the barcode string
- StringFormat sfBarcode = StringFormat.GenericTypographic;
- sfBarcode.FormatFlags = StringFormatFlags.NoClip;
- using (Graphics g = Graphics.FromImage(bm))
- {
- // Create rectangle to place the barcode and text
- SizeF bcStringSize = g.MeasureString("*" + value + "*", bcFont);
- SizeF valueSize = g.MeasureString(value, valueFont);
- RectangleF recText = new RectangleF(x, y, (float)MeasureDisplayStringWidth(g, "*" + value + "*", bcFont), (float)(bcStringSize.Height + valueSize.Height));
- // Drawing the barcode and text
- g.SmoothingMode = SmoothingMode.AntiAlias;
- g.TextRenderingHint = TextRenderingHint.AntiAlias;
- g.FillRectangle(new SolidBrush(Color.White), rectBg);
- g.DrawString("*" + value + "*", bcFont, new SolidBrush(Color.Black), recText, sfBarcode);
- g.DrawString(value, valueFont, new SolidBrush(Color.Black), recText, sfValue);
- }
- return bm;
- }
- }
Add Comment
Please, Sign In to add comment