Solved

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

Posted on 2011-09-29
8
253 Views
Last Modified: 2013-12-17
I want to create an image with width 640 and my data length !!!
0
Comment
Question by:abgconsulting
[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
  • 4
  • 3
8 Comments
 
LVL 4

Expert Comment

by:jatkin
ID: 36813283
Can you not use this:

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

where 1000 is your data length?
0
 

Author Comment

by:abgconsulting
ID: 36813339
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
 
LVL 4

Expert Comment

by:jatkin
ID: 36813406
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 40
ID: 36813518
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
 

Author Comment

by:abgconsulting
ID: 36813553
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
 
LVL 4

Expert Comment

by:jatkin
ID: 36813565
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
 

Author Comment

by:abgconsulting
ID: 36813815
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
 
LVL 4

Accepted Solution

by:
jatkin earned 500 total points
ID: 36813848
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

687 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