我试图用DrawString文字作为图像,然后旋转90度.它既可以使用位图也可以直接在PictureBox上工作,但最大的区别在于质量.PictureBox绘制的文字质量很好,看起来不错.当我在图像上绘制它看起来很可怕和块状.我做了一些改变试图让它看起来更好,但它看起来并不像它应该的那么好.
示例代码:
使用Windows窗体项目并在其上放置2个图片框和一个按钮,并使用以下代码运行它以查看我的意思:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim g As System.Drawing.Graphics
g = PictureBox1.CreateGraphics
' x.DrawRectangle(New Pen(Brushes.White, 200), New Rectangle(0, 0, 200, 200))
g.TranslateTransform(10.0F, 0.0F)
g.RotateTransform(90)
g.DrawString("MM Components", New Font("Arial", 7, FontStyle.Regular), Brushes.DarkBlue, New PointF(0, 0))
Dim g2 As System.Drawing.Graphics
Dim img As New Bitmap(300, 300, Drawing.Imaging.PixelFormat.Format24bppRgb)
g2 = Graphics.FromImage(img)
g2.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g2.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
g2.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
' img.SetResolution(150, 150)
' x.DrawRectangle(New Pen(Brushes.White, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用.NET框架提供的PrintDocument将khmer脚本(unicode)字符串发送到打印机.
不幸的是,在我看来,Graphics.DrawString()没有正确呈现高棉脚本.
平台:Windows 7 Ultimate
IDE:VS 2010 Ultimate
以下是示例代码:
void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
var font = new Font("Khmer UI", 12);
var text = "??????"; // "Hello"
e.Graphics.DrawString(text, font, Brushes.Black, 100, 100);
}
Run Code Online (Sandbox Code Playgroud) 作为打印类的一部分,我希望能够在多个页面上打印长字符串,但我不知道如何计算整个字符串的高度,我将通过首先计算字符串中的行数来确定.我知道我可以计算换行符的数量,但我也使用自动换行,因此每当一行超过页面宽度时,就会添加换行符.所以我想我可以计算换行符的数量,并找出每一行的宽度,并找出是否需要每行的自动换行换行符,但这似乎是一个过于复杂的问题我想可以更简单地完成.
e.Graphics.DrawString(multiPageString, new Font("Courier New", 12), Brushes.Black, new RectangleF(0, 0, 810, pageHeight));
Run Code Online (Sandbox Code Playgroud)
如果您有任何建议,请告诉我们谢谢!
为什么显示的GUI具有不同的字体样式/渲染graphics.drawString()和具有激活的cleartype的默认JLabel?我该如何解决?

