当字体放大时,字的图边缘部分不平滑有很多锯齿,我在photoshop中看他的RGB通道也都有锯齿,但是他的alpha通道很平滑,有没有处理的方法,使得文字平滑? GDI+我试过,效果也不行。这样的算法如何实现?
解决方案 »
- 高手请进,我的程序能正常运行,但是关闭的时候提示“FILE:afxwin2.inl line:39”错误???请问怎么解决???谢谢
- vc+如何模似注销当前用户,但是不出现注销窗口!
- LoadCursor的用法?我想改变鼠标的形状,总是不成功
- error c2065帮我解决一下
- 请问:用什么数据结构或者MFC对象处理矩阵运算?
- 在VC+SQLSERVER+ADO中,请问如何读取一个表的字段,已知表的name!
- 关于网口通讯与串口通讯发生冲突的问题
- 编译错误。快来抢分!
- 请问怎样在文件的右键菜单中加入自己的程序?
- 这几个问题可能很简单,可是我不懂,多谢赐教。
- MdiChildWnd 改变标题栏文字 字体
- 3ds未贴图可以导入到opengl贴图的导入不了。
点阵字体:http://baike.baidu.com/view/1941516.htm
TrueType:http://baike.baidu.com/view/333247.htm
如果非用点阵,就用TrueType字体生成点阵字体。
==============================================================================
这些字体我都试了,效果还是那样。程序要做成能随便设置字体的。搞了好久了,头疼。
首先,你要平滑的字体做什么!
如果你连 Adobe 和 微软 的效果都看不上,你是不会找到更好的结果的。
不知道你是真的看不上,还是压根就没用对!别折腾了,就Adobe和GDI+选一个了。
你自己找算法是在搞笑!或者说,你只是想搞一会算法玩一玩!
点阵字体:http://baike.baidu.com/view/1941516.htm
TrueType:http://baike.baidu.com/view/333247.htm
var
i, j: Integer;
pS1, pS2, pS3, pS4: PByteArray;
pDes: PByteArray;
x, y: Integer;
P: TPoint;
LogFont: TLogFont;
Beta: Double;
TextSize: TSize;
R: TRect;
begin
if (AAFont = nil) or (AAFont.Canvas = nil) then
Exit; InitGrayBmp;
FWidth := Extend.cx; //大小
FHeight := Extend.cy;
if GrayBmp.Width < Width * Scale then //放大
GrayBmp.Width := Width * Scale;
if GrayBmp.Height < Height * Scale then
GrayBmp.Height := Height * Scale; GetObject(AAFont.Canvas.Font.Handle, SizeOf(TLogFont), @LogFont);
with LogFont do
begin
lfHeight := lfHeight * Scale;
lfWidth := lfWidth * Scale;
Beta := lfEscapement * Pi / 1800;
end;
GrayBmp.Canvas.Font.Handle := CreateFontIndirect(LogFont);
GrayBmp.Canvas.Font.Color := clWhite;
FillRect(GrayBmp.Canvas.Handle, Bounds(0, 0, GrayBmp.Width, GrayBmp.Height), 0);
x := Point.x * Scale;
y := Point.y * Scale;
if Beta <> 0 then // 考虑字体旋转
begin
TextSize := TextExtentEx(Text, P);
Inc(x, P.x * Scale);
Inc(y, P.y * Scale);
end;
R := Bounds(0, 0, GrayBmp.Width, GrayBmp.Height);
Windows.TextOut(GrayBmp.Canvas.Handle, x, y, PChar(Text), Length(Text)); BytesLineGray := (GrayBmp.Width + 3) div 4 * 4; //扫描线宽度
BytesLineMask := (Width + 3) div 4 * 4;
ReAllocMem(FpMaskBuff, BytesLineMask * Height); pS1 := GrayBmp.ScanLine[0]; //源灰度图
pS2 := PByteArray(Integer(pS1) - BytesLineGray);
pS3 := PByteArray(Integer(pS2) - BytesLineGray);
pS4 := PByteArray(Integer(pS3) - BytesLineGray);
pDes := PByteArray(Integer(pMaskBuff) + (Height - 1) * BytesLineMask);
//目标灰度为源矩形块的平均值
case Quality of
aqHigh:
begin //高精度4X4采样
for i := 0 to Height - 1 do
begin
for j := 0 to Width - 1 do
begin
x := j * 4;
pDes^[j] :=
(pS1^[x] + pS1^[x + 1] + pS1^[x + 2] + pS1^[x + 3] +
pS2^[x] + pS2^[x + 1] + pS2^[x + 2] + pS2^[x + 3] +
pS3^[x] + pS3^[x + 1] + pS3^[x + 2] + pS3^[x + 3] +
pS4^[x] + pS4^[x + 1] + pS4^[x + 2] + pS4^[x + 3]) shr 4;
end;
pS1 := PByteArray(Integer(pS4) - BytesLineGray);
pS2 := PByteArray(Integer(pS1) - BytesLineGray);
pS3 := PByteArray(Integer(pS2) - BytesLineGray);
pS4 := PByteArray(Integer(pS3) - BytesLineGray);
pDes := PByteArray(Integer(pDes) - BytesLineMask);
end;
end;
aqNormal:
begin //普通精度3X3采样
for i := 0 to Height - 1 do
begin
for j := 0 to Width - 1 do
begin
x := j * 3;
pDes^[j] :=
(pS1^[x] + pS1^[x + 1] + pS1^[x + 2] shr 1 +
pS2^[x] + pS2^[x + 1] + pS2^[x + 2] +
pS3^[x] shr 1 + pS3^[x + 1] + pS3^[x + 2]) shr 3;
end;
pS1 := PByteArray(Integer(pS3) - BytesLineGray);
pS2 := PByteArray(Integer(pS1) - BytesLineGray);
pS3 := PByteArray(Integer(pS2) - BytesLineGray);
pDes := PByteArray(Integer(pDes) - BytesLineMask);
end;
end;
aqLow:
begin //低精度2X2采样
for i := 0 to Height - 1 do
begin
for j := 0 to Width - 1 do
begin
x := j * 2;
pDes^[j] :=
(pS1^[x] + pS1^[x + 1] +
pS2^[x] + pS2^[x + 1]) shr 2;
end;
pS1 := PByteArray(Integer(pS2) - BytesLineGray);
pS2 := PByteArray(Integer(pS1) - BytesLineGray);
pDes := PByteArray(Integer(pDes) - BytesLineMask);
end;
end;
aqNone:
begin //无平滑效果
for i := 0 to Height - 1 do
begin
CopyMemory(pDes, pS1, Width);
pS1 := PByteArray(Integer(pS1) - BytesLineGray);
pDes := PByteArray(Integer(pDes) - BytesLineMask);
end;
end;
end;
FreeGrayBmp;
end;
FixedSYS字体不能平衡的原因不是不支持,而是这是这个字体的一个特点!
或者这么说,你在系统字体对话框里找到的都可以平滑。Graphics::SetTextRenderingHint(TextRenderingHintAntiAlias)记得,当字体尺寸大于12的时候再开抗锯齿,太小了开抗锯齿反而不好!
这段源码包含汗多数学处理。或者行数超过100。只有在两个情况下你可以使用:1、这段代码已经被网上成千上万的人用过,并且有专门的团队来维护,并且如果你关键词合适,他出现在
google的第一条2、这段代码来自微软,或者和微软差不多大的公司。除了上面两个条件,你最好只用你自己的代码!否则,你就将成为试验品,而那个写代码根本无视你的痛苦,他只会沾沾自喜有人在用他的代码。
这个DirectX本来就有! 你为什么就不能把SDK里的例子程序全试验一遍再出手!
好像vc代码能直接编译为.net app把
大连网站制作www.dlsnail.com大连网站制作
实际上Photoshop也是调用的GDI,不过它是先在一个内存DC上画一个大一倍的字体,然后用二次插值缩小。
不过Windows本身的字体引擎比较烂,加上宋体是嵌入点阵的,无法ClearType,对于小字号字体会比较难看。
这方面Mac OS X和Linux做得都比较好。如果是特别需要,可以用FreeType库。
http://www.topnetsecurity.com/viewthread.php?tid=301&extra=page%3D2