我想通过在文本框中添加文本和符号来创建单个图像。 [英] I want to create a single image by adding the text and symbol in textbox.
本文介绍了我想通过在文本框中添加文本和符号来创建单个图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想开发雕刻功能克隆到http://www.larsonjewelers.com/p-2327-10k-fingerprint-ring-rose-gold-engraved-domed-band-4mm-8mm.aspx
当你添加文字&符号然后你可以看到单个图像的预览,它结合了所有文本和符号
[HttpPost]
public ActionResult DynamicImage( string name)
{
var Iconimg = 1.png; // 图片名称
string old = Server.MapPath( 〜\\cdn \\Symbol \\ + Iconimg); // 从服务器获取图像
string text = satish tiwari + old; // 附加文本和图像
位图位图= new 位图( 1 , 1 );
Font font = new 字体( Arial , 25 ,FontStyle.Regular,GraphicsUnit.Pixel);
图形图形= Graphics.FromImage(位图);
int width =( int )graphics.MeasureString(text,font).Width;
int height =( int )graphics.MeasureString(text,font).Height;
bitmap = new 位图(位图, new 尺寸(宽度,高度));
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 ,< span class =code-digit> 0 , 0 )), 0 ,< span class =code-digit> 0 );
graphics.Flush();
graphics.Dispose();
string fileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName())+ JPG跨度>。
bitmap.Save(Server.MapPath( 〜/ cdn / Demo /)+ fileName,ImageFormat.Jpeg);
var returnFile = 〜/ cdn /演示/ + fileName;
return 文件(returnFile, image / JPEG跨度>);
}
解决方案
两个生成文本作为图像
< pre lang =cs> [HttpPost]
public ActionResult NewImg( string txt)
{
// 图像流
FileContentResult img = 空跨度>;
使用( var mem = new MemoryStream())
使用( var bmp = new 位图( 130 , 30 ))
使用( var gfx = Graphics.FromImage((Image)bmp))
{
gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
gfx.SmoothingMode = SmoothingMode.AntiAlias;
gfx.FillRectangle(Brushes.White, new 矩形( 0 , 0 ,bmp.Width,bmp.Height));
gfx.DrawString(txt, new 字体( Tahoma, 15 ),Brushes.Gray, 2 , 3 跨度>);
// 渲染为Jpeg
bmp.Save(mem ,System.Drawing.Imaging.ImageFormat.Jpeg);
img = this .File(mem.GetBuffer(), 图像/ JPEG跨度>);
}
return img;
}
查看
< ; h2> NewImg < / h2 >
@using(Html.BeginForm()){
@ Html.Label( Text)
@ Html.TextBox( txt)
< input type = submit value = 新图片 /> ;
}
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
[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");
}
解决方案
Two Generate Text as Image
[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
<h2>NewImg</h2> @using(Html.BeginForm()){ @Html.Label("Text") @Html.TextBox("txt") <input type="submit" value="new image" /> }
这篇关于我想通过在文本框中添加文本和符号来创建单个图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文