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

Overlay Text Color is not changing  #505

Description

@PKYADAV

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();
    }`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions