add text to image help

Last post 05-10-2008 7:40 AM by snovice. 9 replies.

Sort Posts:

  • add text to image help

    05-08-2008, 1:59 PM
    • Loading...
    • snovice
    • Joined on 01-25-2008, 2:05 PM
    • Posts 119

    I am working on a project

    in which i need to add text on images.

    What is happening that when i display image on process.aspx page

    nothing else is displayed on that page

    and with this image being displayed everythign is dispalyed

    this is how i am displaying image

           Response.ContentType = "image/jpeg";

           bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);

    everything is to being done in code behind.

    also please pass me some links where i can get good simple example of image handling in asp.net.

     

    Thankyou all

     

    Any help please?

     

  • Re: add text to image help

    05-09-2008, 5:28 AM

    In order to add this generated image, then in pages where you want to include the image you do this

    <img src="process.aspx" /> you can also add a query string to it to identify a certain image like process.aspx?imageid=10

    As to writing on the image itself use this code to modify the Image object you have in memory before you stream it back as a response.

    // add watermark
    Graphics graphics = Graphics.FromImage(bmp);
    Font font = new Font("Courier New", 11);
    SizeF size = graphics.MeasureString("© Copyright ", font);
    Rectangle rect = new Rectangle(0, 0, (int)Math.Ceiling(size.Width) + 1, (int)Math.Ceiling(size.Height));
    graphics.FillRectangle(new SolidBrush(Color.Wheat), rect);
    graphics.DrawString("© Copyright ", font, new SolidBrush(Color.Black), rect);
    graphics.Dispose();
    // add watermark

     Hope this helps.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    My Blog
    If you get the answer to your question, please mark it as the answer.
  • Re: add text to image help

    05-09-2008, 10:06 AM
    • Loading...
    • snovice
    • Joined on 01-25-2008, 2:05 PM
    • Posts 119

    Hello,

    This is my process.aspx.cs part of code on page load event

     

     

           Bitmap bitMapImage = new

     

            System.Drawing.Bitmap(Server.MapPath("Image/image002.jpg"));

     

           Graphics graphicImage = Graphics.FromImage(bitMapImage);

           graphicImage.SmoothingMode = SmoothingMode.AntiAlias;

           graphicImage.DrawString(Request.QueryString["message"],

           new Font("Arial", 12, FontStyle.Bold),

           Brushes.Red, new Point(15, 125));

                  

           Response.ContentType = "image/jpeg";

           //Save the new image to the response output stream.

           bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);

           graphicImage.Dispose();

           bitMapImage.Dispose();

     

    And in Process.aspx page I have added this line as you have said

    <img src="process.aspx"/> 

    I have image and text selected on main page that is passed thru querry string

    from querry string i have to take image and text to display rendered image .

    and I dont need to save this image on my hard disk.

    this is what i am tring to do

    but in process.aspx page Image is displayed without any trouble but other elements on that page are not displayed
     

     

  • Re: add text to image help

    05-09-2008, 10:25 AM
    Answer

    You should not use the process.aspx page for anything other than to stream the image data.

    You should not have any elements in it, in fact you should open the aspx page and remove all html elements, just leave the first line for the page directive.

    Whatever you want to show as elements, you have to create another page and in that page, when you want to show the dynamic image you add

    <img src="process.aspx?message=urtexthere" />

    Hope this is clear now. Let me know.

     

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    My Blog
    If you get the answer to your question, please mark it as the answer.
  • Re: add text to image help

    05-09-2008, 10:35 AM
    • Loading...
    • snovice
    • Joined on 01-25-2008, 2:05 PM
    • Posts 119

    Sorry for this questions but i didnt get you how i am going to achieve this.

    i have main.aspx page where image is selected and text is enteted.

    then this page  redirect the output to process.aspx./ querry string and both parameters

    here all my code comes /image displying

    and now if i create Finalpage.aspx // as you have suggested

    then how do i get to that page?

    where my image is shown with <img> tag and other elements

     


     

  • Re: add text to image help

    05-09-2008, 11:06 AM

    You can not redirect the output to process.aspx. You should forget the page process.aspx as being a page. Process.aspx is only used in the image tags now <img src="process...

    So you should not redirect your output to process.aspx you should redirect it to finalpage.aspx and inside the finalpage.aspx you should have the image tag as I described it.

    If you are sending the query parameters to finalpage, then inside the page finalpage you should write that inside the image tag as well

    For example

    add to the final page a public string message;

    inside your page_load of your finalpage

    message = Request["message"]

    DataBind();

     

    And finally in your aspx file of finalpage

    <img src="process.aspx?message=<%=message%>" />

    Hope this is clearer now.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    My Blog
    If you get the answer to your question, please mark it as the answer.
  • Re: add text to image help

    05-09-2008, 12:08 PM
    • Loading...
    • snovice
    • Joined on 01-25-2008, 2:05 PM
    • Posts 119

    Thanks this thing has worked as charm when i use static image and text

     

    Now i have to upgrade this with image and text passed by user

    in my main page i have selected my options and redirected to final page thru querry string

     and in final page code behind  i have used this line as it is

            string messager = Request["message"];

    DataBind();

    textbox1.text=messager;

    now text box has this message // final page.aspx

    now in final page i have used same

    image tag

    <img src="process.aspx?newmessage<%=messager%>"/>

    and it gives error

      The name 'messager' does not exist in the current context   

    any help

     

  • Re: add text to image help

    05-10-2008, 6:54 AM
    Answer

    HI can you send me/email me the files or the full project so that I can fix your code. It is easier :)

    Thanks.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    My Blog
    If you get the answer to your question, please mark it as the answer.
  • Re: add text to image help

    05-10-2008, 7:01 AM
    • Loading...
    • newbie2C#
    • Joined on 02-15-2007, 10:37 PM
    • Posts 95

    that's interesting.  I didn't know this could be done this way.  Why not add the text in photoshop or another image editing program?

    If errors were dollars, I'd be rich.
  • Re: add text to image help

    05-10-2008, 7:40 AM
    • Loading...
    • snovice
    • Joined on 01-25-2008, 2:05 PM
    • Posts 119

     I have sent you one email

    I wanted to send you email with attachment  but can't find any attachment link

    if u can reply back to this to my email (just now sent you mail thru this site) i will attach my files with it.

    or if you want me to paste code here i can do that also what ever you prefer

     

Page 1 of 1 (10 items)