private static UniversalBitmap NormalizeBitmap(UniversalBitmap bitmap) { int oldWidth = bitmap.Width; int oldHeight = bitmap.Height; int newWidth = CrayonWrapper.nextPowerOf2(oldWidth); int newHeight = CrayonWrapper.nextPowerOf2(oldHeight); if (newWidth == oldWidth && newHeight == oldHeight) { return(bitmap); } UniversalBitmap newBmp = new UniversalBitmap(newWidth, newHeight); newBmp.GetActiveDrawingSession().Draw(bitmap, 0, 0, 0, 0, oldWidth, oldHeight).Flush(); return(newBmp); }
public static void SendImageToRenderer(object frameObj, int id, object nativeImageData, int x, int y, int width, int height) { NoriFrame frame = (NoriFrame)frameObj; UniversalBitmap atlas = (UniversalBitmap)nativeImageData; UniversalBitmap cropped; if (atlas.Width == width && atlas.Height == height) { cropped = atlas; } else { cropped = new UniversalBitmap(width, height); UniversalBitmap.DrawingSession session = cropped.GetActiveDrawingSession(); session.Draw(atlas, 0, 0, x, y, width, height); session.Flush(); } byte[] pngBytes = cropped.GetBytesAsPng(); string base64Image = UniversalBitmap.ToBase64("data:image/png;base64,", pngBytes); frame.SendImageToBrowser(id, width, height, base64Image); }