[英]SkiaSharp save image with ICC profile
在 SkiaSharp 中,當您從現有圖像創建新圖像時(例如調整大小時),您如何使用來自原始圖像的 ICC 配置文件保存新圖像?
所以答案是:如果在源圖像和目標圖像之間設置和維護ColorSpace
Skia 將自動應用 ICC 配置文件。
必須在源對象和目標對象(SKBitmap、SKImage、SKSurface 等)上設置ColorSpace
。 這樣 Skia 就可以知道如何在源和目標之間轉換顏色。 如果ColorSpace
未在其中任何一個上設置,或者如果ColorSpace
在此過程中丟失(這在您創建新對象時很容易發生),Skia 將使用默認設置,這可能會扭曲顏色轉換。
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.
}
}
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.