public static SKImage?Decode(this UTexture2D texture) { if (!texture.IsVirtual && texture.GetFirstMip() is { } mip) { DecodeTexture(mip, texture.Format, out byte[] data, out var colorType); using var bitmap = new SKBitmap(new SKImageInfo(mip.SizeX, mip.SizeY, colorType, SKAlphaType.Unpremul)); unsafe { fixed(byte *p = data) { bitmap.SetPixels(new IntPtr(p)); } } return(SKImage.FromBitmap(bitmap)); } return(null); }
public static SKImage?Decode(this UTexture2D texture, bool bNearest = false) { if (!texture.IsVirtual && texture.GetFirstMip() is { } mip) { DecodeTexture(mip, texture.Format, out byte[] data, out var colorType); var width = mip.SizeX; var height = mip.SizeY; using var bitmap = new SKBitmap(new SKImageInfo(width, height, colorType, SKAlphaType.Unpremul)); unsafe { fixed(byte *p = data) { bitmap.SetPixels(new IntPtr(p)); } } return(SKImage.FromBitmap(!bNearest ? bitmap : bitmap.Resize(new SKImageInfo(width, height), SKFilterQuality.None))); } return(null); }
public static SKBitmap?Decode(this UTexture2D texture, ETexturePlatform platform = ETexturePlatform.DesktopMobile) => texture.Decode(texture.GetFirstMip(), platform);