簡體   English   中英

SkiaSharp 使用 ICC 配置文件保存圖像

[英]SkiaSharp save image with ICC profile

在 SkiaSharp 中,當您從現有圖像創建新圖像時(例如調整大小時),您如何使用來自原始圖像的 ICC 配置文件保存新圖像?

所以答案是:如果在源圖像和目標圖像之間設置和維護ColorSpace Skia 將自動應用 ICC 配置文件。

必須在源對象和目標對象(SKBitmap、SKImage、SKSurface 等)上設置ColorSpace 這樣 Skia 就可以知道如何在源和目標之間轉換顏色。 如果ColorSpace未在其中任何一個上設置,或者如果ColorSpace在此過程中丟失(這在您創建新對象時很容易發生),Skia 將使用默認設置,這可能會扭曲顏色轉換。

維護 ColorSpace 的正確方法示例:

using (SKData origData = SKData.Create(imgStream)) // convert the stream into SKData
using (SKImage srcImg = SKImage.FromEncodedData(origData))
    // srcImg now contains the original ColorSpace (e.g. CMYK)
{
    SKImageInfo info = new SKImageInfo(resizeWidth, resizeHeight,
        SKImageInfo.PlatformColorType, SKAlphaType.Premul, SKColorSpace.CreateSrgb());
    // this is the important part. set the destination ColorSpace as
    // `SKColorSpace.CreateSrgb()`. Skia will then be able to automatically convert
    // the original CMYK colorspace, to this new sRGB colorspace.

    using (SKImage newImg = SKImage.Create(info)) // new image. ColorSpace set via `info`
    {
        srcImg.ScalePixels(newImg.PeekPixels(), SKFilterQuality.None);
        // now when doing this resize, Skia knows the original ColorSpace, and the
        // destination ColorSpace, and converts the colors from CMYK to sRGB.
    }
}

另一個維護 ColorSpace 的例子:

using (SKCodec codec = SKCodec.Create(imgStream)) // create a codec with the imgStream
{
    SKImageInfo info = new SKImageInfo(codec.Info.Width, codec.Info.Height,
        SKImageInfo.PlatformColorType, SKAlphaType.Premul, SKColorSpace.CreateSrgb());
    // set the destination ColorSpace via SKColorSpace.CreateSrgb()

    SKBitmap srcImg = SKBitmap.Decode(codec, info);
    // Skia creates a new bitmap, converting the codec ColorSpace (e.g. CMYK) to the
    // destination ColorSpace (sRGB)
}

關於 Skia 色彩校正的其他非常有用的信息: https ://skia.org/user/sample/color?cl = 9919

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM