void RenderWithMsdfImg(Typeface typeface, char testChar, float sizeInPoint) { p.FillColor = PixelFarm.Drawing.Color.Black; //p.UseSubPixelRendering = chkLcdTechnique.Checked; p.Clear(PixelFarm.Drawing.Color.White); //---------------------------------------------------- var builder = new MyGlyphPathBuilder(typeface); var hintTech = (HintTechnique)cmbHintTechnique.SelectedItem; builder.UseTrueTypeInstructions = false; //reset builder.UseVerticalHinting = false; //reset switch (hintTech) { case HintTechnique.TrueTypeInstruction: builder.UseTrueTypeInstructions = true; break; case HintTechnique.TrueTypeInstruction_VerticalOnly: builder.UseTrueTypeInstructions = true; builder.UseVerticalHinting = true; break; case HintTechnique.CustomAutoFit: //custom agg autofit break; } //---------------------------------------------------- builder.Build(testChar, sizeInPoint); //---------------------------------------------------- var msdfGlyphGen = new MsdfGlyphGen(); GlyphImage2 glyphImg = msdfGlyphGen.CreateMsdfImage( builder.GetOutputPoints(), builder.GetOutputContours(), builder.GetPixelScale()); var actualImg = ActualImage.CreateFromBuffer(glyphImg.Width, glyphImg.Height, PixelFormat.ARGB32, glyphImg.GetImageBuffer()); p.DrawImage(actualImg, 0, 0); //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a001_xn2_" + n + ".png"); //} if (chkShowGrid.Checked) { //render grid RenderGrid(800, 600, _gridSize, p); } //6. use this util to copy image from Agg actual image to System.Drawing.Bitmap PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp); //--------------- //7. just render our bitmap g.Clear(Color.White); g.DrawImage(winBmp, new Point(30, 20)); }
void RenderWithMsdfImg(Typeface typeface, char testChar, float sizeInPoint) { painter.FillColor = PixelFarm.Drawing.Color.Black; //p.UseSubPixelRendering = chkLcdTechnique.Checked; painter.Clear(PixelFarm.Drawing.Color.White); //---------------------------------------------------- var builder = new GlyphPathBuilder(typeface); builder.SetHintTechnique(_glyphRenderOptions.HintTechnique); //---------------------------------------------------- builder.Build(testChar, sizeInPoint); //---------------------------------------------------- var glyphToContour = new GlyphContourBuilder(); var msdfGenPars = new MsdfGenParams(); builder.ReadShapes(glyphToContour); //glyphToContour.Read(builder.GetOutputPoints(), builder.GetOutputContours()); MsdfGenParams genParams = new MsdfGenParams(); GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(glyphToContour, genParams); var actualImg = ActualImage.CreateFromBuffer(glyphImg.Width, glyphImg.Height, PixelFormat.ARGB32, glyphImg.GetImageBuffer()); painter.DrawImage(actualImg, 0, 0); //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a001_xn2_" + n + ".png"); //} if (_contourAnalysisOpts.ShowGrid) { //render grid RenderGrids(800, 600, _gridSize, painter); } //6. use this util to copy image from Agg actual image to System.Drawing.Bitmap PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp); //--------------- //7. just render our bitmap g.Clear(Color.White); g.DrawImage(winBmp, new Point(30, 20)); }