public static Bitmap ToBitmap(Grid g1, Grid g2, int scalefactor, InterpolationMode interpolation) { uint[] buffer; Bitmap bmp = BitmapHelper.CreateNewManagedBitmap(g1.Width, g1.Height, out buffer); float spread = Math.Min(g1.Width, g1.Height) / (1 << scalefactor); float min = -spread; float max = spread; int width = bmp.Width; int height = bmp.Height; int idx = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float dst = g1.grid[idx].Dist() - g2.grid[idx].Dist(); dst = dst < 0 ? -128 * (dst - min) / min : 128 + 128 * dst / max; uint channel = (uint)Math.Max(0, Math.Min(255, dst)); uint val = (channel << 24) | (channel << 16) | (channel << 8) | channel; buffer[idx] = val; idx++; } } return(BitmapHelper.ResizeBitmap(bmp, g1.Width >> scalefactor, g1.Height >> scalefactor, interpolation)); }
public static Bitmap RenderDistanceFieldForChar(char c, Font f, int width, int height, InterpolationMode interpolation) { uint[] buffer; Bitmap bmp = BitmapHelper.CreateNewManagedBitmap(width, height, out buffer); using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(Color.White); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; g.SmoothingMode = SmoothingMode.HighQuality; g.DrawString(c.ToString(), f, Brushes.Black, new PointF(0, 0)); } return(CreateDistanceField(interpolation, width, height, 3, buffer)); }
public static void RenderSvgToDistanceFieldToFile(string input, string output) { uint[] buffer; int width = 4096; int height = 4096; Bitmap svg = RenderSvgToBitmapWithMaximumSize(input, width, height); Bitmap bmp = BitmapHelper.CreateNewManagedBitmap(width, height, out buffer); using (Graphics g = Graphics.FromImage(bmp)) { g.DrawImage(svg, 0, 0); } ConvertToMonochrome(buffer, width, height); CreateAndStoreBigDistanceField(InterpolationMode.HighQualityBicubic, width, height, 5, output, buffer); }
public static Bitmap RenderSvgToDistanceFieldToBMP(string input, int scaleFactor = 5, int spreadfactor = -1, int sourceWidth = 4096, int sourceHeight = 4096) { uint[] buffer; //TODO: make these a config setting int width = sourceWidth; int height = sourceHeight; Bitmap svg = RenderSvgToBitmapWithMaximumSize(input, width, height); Bitmap bmp = BitmapHelper.CreateNewManagedBitmap(width, height, out buffer); using (Graphics g = Graphics.FromImage(bmp)) { g.DrawImage(svg, 0, 0); } ConvertToMonochrome(buffer, width, height); return(CreateBigDistanceField(InterpolationMode.HighQualityBicubic, width, height, scaleFactor, buffer, spreadfactor)); //return CreateDistanceField(InterpolationMode.HighQualityBicubic, width, height, scaleFactor, buffer); }