Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

How to create an image define size, add some pictures and write on it programmatically?

I want to create an image with width 640 and my data length !!!
0
abgconsulting
Asked:
abgconsulting
  • 4
  • 3
1 Solution
 
James AtkinSenior Principle Software EngineerCommented:
Can you not use this:

System.Drawing.Image myImage = new Bitmap(600, 1000);

where 1000 is your data length?
0
 
abgconsultingAuthor Commented:
Thks Jatkin for your response,

But how i can fill my image with my data, i have to fill it like a receipt of superMarket?

0
 
James AtkinSenior Principle Software EngineerCommented:
There of loads of different ways you can directly put info into an image.
Check out this article for some of the ones I use quite frequently...

http://www.codeproject.com/KB/web-image/TextOnImage.aspx

James
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Jacques Bourgeois (James Burger)PresidentCommented:
You can use the PainEvent and draw the text into it with the e.Graphics.DrawString. It involves some preparation for the font and the color, but it lets you build an image from text. The documentation for the DrawString method has good samples of how to use it.
0
 
abgconsultingAuthor Commented:
James,
And what about the fact if  i want to put an image at the beginning and at the end of my image ?

PMS

0
 
James AtkinSenior Principle Software EngineerCommented:
You can use the DrawImage method for situations like this, for example:

static public Bitmap Copy(Bitmap srcBitmap, Rectangle section)
{
    // Create the new bitmap and associated graphics object
    Bitmap bmp = new Bitmap(section.Width, section.Height);
    Graphics g = Graphics.FromImage(bmp);

    // Draw the specified section of the source bitmap to the new one
    g.DrawImage(srcBitmap, 0, 0, section, GraphicsUnit.Pixel);

    // Clean up
    g.Dispose();

    // Return the bitmap
    return bmp;
}
0
 
abgconsultingAuthor Commented:
Hi jatkin

I am a little confused, could you explain me  again please.
  I try to create an image and the image I want to put a picture at the beginning and another at the end and in between I want to put the string as the receipts of the supermarket.

If I am your thinking so you asked me to create a bitmap like this
System.Drawing.Image = new Bitmap myImage (600, 1000);

and use the method DrawImage

static public Bitmap Copy (Bitmap srcBitmap, Rectangle section)
{
     / / Create the new bitmap and associated graphics object
     Bitmap bmp = new Bitmap (section.Width, section.Height);
     Graphics g = Graphics.FromImage (bmp);

     / / Draw the specified section of the source bitmap to the new one
     g.DrawImage (srcBitmap, 0, 0, section, GraphicsUnit.Pixel);

     / / Clean up
     g.Dispose ();

     / / Return the bitmap
     return bmp;
}
  But where do I pass the pictures I add to my image?

Thanks in advance

PMS
0
 
James AtkinSenior Principle Software EngineerCommented:
The above code was more of an example of how to use the DrawImage function.

For your specific case you would do:

Image xMainImage = new Bitmap(600, 1000);
Image xHeader = new Bitmap("C:\\Header.bmp");
Image xFooter = new Bitmap("C:\\Header.bmp");

Graphics g = Graphics.FromImage(xMainImage);
g.DrawImage(xHeader, 0, 0, new Rectangle(0, 0, 600, 100);
g.DrawImage(xHeader, 0, 900, new Rectangle(0, 0, 600, 100);
g.Dispose();

<Put your text stuff in the middle somewhere>

Does this all make sense?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now