public static void WriteAsImageSharp <TSelfPixel, TOtherPixel>(PointerBitmap self, Action <Image <TOtherPixel> > action) where TSelfPixel : unmanaged where TOtherPixel : unmanaged, IPixel <TOtherPixel> { _Verify <TSelfPixel, TOtherPixel>(self.Info); if (self.Info.IsContinuous) { var m = self.UsingMemory <TOtherPixel>(); var s = self.Size; using (var selfImg = Image.WrapMemory(m, s.Width, s.Height)) { Run(selfImg, action); } } else { using (var selfImg = new Image <TOtherPixel>(self.Width, self.Height)) { _Implementation.CopyPixels(self, selfImg); Run(selfImg, action); _Implementation.CopyPixels(selfImg, self); } } }
public static TResult ReadAsImageSharp <TSelfPixel, TOtherPixel, TResult>(PointerBitmap self, Func <Image <TOtherPixel>, TResult> function) where TSelfPixel : unmanaged where TOtherPixel : unmanaged, IPixel <TOtherPixel> { _Verify <TSelfPixel, TOtherPixel>(self.Info); if (self.Info.IsContinuous) { var m = self.UsingMemory <TOtherPixel>(); var s = self.Size; using (var selfImg = Image.WrapMemory(m, s.Width, s.Height)) { return(Run(selfImg, function)); } } else { using (var selfImg = new Image <TOtherPixel>(self.Width, self.Height)) { _Implementation.CopyPixels(self, selfImg); return(Run(selfImg, function)); } } }