private void Form1_ResizeEnd(object sender, EventArgs e)
 {
     if (!Rendered)
     {
         if (DecalLoaded)
         {
             //decalPreview.Image = RenderSVGToFit(lastSourceFilename, decalPreview.Width, decalPreview.Height);
             decalPreview.Image = BitmapHelper.ResizeBitmapToFit(SourceBitmap, decalPreview.Width, decalPreview.Height, (lastWidthHeight.Item1 / lastWidthHeight.Item2));
         }
     }
     else
     {
         decalPreview.Image = lastGenerated;
     }
     centerWaitGraphic();
 }
        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 Bitmap ResizeBitmapToFit(Bitmap sourceBitmap, int width, int height, float aspectRatio)
        {
            int renderheight, renderwidth;

            if ((aspectRatio <= 1.0f))
            {
                renderheight = height;
                renderwidth  = (int)(height * aspectRatio);
            }
            else
            {
                renderheight = (int)(width * (1.0f / aspectRatio));
                renderwidth  = width;
            }
            return(BitmapHelper.ResizeBitmap(sourceBitmap, renderwidth, renderheight, InterpolationMode.Bilinear));
        }
        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);
        }
예제 #6
0
        public static Bitmap ToBitmap(Grid g1, Grid g2, int scalefactor, InterpolationMode interpolation, int spreadfactor = -1)
        {
            uint[] buffer;
            if (spreadfactor == -1)
            {
                spreadfactor = scalefactor;
            }
            Bitmap bmp    = BitmapHelper.CreateNewManagedBitmap(g1.Width, g1.Height, out buffer);
            float  spread = Math.Min(g1.Width, g1.Height) / (1 << spreadfactor);

            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));
        }