WPF如何生成一个自定义的图片啊

WPF如何生成一个自定义的图片啊要求尺寸:3200x523DPI:1693字体7.5PT字体Style:FontWeights.thin,字体:Arial... WPF如何生成一个自定义的图片啊 要求尺寸:3200x523 DPI: 1693 字体7.5PT 字体Style:FontWeights.thin ,字体:Arial 展开
 我来答
RayNCC
推荐于2016-06-12 · TA获得超过615个赞
知道小有建树答主
回答量:452
采纳率:0%
帮助的人:595万
展开全部
1、使用DrawingVisual绘制你的内容:
var drawingVisual = new DrawingVisual();
using(var drawingContext = drawingVisual.RenderOpen())
{
var text = new FormattedText(.....);
var position = new Point(......);
drawingVisual.DrawText(text, position);
}

2、用RenderTargetBitmap渲染成位图:
var renderTargetBitmap = new RenderTargetBitmap(.....);
renderTargetBitmap.Render(drawingVisual);

3、选用一种BitmapEncoder保存,比如PngBitmapEncoder:
var encoder = new PngBitmapEncoder();
var frame = BitmapFrame.Create(renderTargetBitmap);
encoder.Frames.Add(frame);
encoder.Save(...);
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
荣归2014
2014-05-27
知道答主
回答量:9
采纳率:0%
帮助的人:9.7万
展开全部
你要绘图还是用GDI吧,WPF工程中要引用System.Drawing
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(3200, 523, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
bmp.SetResolution(1693, 1693);
System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(bmp);
System.Drawing.Font font = new System.Drawing.Font("Arial", 7.5f); //, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // 这行可以不要,用于控制输出效果
graphic.DrawString("This is test text...", font, System.Drawing.Brushes.Black, new System.Drawing.PointF(50, 20)); // 测试文字输出
// 绘制一个圆
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red);
pen.Width = 4;
graphic.DrawEllipse(pen, System.Drawing.Rectangle.FromLTRB(50, 200, 400, 400));
bmp.Save("C:\\Test.png", System.Drawing.Imaging.ImageFormat.Png);
font.Dispose();
graphic.Dispose();
bmp.Dispose();
更多追问追答
追问
谢谢,我现在用的就是GDI,可是现在的工作要求必须用WPF,因为要用到FontWeights.thin,而这个在windows下面是没有的。
追答
This attribute is modeled after the lfWeight field in GDI LOGFONT.  For consistency, the following values have been adopted from LOGFONT: 0=DontCare, 100=Thin, 200=ExtraLight or UltraLight, 300=Light, 400=Normal or Regular, 500=Medium, 600=SemiBold or DemiBold, 700=Bold, 800=ExtraBold or UltraBold, and 900=Heavy or Black.
你可以使用GDI的LOGFONT实现你要的,界面交给WPF,对图像的后台处理还是GDI吧,毕竟WPF的优势不在于此
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式