Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Overlay Text Color is not changing #505

Open
PKYADAV opened this issue Oct 12, 2023 · 1 comment
Open

Overlay Text Color is not changing #505

PKYADAV opened this issue Oct 12, 2023 · 1 comment

Comments

@PKYADAV
Copy link

PKYADAV commented Oct 12, 2023

I am trying to write overlay text on images using Microsoft Maui Graphics and it's working but I am not able to change the text color from white to any other colors.

.Net 7 and Ubuntu 22.04 and 20.04

`void OverlayImage(string? path)
{
var resizeFactor = 0.9f;
var bitmap = SKBitmap.Decode(path);

        var toBitmap = new SKBitmap((int)Math.Round(bitmap.Width * resizeFactor), (int)Math.Round(bitmap.Height * resizeFactor), bitmap.ColorType, bitmap.AlphaType);

        var canvas = new SKCanvas(toBitmap);
        // Draw a bitmap rescaled
        canvas.SetMatrix(SKMatrix.CreateScale(resizeFactor, resizeFactor));
        canvas.DrawBitmap(bitmap, 0, 0);
        canvas.ResetMatrix();
        float textSize = 12;
        
        var font = SKTypeface.FromFamilyName("Arial");
        var brush = new SKPaint
        {
            Typeface = font,
            TextSize = textSize,
            IsAntialias = true,
            Color = SKColor.Parse("#39FF14")
        };
        string drawText = $"Test Text: ABCD132456";
        canvas.DrawText(drawText, 10, 15, brush);
        canvas.DrawText("www.nidoworld.com", 10, bitmap.Height - (bitmap.Height * 13 / 100), brush);

        canvas.Flush();

        var image = SKImage.FromBitmap(toBitmap);
        var data = image.Encode(SKEncodedImageFormat.Jpeg, 90);
      
        var stream = new MemoryStream();
        data.SaveTo(stream);

        if (_isImageSave == true)
        {
            string? filePath = "some path";
            using FileStream file = new(filePath, FileMode.Create, FileAccess.Write);
            stream.WriteTo(file);
        }

        var bytesString = Convert.ToBase64String(stream.ToArray());
        data.Dispose();
        image.Dispose();
        canvas.Dispose();
        brush.Dispose();
        font.Dispose();
        toBitmap.Dispose();
        bitmap.Dispose();
        stream.Dispose();
    }`
@PKYADAV
Copy link
Author

PKYADAV commented Nov 29, 2023

Any update or information on this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant