SKImage 加载图像,但当它有黄色时将其绘制为蓝色

问题描述 投票:0回答:1

问题

绘制 png 图像时,它是用蓝色色调绘制的。请帮忙,我已经被这个问题困扰了 4 个多小时了。

代码

更新了

canvas
的创建方式

SKImageInfo info = new SKImageInfo(2000, 2000);
SKBitmap bitmap = new SKBitmap(info);
Texture texture = new Texture((uint)bitmap.Width, (uint)bitmap.Height);
Sprite sprite = new Sprite(texture);
var surface = SKSurface.Create(bitmap.Info, bitmap.GetPixels(), bitmap.RowBytes);
var canvas = surface.Canvas;

var X = 0;
var Y = 0;
var paint = new SKPaint {
    IsAntialias = true,
    Color = SKColors.White,
    BlendMode = SKBlendMode.SrcOver,
    IsDither = true,
    ColorFilter = SKColorFilter.CreateBlendMode(SKColors.White, SKBlendMode.Modulate)
}
var cursorImage = SKImage.FromEncodedData("my_yellow_file.png");
var cursorPositionSrc = new SKRect(0, 0, cursorImage.Width, cursorImage.Height);
var cursorPositionDest = new SKRect(
    X,
    Y - (cursorImage.Height / 2),
    X + cursorImage.Width,
    Y + (cursorImage.Height / 2)
);
// canvas is a large surface to draw on
canvas.DrawImage(this.cursorImage, cursorPositionSrc, this.cursorPositionDest, this.cursorPaint);

图片

图像元数据详细信息

enter image description here

渲染/绘制图像

enter image description here

机器规格

操作系统:Win11

c# .net graphics game-development skiasharp
1个回答
0
投票

发现问题了,是画布的色彩空间问题

SKImageInfo info = new SKImageInfo(2000, 2000);

应该是

SKImageInfo info = new SKImageInfo(2000, 2000, SKColorType.Rgba8888, SKAlphaType.Premul);
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.