You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SkiaSharp.SKBitmap替代System.Drawing.Bitmap未达预期效果

SkiaSharp替代System.Drawing时像素读取异常问题

原System.Drawing实现代码

byte[] logoBytes = decodeBase64SafeWeb(json["logo.png"].ToString());
using (Bitmap bitmapold = (Bitmap)Bitmap.FromStream(new MemoryStream(logoBytes)))
{
    // 处理bitmapold的业务代码
}

替换为SkiaSharp的代码

byte[] logoBytes = decodeBase64SafeWeb(json["logo.png"].ToString());    
using (var stream = new SKMemoryStream(logoBytes))
using (var bitmap = SKBitmap.Decode(stream))
{
    // 处理bitmap的业务代码
}

问题现象

在后续遍历像素的代码中:

for (int i = 0; i < bmp.Height; i++)
{
    // 遍历每一行
    for (int j = 0; j < bmp.Width; j++)
    {
        Color pixel = bmp.GetPixel(j, i);
        // 像素处理逻辑
    }
}
  • 使用System.Drawing的bitmapold时,所有首像素均为有效值
  • 使用SkiaSharp的bitmap时,所有首像素的值均为0

已尝试的无效方案

  • 跳过流直接从byte[]解码SkiaSharp Bitmap
  • 调用stream.Seek(0, SeekOrigin.Begin);重置流读取位置
  • 尝试对比两者非零像素,但System.Drawing的Bitmap未暴露像素数据无法实现

内容的提问来源于stack exchange,提问作者RiB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 17:43:12