Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i want to create an application in c# where i upload text image.

the application create space between the characters in that image.
can somebody have any idea. please let me know
thanks
Posted
Comments
lukeer 5-Jan-12 8:27am    
Please tell a bit more about "text images". It's not quite clear what you mean by that.

And since you mention "uploading" it somewhere, is this question about Windows Forms, WPF, ASP.NET or something I haven't thought about?

Please use the "Improve question" link to re-work your question.
saifullahiit 5-Jan-12 8:32am    
acutally i want to create a windows form.
the image shuld be like captcha image in which text is shown in an image.

That is not really feasible.
The problems are:
1) Identify the text and separate it from the image.
2) Decide where you want the extra space to go and move the image of the characters of the text over appropriately.
3) Work out what to fill in behind the characters so they don't leave big, character shaped holes in the image.

Why do you want to do that - use the text and write it into a "virgin" image instead. It's a lot easier, quicker, and more effective.
 
Share this answer
 
Comments
fjdiewornncalwe 5-Jan-12 10:24am    
+5. Agreed.
The terminology of what you are looking for is called kerning[^] in typography[^].

I've tried this and it works like a charm:

C#
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("gdi32.dll", CharSet = CharSet.Auto)]
        public static extern int SetTextCharacterExtra(
            IntPtr hdc,    // DC handle
            int nCharExtra // extra-space value
        );

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            IntPtr hDC = e.Graphics.GetHdc();
            for (int idx = 0; idx < 10; idx++)
            {
                SetTextCharacterExtra(hDC, idx);
                IDeviceContext HDC = System.Drawing.Graphics.FromHdc(hDC);
                TextRenderer.DrawText(HDC, "The quick brown fox jumped over the lazy dog!", this.Font, new Point(10, 10 + idx * 30), SystemColors.ControlText);
            }
            e.Graphics.ReleaseHdc(hDC);
        }
    }
}


All that's left to do for you is to draw the text into a bitmap instead of directly onto the form.

Regards,

Manfred
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900