user12520502
user12520502

Reputation:

Skiasharp scale bitmap before drawing

I have a problem. I am using a TextToBitmap function, so I can modify the bitmap. 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. 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. 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'

What am I doing wrong?

Upvotes: 0

Views: 1283

Answers (1)

Jason
Jason

Reputation: 89169

use Concat to combine two Matrices

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))

Upvotes: 1

Related Questions