Click here to Skip to main content
15,914,323 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi guys

Can You Plz Tell me how to add text on an Image.I am doing it but it gives error Parameter is not valid.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    string image = Server.MapPath("Message - Popup - prohp_net.jpg");
    Bitmap bitmapimage = new System.Drawing.Bitmap(image);
        Graphics graphicimage = Graphics.FromImage(bitmapimage);
        graphicimage.SmoothingMode = SmoothingMode.AntiAlias;
        graphicimage.DrawString("That's my boy!", new Font("Arial", 12, FontStyle.Bold),SystemBrushes.WindowText,new Point(100,250));
        Response.ContentType = "image/jpg";
        bitmapimage.Save(Response.OutputStream, ImageFormat.Jpeg);
    }
}
Posted
Updated 17-Oct-12 22:29pm
v2
Comments
OriginalGriff 18-Oct-12 4:45am    
Where does it give the error?
Tisha Ahuja 18-Oct-12 4:53am    
near to server.mappath
OriginalGriff 18-Oct-12 4:58am    
"Near to" is not very helpful. Is that "near to" as in "on that line" or as in "in that method somewhere, probably"?
Tisha Ahuja 18-Oct-12 5:01am    
in page_Load string image = Server.MapPath("Message - Popup - prohp_net.jpg");
it gives error on this line.
Error: Parameter is not Valid.
OriginalGriff 18-Oct-12 5:30am    
And you are sure it is on that line? Not the following one?
The reason being that MapPath doesn't even check the file exists, while "Parameter is not Valid" is a generic GDI error that means anything from "File not found" to "bad image format". I would suspect the error comes from the new Bitmap(image) lien instead. Can you check with the debugger? Where does the file come from?

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