может кто-нибудь сказать мне, почему ClearType выбирает прозрачность фона в простом примере SharpDX ниже? И как остановить это.
он отображает две строки сплошного черного текста в полупрозрачное растровое изображение. первая строка отображается с помощью оттенков серого, а вторая отображается с помощью ClearType.
РЕДАКТИРОВАТЬ: было высказано предположение, что проблема в том, что поверхность предварительно умножена. но это не объясняет разницы между двумя визуализациями Grayscale / ClearType.
результат (win7):
public static void Main()
{
var pixelFormat = SharpDX.WIC.PixelFormat.Format32bppPBGRA;
using (var wicFactory = new ImagingFactory())
using (var dddFactory = new SharpDX.Direct2D1.Factory())
using (var dwFactory = new SharpDX.DirectWrite.Factory())
using (var textFormat = new TextFormat(dwFactory, "Arial", FontWeight.Bold, FontStyle.Normal, 48))
using (var textLayout = new TextLayout(dwFactory, "argle-bargle", textFormat, float.PositiveInfinity, float.PositiveInfinity))
{
var width = (int) Math.Ceiling(textLayout.Metrics.Width);
var height = (int) Math.Ceiling(textLayout.Metrics.Height);
using (var wicBitmap = new SharpDX.WIC.Bitmap(
wicFactory,
width, height * 2,
pixelFormat,
BitmapCreateCacheOption.CacheOnLoad))
{
var renderTargetProperties = new RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied));
Color4 textColor = new Color4(0f, 0f, 0f, 1f);
using (var renderTarget = new WicRenderTarget(dddFactory, wicBitmap, renderTargetProperties))
using (var textBrush = new SolidColorBrush(renderTarget, textColor))
{
renderTarget.BeginDraw();
renderTarget.Clear(new Color4(1f, 1f, 0f, .25f));
renderTarget.TextAntialiasMode = TextAntialiasMode.Grayscale;
renderTarget.DrawTextLayout(new Vector2(0, 0), textLayout, textBrush);
renderTarget.TextAntialiasMode = TextAntialiasMode.Cleartype;
renderTarget.DrawTextLayout(new Vector2(0, height), textLayout, textBrush);
renderTarget.EndDraw();
}
var path = Path.Combine(Path.GetTempPath(), "test.png");
using (var stream = File.OpenWrite(path))
{
using (var encoder = new PngBitmapEncoder(wicFactory, stream))
using (var frameEncoder = new BitmapFrameEncode(encoder))
{
frameEncoder.Initialize();
frameEncoder.WriteSource(wicBitmap);
frameEncoder.Commit();
encoder.Commit();
}
}
}
}
}