[英]Skiasharp scale bitmap before drawing
I have a problem.我有个问题。 I am using a TextToBitmap function, so I can modify the bitmap.我正在使用 TextToBitmap 函数,因此我可以修改位图。 But the resolution of the text gets bad when I scale it to a bigger bitmap.但是当我将它缩放到更大的位图时,文本的分辨率会变差。 To solve that, I set the TextSize to 400, so the text is drawn very big with high resolution which gives me a high resolution bitmap.为了解决这个问题,我将 TextSize 设置为 400,因此文本以高分辨率绘制得非常大,这为我提供了高分辨率位图。 The problem is that when the bitmap gets drawn, it is still very big, so I want to scale the bitmap to a specific Height.问题是绘制位图时,它仍然很大,所以我想将位图缩放到特定的高度。
Now I know how I can do this, I need to do this:现在我知道如何做到这一点,我需要这样做:
bitmapCollection.Add(bitmapCollection.Count, new TouchManipulationBitmap(TextBitmap)
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
Matrix = SKMatrix.MakeScale((float)0.3, (float)0.3),
});
But I can't use Matrix 2 times.但我不能使用 Matrix 2 次。 The translation and scale are neccesary, so how can I modify both?翻译和比例是必要的,那么我该如何修改两者呢?
EDIT:编辑:
I tried using this:我尝试使用这个:
SKMatrix matrix;
bitmapCollection.Add(bitmapCollection.Count, new TouchManipulationBitmap(TextBitmap)
{
Matrix = SKMatrix.Concat(matrix, SKMatrix.MakeTranslation(position.X, position.Y),
SKMatrix.MakeScale((float)0.3, (float)0.3))
});
But that gives me the following errors:但这给了我以下错误:
Argument 1 Must be passed with the 'ref' keyword Use of unassigned local variable 'matrix'参数 1 必须与 'ref' 关键字一起传递 使用未分配的局部变量 'matrix'
What am I doing wrong?我究竟做错了什么?
use Concat to combine two Matrices使用Concat组合两个矩阵
public static void Concat (ref SkiaSharp.SKMatrix target, ref SkiaSharp.SKMatrix first, ref SkiaSharp.SKMatrix second);
There is a lengthy discussion on this topic in the docs . 文档中有关于这个主题的冗长讨论。
in your specific case在您的具体情况下
SKMatrix matrix = new SKMatrix();
// matrix will contain the combined value
SKMatrix.Concat(ref matrix,
SKMatrix.MakeTranslation(position.X, position.Y),
SKMatrix.MakeScale((float)0.3, (float)0.3))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.