Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to develop engraving functionality Clone to http://www.larsonjewelers.com/p-2327-10k-fingerprint-ring-rose-gold-engraved-domed-band-4mm-8mm.aspx

when you add text & symbols then you can see the preview of single images which combine all the text & symbol

C#
[HttpPost]
public ActionResult DynamicImage(string name)
{
    var Iconimg = "1.png"; //Image Name
    string old = Server.MapPath("~\\cdn\\Symbol\\" + Iconimg);   //Getting the Image from Server
    string text = "satish tiwari"+old;                    // Appending the Text and Image 
    Bitmap bitmap = new Bitmap(1, 1);
    Font font = new Font("Arial", 25, FontStyle.Regular, GraphicsUnit.Pixel);
    Graphics graphics = Graphics.FromImage(bitmap);
    int width = (int)graphics.MeasureString(text, font).Width;
    int height = (int)graphics.MeasureString(text, font).Height;
    bitmap = new Bitmap(bitmap, new Size(width, height));
    graphics = Graphics.FromImage(bitmap);
    graphics.Clear(Color.White);
    graphics.SmoothingMode = SmoothingMode.AntiAlias;
    graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
    graphics.DrawString(text, font, new SolidBrush(Color.FromArgb(255, 0, 0)), 0, 0);
    graphics.Flush();
    graphics.Dispose();
    string fileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".jpg";
    bitmap.Save(Server.MapPath("~/cdn/Demo/") + fileName, ImageFormat.Jpeg);
    var returnFile = "~/cdn/Demo/" + fileName;
    return File(returnFile, "image/jpeg");
}
Posted

1 solution

Two Generate Text as Image
C#
[HttpPost]
      public ActionResult NewImg(string txt)
      {
          //image stream
          FileContentResult img = null;

          using (var mem = new MemoryStream())
          using (var bmp = new Bitmap(130, 30))
          using (var gfx = Graphics.FromImage((Image)bmp))
          {
              gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
              gfx.SmoothingMode = SmoothingMode.AntiAlias;
              gfx.FillRectangle(Brushes.White, new Rectangle(0, 0, bmp.Width, bmp.Height));
              gfx.DrawString(txt, new Font("Tahoma", 15), Brushes.Gray, 2, 3);

              //render as Jpeg
              bmp.Save(mem, System.Drawing.Imaging.ImageFormat.Jpeg);
              img = this.File(mem.GetBuffer(), "image/Jpeg");
          }
          return img;
      }


View
C#
<h2>NewImg</h2>

@using(Html.BeginForm()){
                            @Html.Label("Text")
                            @Html.TextBox("txt")
                                    
                        
                                           <input type="submit" value="new image" />
}
 
Share this answer
 

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