Solved

How do I create an new image using an exisiting background and adding text programatically?

Posted on 2008-10-01
3
274 Views
Last Modified: 2013-12-25
Hi all, Here's what I want to do:
I have 20 odd different images which represent sign backings. I want to be able to get clients to pick a background, enter the text they want in a text box and then create a specific image which adds the text to the backing. Basically I want them to be able to see what their sign will look like. Ideally I would like to be able to use probably 8 different fonts (I understand these are differing widths) and be able to change the font color to either black or silver.  I've never worked with images in C# /.Net before so I'm looking for some kind of guideline as to where to begin. ie: What classes / how to add to an existing image, how to save that image as another etc.  
0
Comment
Question by:Jen_M66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Expert Comment

by:trunghieubkit
ID: 22621450
The snippet below may help you,

if you want to draw on it before saving as another file you can create Graphics as following

           Graphics g = this.CreateGraphics();

           g.DrawImage(...);            g.DrawLine(...);            g.DrawRectangle(...);




private void Form1_Load(object sender, EventArgs e)
{
    string lstrFromFile = @"D:\From.gif";
    string lstrToFile = @"D:\To.jpeg";
 
    this.BackgroundImage = Image.FromFile(lstrFromFile);
    this.BackgroundImage.Save(lstrToFile);
}

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 22626067
Here is a small converted VB.Net snippet that loads a background image and puts text into the middle of it:
    Bitmap bmp = new Bitmap(@"c:\someImage.jpg");
    string msg = "Hello World!";
 
    Graphics G = Graphics.FromImage(bmp);
    Font F = new Font("Arial", 48, FontStyle.Regular, GraphicsUnit.Point);
    StringFormat SF = new StringFormat();
    SizeF SZ = G.MeasureString(msg, F, new SizeF(bmp.Width, bmp.Height), SF);
 
    G.DrawString(msg, F, Brushes.Red, (bmp.Width / 2) - (SZ.Width / 2), (bmp.Height / 2) - (SZ.Height / 2), SF);
 
    F.Dispose();
    G.Dispose();
 
    pictureBox1.Image = bmp;

Open in new window

0
 

Author Closing Comment

by:Jen_M66
ID: 31502257
Great thank you - that was much easier than I thought it would be.
0

Featured Post

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question