|
|
@ -41,32 +41,34 @@ public class ChannelLogoGenerator : IChannelLogoGenerator |
|
|
|
//Custom Font
|
|
|
|
//Custom Font
|
|
|
|
string fontPath = Path.Combine(FileSystemLayout.ResourcesCacheFolder, "Sen.ttf"); |
|
|
|
string fontPath = Path.Combine(FileSystemLayout.ResourcesCacheFolder, "Sen.ttf"); |
|
|
|
using SKTypeface fontTypeface = SKTypeface.FromFile(fontPath); |
|
|
|
using SKTypeface fontTypeface = SKTypeface.FromFile(fontPath); |
|
|
|
int fontSize = 30; |
|
|
|
var fontSize = 30; |
|
|
|
SKPaint paint = new SKPaint |
|
|
|
var font = new SKFont |
|
|
|
{ |
|
|
|
{ |
|
|
|
Typeface = fontTypeface, |
|
|
|
Typeface = fontTypeface, |
|
|
|
TextSize = fontSize, |
|
|
|
Size = fontSize |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var paint = new SKPaint |
|
|
|
|
|
|
|
{ |
|
|
|
IsAntialias = true, |
|
|
|
IsAntialias = true, |
|
|
|
Color = SKColors.White, |
|
|
|
Color = SKColors.White, |
|
|
|
Style = SKPaintStyle.Fill, |
|
|
|
Style = SKPaintStyle.Fill |
|
|
|
TextAlign = SKTextAlign.Center |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
SKRect textBounds = new SKRect(); |
|
|
|
font.MeasureText(text, out SKRect textBounds, paint); |
|
|
|
paint.MeasureText(text, ref textBounds); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ajuster la taille de la police si nécessaire
|
|
|
|
// Ajuster la taille de la police si nécessaire
|
|
|
|
while (textBounds.Width > logoWidth - 10 && fontSize > 16) |
|
|
|
while (textBounds.Width > logoWidth - 10 && fontSize > 16) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fontSize -= 2; |
|
|
|
fontSize -= 2; |
|
|
|
paint.TextSize = fontSize; |
|
|
|
font.Size = fontSize; |
|
|
|
paint.MeasureText(text, ref textBounds); |
|
|
|
font.MeasureText(text, out textBounds, paint); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Dessiner le texte
|
|
|
|
// Dessiner le texte
|
|
|
|
float x = logoWidth / 2f; |
|
|
|
float x = logoWidth / 2f; |
|
|
|
float y = logoHeight / 2f - textBounds.MidY; |
|
|
|
float y = logoHeight / 2f - textBounds.MidY; |
|
|
|
canvas.DrawText(text, x, y, paint); |
|
|
|
canvas.DrawText(text, x, y, SKTextAlign.Center, font, paint); |
|
|
|
|
|
|
|
|
|
|
|
using SKImage image = surface.Snapshot(); |
|
|
|
using SKImage image = surface.Snapshot(); |
|
|
|
using MemoryStream ms = new MemoryStream(); |
|
|
|
using MemoryStream ms = new MemoryStream(); |
|
|
|