这正是我想要做的:
Graphics2D g2 = (Graphics2D) g;
g2.setFont(new Font("Serif", Font.PLAIN, 5));
g2.setPaint(Color.black);
g2.drawString("Line 1\nLine 2", x, y);
Run Code Online (Sandbox Code Playgroud)
该行打印如下:
Line1Line2
Run Code Online (Sandbox Code Playgroud)
我希望这样:
Line1
Line2
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做drawString?
以及如何为一条线做一个标签空间?
无论我是否使用XTextFormatter,我都得到关于LayoutRectangle的高度为0或类似的错误.
new PdfSharp.Drawing.Layout.XTextFormatter(_gfx).DrawString(text
, new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle)
, new PdfSharp.Drawing.XSolidBrush(PdfSharp.Drawing.XColor.FromArgb(foreColour))
, new PdfSharp.Drawing.XRect(new PdfSharp.Drawing.XPoint(xPos, yPos), new PdfSharp.Drawing.XPoint(xLimit, yLimit))
, PdfSharp.Drawing.XStringFormats.Default);
Run Code Online (Sandbox Code Playgroud)
fontStyle的类型为System.Drawing.FontStyle foreColour的类型为System.Drawing.Color我已经从PdfPage预定义_gfx,Orientation = Landscape,Size = Letter xPos和yPos是double类型的参数,与xLimit和yLimit相同.
我得到运行时错误,LayoutRectangle的高度必须为零(0)...
根据定义,矩形意味着具有高度,否则称为线!我不明白!...
我直接尝试使用XGraphics.DrawString()方法,我得到了同样的错误.似乎我不能使用LayoutRectangle,但必须手动管理文本适合所需区域.
var textFont = new PdfSharp.Drawing.XFont(fontName, fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
while (xPos + _gfx.MeasureString(text, textFont).Width > xLimit)
textFont = new PdfSharp.Drawing.XFont(fontName, --fontSize, (PdfSharp.Drawing.XFontStyle)fontStyle);
while (yPos + _gfx.MeasureString(text, textFont).Height > yLimit && fontSize > 0)
textFont = …Run Code Online (Sandbox Code Playgroud) 我只是想在一个充满黑色的矩形中显示我的String.谢谢您的帮助!

我正在为员工生成 ICard。我必须在 ICard 上写下雇员的地址。
Image blankICard = Image.FromFile(@"C:\Users\admin\Pictures\filename.jpg");
Bitmap outputImage = new Bitmap(blankICard.Width, blankICard.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.SolidBrush b = new SolidBrush(Color.FromArgb(255, 88, 89, 91));
using (Graphics graphics = Graphics.FromImage(outputImage))
{
graphics.DrawImage(blankICard, new Rectangle(0, 0, blankICard.Width, blankICard.Height),
new Rectangle(new Point(), blankICard.Size), GraphicsUnit.Pixel);
Font stringFont = new Font("FreightSans Medium", 20, FontStyle.Regular);
string address = "Address goes here";
graphics.DrawString(address, new Font("FreightSans Medium", 20, FontStyle.Regular), b, new Point(621, 234));
graphics.DrawString("Employee Code:12345678", new Font("FreightSans Medium", 26, FontStyle.Regular), b, new Point(350, 407));
}
Run Code Online (Sandbox Code Playgroud)
电流输出显示在图像的左侧。这是我的字符串开箱即用会发生什么。
我想把它装在固定尺寸的盒子里。
示例显示在图像的右侧。
我使用GDI DrawString方法绘制文本。程序运行时,屏幕上的文本看起来非常好,但是一旦将文件保存到图像中,字体将比以前更粗体。普通将为粗体,粗体将为粗体。该如何处理?
public override void DrawTo(Graphics g, int x, int y, int flag)
{
if (flag == 1)
{
Pen dpen = new Pen(Color.FromArgb(128, 0, 0, 0), 1);
dpen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
g.DrawRectangle(dpen, new Rectangle(Bounds.X + x, Bounds.Y + y, Bounds.Width, Bounds.Height));
}
if (!string.IsNullOrEmpty(Text))
{
g.DrawString(Text, Font, new SolidBrush(Color), new Rectangle(Bounds.X + x, Bounds.Y + y, Bounds.Width, Bounds.Height));
}
}
Run Code Online (Sandbox Code Playgroud) 两个问题合在一起,但我有一个非常简短的测试用例来证明我的问题:
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.imageio.*;
public class Numbers {
public static void main(String[] args) throws IOException {
double[] numbers = { 10000.12, 20000.23, 3000.45 };
DecimalFormat format = new DecimalFormat("0.00");
format.setGroupingUsed(false);
BufferedImage image = new BufferedImage(400, 150, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
g2d.setColor(Color.BLACK);
g2d.setBackground(Color.YELLOW);
g2d.clearRect(0, 0, image.getWidth(), image.getHeight());
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setFont(new Font(Font.SANS_SERIF,Font.BOLD, 24));
FontMetrics metrics = g2d.getFontMetrics();
for (int i = 0; i < numbers.length; i++) {
String str = format.format(numbers[i]);
System.out.println(i …Run Code Online (Sandbox Code Playgroud)