private static Image <Rgba32> ImageBufferToImage32(IImageByte sourceImage) { var source = sourceImage.GetBuffer(); var invertedBuffer = new byte[source.Length]; int index = 0; for (int y = sourceImage.Height - 1; y >= 0; y--) { var line = sourceImage.GetBufferOffsetY(y); for (int x = 0; x < sourceImage.Width; x++) { var pix = x * 4; invertedBuffer[index++] = source[line + pix + 2]; invertedBuffer[index++] = source[line + pix + 1]; invertedBuffer[index++] = source[line + pix + 0]; invertedBuffer[index++] = source[line + pix + 3]; } } var image2 = SixLabors.ImageSharp.Image.LoadPixelData <Rgba32>(invertedBuffer, sourceImage.Width, sourceImage.Height); return(image2); }
public static bool SaveImageData(string filename, IImageByte sourceImage) { try { using (var tgaSave = new MemoryStream()) { var source = sourceImage.GetBuffer(); var invertedBuffer = new byte[source.Length]; int index = 0; for (int y = sourceImage.Height - 1; y >= 0; y--) { var line = sourceImage.GetBufferOffsetY(y); for (int x = 0; x < sourceImage.Width; x++) { var pix = x * 4; invertedBuffer[index++] = source[line + pix + 2]; invertedBuffer[index++] = source[line + pix + 1]; invertedBuffer[index++] = source[line + pix + 0]; invertedBuffer[index++] = source[line + pix + 3]; } } var image2 = SixLabors.ImageSharp.Image.LoadPixelData <Rgba32>(invertedBuffer, sourceImage.Width, sourceImage.Height); image2.Save(filename); } return(true); } catch { } return(false); }
public int GetBufferOffsetY(int y) { return(linkedImage.GetBufferOffsetY(y)); }