コード例 #1
0
        public override void Load()
        {
            //draw 1

            FormTestWinGLControl form   = new FormTestWinGLControl();
            CanvasGL2d           canvas = new CanvasGL2d(this.Width, this.Height);
            GLBitmap             hwBmp  = null;

            form.SetGLPaintHandler((o, s) =>
            {
                canvas.Clear(PixelFarm.Drawing.Color.White);
                canvas.StrokeColor = PixelFarm.Drawing.Color.DeepPink;
                canvas.DrawLine(0, 300, 500, 300);

                //if (hwBmp == null)
                //{
                //    string app = Application.ExecutablePath;
                //    hwBmp = GLBitmapTextureHelper.CreateBitmapTexture(new Bitmap("../../../Data/Textures/logo-dark.jpg"));

                //}

                ////canvas.DrawImage(hwBmp, 10, 10);
                //canvas.DrawImage(hwBmp, 300, 300, hwBmp.Width / 4, hwBmp.Height / 4);
                //-----------------------------------------------------
                canvas.StrokeColor = PixelFarm.Drawing.Color.Magenta;
                //draw line test
                canvas.DrawLine(20, 20, 600, 200);
                //-----------------------------------------------------
                var color = new PixelFarm.Drawing.Color(50, 255, 0, 0);  //  PixelFarm.Drawing.Color.Red;
                //rect polygon
                var polygonCoords = new float[] {
                    5, 300,
                    40, 300,
                    50, 340,
                    10f, 340
                };
                canvas.DrawPolygon(polygonCoords, 4);
                //fill polygon test
                canvas.FillPolygon(color, polygonCoords);

                var polygonCoords2 = new float[] {
                    5 + 10, 300,
                    40 + 10, 300,
                    50 + 10, 340,
                    10f + 10, 340
                };

                canvas.SmoothMode  = CanvasSmoothMode.AggSmooth;
                canvas.StrokeColor = new PixelFarm.Drawing.Color(100, 0, 255, 0);  //  L
                canvas.DrawPolygon(polygonCoords2, 4);

                int strkW          = 10;
                canvas.StrokeColor = PixelFarm.Drawing.Color.LightGray;

                for (int i = 1; i < 90; i += 10)
                {
                    canvas.StrokeWidth = strkW;
                    double angle       = OpenTK.MathHelper.DegreesToRadians(i);
                    canvas.DrawLine(20, 400, (float)(600 * Math.Cos(angle)), (float)(600 * Math.Sin(angle)));

                    strkW--;
                    if (strkW < 1)
                    {
                        strkW = 1;
                    }
                }


                canvas.StrokeColor = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Green);

                //////---------------------------------------------
                //////draw ellipse and circle

                canvas.StrokeWidth = 0.75f;
                canvas.DrawCircle(400, 500, 50);
                canvas.FillCircle(PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Green), 450, 550, 25);

                canvas.StrokeWidth = 3;
                canvas.DrawRoundRect(500, 450, 100, 100, 10, 10);


                canvas.StrokeWidth = 3;
                canvas.StrokeColor = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Blue);

                //canvas.DrawBezierCurve(0, 0, 500, 500, 0, 250, 500, 250);
                canvas.DrawBezierCurve(120, 500 - 160, 220, 500 - 40, 35, 500 - 200, 220, 500 - 260);
                canvas.SmoothMode = CanvasSmoothMode.No;

                //canvas.DrawArc(150, 200, 300, 50, 0, 150, 150, SvgArcSize.Large, SvgArcSweep.Negative);
                canvas.DrawArc(100, 200, 300, 200, 30, 30, 50, SvgArcSize.Large, SvgArcSweep.Negative);

                canvas.StrokeColor = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Green);
                // canvas.DrawArc(100, 200, 300, 200, 0, 100, 100, SvgArcSize.Large, SvgArcSweep.Negative);

                canvas.StrokeColor = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Black);
                canvas.DrawLine(100, 200, 300, 200);


                //////load font data
                ////var font = PixelFarm.Agg.Fonts.NativeFontStore.LoadFont("c:\\Windows\\Fonts\\Tahoma.ttf", 64);
                ////var fontGlyph = font.GetGlyph('{');
                //////PixelFarm.Font2.MyFonts.SetShapingEngine();

                ////canvas.FillVxs(PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Black), fontGlyph.flattenVxs);

                ////canvas.StrokeColor = PixelFarm.Drawing.Color.White;
                ////canvas.CurrentFont = font;

                ////canvas.StrokeColor = PixelFarm.Drawing.Color.Black;
                ////canvas.DrawLine(0, 200, 500, 200);

                //////test Thai words
                ////canvas.DrawString("ดุดีดำด่าด่ำญญู", 80, 200);
                ////canvas.DrawString("1234567890", 80, 200);
                ////GLBitmap bmp = new GLBitmap(new LazyAggBitmapBufferProvider(fontGlyph.glyphImage32));
                ////canvas.DrawImage(bmp, 50, 50);
                ////bmp.Dispose();
            });
            form.Show();
        }
コード例 #2
0
 protected override void OnSetVarsBeforeRenderer()
 {
     PixelFarm.Drawing.Color fgColor = ForegroundColor;
     _fgColor.SetValue((float)fgColor.R / 255f, (float)fgColor.G / 255f, (float)fgColor.B / 255f, (float)fgColor.A / 255f);
 }
コード例 #3
0
 /// <summary>
 /// Converts a System.Drawing.Color to a System.Int32.
 /// </summary>
 /// <param name="c">The System.Drawing.Color to convert.</param>
 /// <returns>A System.Int32 containing the R, G, B, A values of the
 /// given System.Drawing.Color in the Rbga32 format.</returns>
 public static int ColorToRgba32(PixelFarm.Drawing.Color c)
 {
     return((int)((c.A << 24) | (c.B << 16) | (c.G << 8) | c.R));
 }
コード例 #4
0
 public override void ClearSurface(PixelFarm.Drawing.Color c)
 {
     painter1.Clear(c);
 }
コード例 #5
0
        //----------------------------------------------------------------------------
        public static void CalculateLinearGradientVxs2(
            float x1, float y1,
            float x2, float y2,
            PixelFarm.Drawing.Color c1,
            PixelFarm.Drawing.Color c2,
            out float[] v2f,
            out float[] colors)
        {
            //1. gradient distance
            float dx       = x2 - x1;
            float dy       = y2 - y1;
            float distance = (float)Math.Pow(dx * dx + dy * dy, 0.5f);
            //find angle
            double angleRad = Math.Atan2(dy, dx);

            if (dx < 0)
            {
                //swap
                float tmpx = x2;
                x2 = x1;
                x1 = tmpx;
                float tmpy = y2;
                y2 = y1;
                y1 = tmpy;
                PixelFarm.Drawing.Color tmpc = c2;
                c2 = c1;
                c1 = tmpc;
            }

            ArrayList <VertexC4V3f> vrx = new ArrayList <VertexC4V3f>();

            //left solid rect pane

            AddRect(vrx,
                    c1.ToABGR(), c1.ToABGR(),
                    -600, -800,
                    x1 + 600, 1800);
            //color gradient pane
            AddRect(vrx,
                    c1.ToABGR(), c2.ToABGR(),
                    x1, -800,
                    distance, 1800);
            //right solid pane
            if (1200 - (x1 + distance) > 0)
            {
                AddRect(vrx,
                        c2.ToABGR(), c2.ToABGR(),
                        (x1 + distance), -800,
                        1200 - (x1 + distance), 1800);
            }
            //----------------------------------------------
            //translate vertex around x1,y1

            PixelFarm.Agg.Transform.AffinePlan[] affPlans =
                new PixelFarm.Agg.Transform.AffinePlan[] {
                PixelFarm.Agg.Transform.AffinePlan.Translate(-x1, -y1),
                PixelFarm.Agg.Transform.AffinePlan.Rotate(angleRad),
                PixelFarm.Agg.Transform.AffinePlan.Translate(x1, y1)
            };
            var          txMatrix  = PixelFarm.Agg.Transform.Affine.NewMatix(affPlans);
            int          j         = vrx.Count;
            List <float> v2fList   = new List <float>();
            List <float> colorList = new List <float>();

            for (int i = 0; i < j; ++i)
            {
                VertexC4V3f v   = vrx[i];
                double      v_x = v.x;
                double      v_y = v.y;
                txMatrix.Transform(ref v_x, ref v_y);
                //vrx[i] = new VertexC4V3f(v.color, (float)v_x, (float)v_y);
                v2fList.Add((float)v_x);
                v2fList.Add((float)v_y);
                var color = v.color;
                //a,b,g,r

                colorList.Add((color & 0xff) / 255f);         //r
                colorList.Add(((color >> 8) & 0xff) / 255f);  //g
                colorList.Add(((color >> 16) & 0xff) / 255f); //b
                colorList.Add(((color >> 24) & 0xff) / 255f); //a
            }
            v2f    = v2fList.ToArray();
            colors = colorList.ToArray();
        }
コード例 #6
0
 public static int ColorToWin32(PixelFarm.Drawing.Color c)
 {
     return((c.R | (c.G << 8)) | (c.B << 0x10));
 }
コード例 #7
0
        public static ArrayList <VertexC4V3f> CalculateLinearGradientVxs(
            float x1, float y1,
            float x2, float y2,
            PixelFarm.Drawing.Color c1,
            PixelFarm.Drawing.Color c2)
        {
            //1. gradient distance
            float dx       = x2 - x1;
            float dy       = y2 - y1;
            float distance = (float)Math.Pow(dx * dx + dy * dy, 0.5f);
            //find angle
            double angleRad = Math.Atan2(dy, dx);

            if (dx < 0)
            {
                //swap
                float tmpx = x2;
                x2 = x1;
                x1 = tmpx;
                float tmpy = y2;
                y2 = y1;
                y1 = tmpy;
                PixelFarm.Drawing.Color tmpc = c2;
                c2 = c1;
                c1 = tmpc;
            }

            ArrayList <VertexC4V3f> vrx = new ArrayList <VertexC4V3f>();

            //left solid rect pane
            AddRect(vrx,
                    c1.ToABGR(), c1.ToABGR(),
                    -600, -800,
                    x1 + 600, 1800);
            //color gradient pane
            AddRect(vrx,
                    c1.ToABGR(), c2.ToABGR(),
                    x1, -800,
                    distance, 1800);
            //right solid pane
            if (1200 - (x1 + distance) > 0)
            {
                AddRect(vrx,
                        c2.ToABGR(), c2.ToABGR(),
                        (x1 + distance), -800,
                        1200 - (x1 + distance), 1800);
            }
            //----------------------------------------------
            //translate vertex around x1,y1

            PixelFarm.Agg.Transform.AffinePlan[] affPlans =
                new PixelFarm.Agg.Transform.AffinePlan[] {
                PixelFarm.Agg.Transform.AffinePlan.Translate(-x1, -y1),
                PixelFarm.Agg.Transform.AffinePlan.Rotate(angleRad),
                PixelFarm.Agg.Transform.AffinePlan.Translate(x1, y1)
            };
            var txMatrix = PixelFarm.Agg.Transform.Affine.NewMatix(affPlans);
            int j        = vrx.Count;

            for (int i = j - 1; i >= 0; --i)
            {
                VertexC4V3f v   = vrx[i];
                double      v_x = v.x;
                double      v_y = v.y;
                txMatrix.Transform(ref v_x, ref v_y);
                vrx[i] = new VertexC4V3f(v.color, (float)v_x, (float)v_y);
            }
            return(vrx);
        }
コード例 #8
0
 public void DrawMarker(float x, float y, PixelFarm.Drawing.Color color, float sizeInPx = 8)
 {
     painter.FillRect(x, y, sizeInPx, sizeInPx, color);
 }
コード例 #9
0
        //ActualBitmap GetTransformedBilinearInterpolation()
        //{
        //    //4 points sampling
        //    //weight between four point
        //    ActualBitmap destCB = new ActualBitmap(rect.Width, rect.Height);
        //    MyBitmapBlender destWriter = new MyBitmapBlender(destCB);
        //    PointF ptInPlane = new PointF();
        //    int x1, x2, y1, y2;
        //    double dab, dbc, dcd, dda;
        //    float dx1, dx2, dy1, dy2, dx1y1, dx1y2, dx2y1, dx2y2;
        //    int rectWidth = rect.Width;
        //    int rectHeight = rect.Height;
        //    Vector ab_vec = this.AB;
        //    Vector bc_vec = this.BC;
        //    Vector cd_vec = this.CD;
        //    Vector da_vec = this.DA;
        //    int rectLeft = this.rect.Left;
        //    int rectTop = this.rect.Top;



        //    for (int y = 0; y < rectHeight; ++y)
        //    {
        //        for (int x = 0; x < rectWidth; ++x)
        //        {
        //            PointF srcPt = new PointF(x, y);
        //            srcPt.Offset(rectLeft, rectTop);
        //            if (!IsOnPlaneABCD(srcPt))
        //            {
        //                continue;
        //            }
        //            //-------------------------------------
        //            dab = Math.Abs(MyVectorHelper.NewFromTwoPoints(_p0, srcPt).CrossProduct(ab_vec));
        //            dbc = Math.Abs(MyVectorHelper.NewFromTwoPoints(_p1, srcPt).CrossProduct(bc_vec));
        //            dcd = Math.Abs(MyVectorHelper.NewFromTwoPoints(_p2, srcPt).CrossProduct(cd_vec));
        //            dda = Math.Abs(MyVectorHelper.NewFromTwoPoints(_p3, srcPt).CrossProduct(da_vec));

        //            ptInPlane.X = (float)(srcW * (dda / (dda + dbc)));
        //            ptInPlane.Y = (float)(srcH * (dab / (dab + dcd)));
        //            x1 = (int)ptInPlane.X;
        //            y1 = (int)ptInPlane.Y;

        //            if (x1 >= 0 && x1 < srcW && y1 >= 0 && y1 < srcH)
        //            {
        //                //bilinear interpolation ***
        //                x2 = (x1 == srcW - 1) ? x1 : x1 + 1;
        //                y2 = (y1 == srcH - 1) ? y1 : y1 + 1;
        //                dx1 = ptInPlane.X - x1;
        //                if (dx1 < 0) dx1 = 0;
        //                dx1 = 1f - dx1;
        //                dx2 = 1f - dx1;
        //                dy1 = ptInPlane.Y - y1;
        //                if (dy1 < 0) dy1 = 0;
        //                dy1 = 1f - dy1;
        //                dy2 = 1f - dy1;
        //                dx1y1 = dx1 * dy1;
        //                dx1y2 = dx1 * dy2;
        //                dx2y1 = dx2 * dy1;
        //                dx2y2 = dx2 * dy2;
        //                //use 4 points


        //                Drawing.Color x1y1Color = srcCB.GetPixel(x1, y1);
        //                Drawing.Color x2y1Color = srcCB.GetPixel(x2, y1);
        //                Drawing.Color x1y2Color = srcCB.GetPixel(x1, y2);
        //                Drawing.Color x2y2Color = srcCB.GetPixel(x2, y2);
        //                float a = (x1y1Color.alpha * dx1y1) + (x2y1Color.alpha * dx2y1) + (x1y2Color.alpha * dx1y2) + (x2y2Color.alpha * dx2y2);
        //                float b = (x1y1Color.blue * dx1y1) + (x2y1Color.blue * dx2y1) + (x1y2Color.blue * dx1y2) + (x2y2Color.blue * dx2y2);
        //                float g = (x1y1Color.green * dx1y1) + (x2y1Color.green * dx2y1) + (x1y2Color.green * dx1y2) + (x2y2Color.green * dx2y2);
        //                float r = (x1y1Color.red * dx1y1) + (x2y1Color.red * dx2y1) + (x1y2Color.red * dx1y2) + (x2y2Color.red * dx2y2);
        //                destWriter.SetPixel(x, y, new Drawing.Color((byte)a, (byte)b, (byte)g, (byte)r));
        //            }
        //        }
        //    }
        //    return destCB;
        //}
        unsafe ActualBitmap GetTransformedBicubicInterpolation()
        {
            //4 points sampling
            //weight between four point
            PointF ptInPlane = new PointF();
            int    x1, x2, y1, y2;
            double dab, dbc, dcd, dda;
            //float dx1, dx2, dy1, dy2, dx1y1, dx1y2, dx2y1, dx2y2;
            int    destRectWidth  = _destBounds.Width;
            int    dectRectHeight = _destBounds.Height;
            Vector ab_vec         = this.AB;
            Vector bc_vec         = this.BC;
            Vector cd_vec         = this.CD;
            Vector da_vec         = this.DA;


            TempMemPtr    bufferPtr = _srcBmp.GetBufferPtr();
            BufferReader4 reader    = new BufferReader4((int *)bufferPtr.Ptr, _srcBmp.Width, _srcBmp.Height);

            ActualBitmap    destCB     = new ActualBitmap(_destBounds.Width, _destBounds.Height);
            MyBitmapBlender destWriter = new MyBitmapBlender(destCB);
            int             rectLeft   = this._destBounds.Left;
            int             rectTop    = this._destBounds.Top;

            //***
            PixelFarm.Drawing.Color[] colors = new PixelFarm.Drawing.Color[16];

            int srcW_lim = srcW - 2;
            int srcH_lim = srcH - 2;

            for (int y = 0; y < dectRectHeight; ++y)
            {
                for (int x = 0; x < destRectWidth; ++x)
                {
                    PointF srcPt = new PointF(x, y);
                    srcPt.Offset(rectLeft, 0);
                    if (!IsOnPlaneABCD(srcPt))
                    {
                        continue;
                    }
                    //-------------------------------------
                    dab         = Math.Abs(MyVectorHelper.NewFromTwoPoints(_p0, srcPt).CrossProduct(ab_vec));
                    dbc         = Math.Abs(MyVectorHelper.NewFromTwoPoints(_p1, srcPt).CrossProduct(bc_vec));
                    dcd         = Math.Abs(MyVectorHelper.NewFromTwoPoints(_p2, srcPt).CrossProduct(cd_vec));
                    dda         = Math.Abs(MyVectorHelper.NewFromTwoPoints(_p3, srcPt).CrossProduct(da_vec));
                    ptInPlane.X = (float)(srcW * (dda / (dda + dbc)));
                    ptInPlane.Y = (float)(srcH * (dab / (dab + dcd)));
                    x1          = (int)ptInPlane.X;
                    y1          = (int)ptInPlane.Y;
                    if (x1 >= 2 && x1 < srcW_lim &&
                        y1 >= 2 && y1 < srcH_lim)
                    {
                        reader.SetStartPixel(x1, y1);
                        //reader.Read16(pixelBuffer);
                        //do interpolate
                        //find src pixel and approximate
                        destWriter.SetPixel(x, y,

                                            GetApproximateColor_Bicubic(reader,
                                                                        colors,
                                                                        ptInPlane.X,
                                                                        ptInPlane.Y)); //TODO:review here blue switch to red channel
                    }
                }
                //newline
                // startLine += stride2;
                //targetPixelIndex = startLine;
            }

            bufferPtr.Release();
            //------------------------
            //System.Runtime.InteropServices.Marshal.Copy(
            //outputBuffer, 0,
            //bmpdata2.Scan0, outputBuffer.Length);
            //outputbmp.UnlockBits(bmpdata2);
            ////outputbmp.Save("d:\\WImageTest\\n_lion_bicubic.png");
            //return outputbmp;
            return(destCB);
        }
コード例 #10
0
ファイル: T110_Text.cs プロジェクト: brezza92/PixelFarm
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _pcx.SmoothMode  = SmoothMode.Smooth;
            _pcx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _pcx.ClearColorBuffer();
            _pcx.Clear(PixelFarm.Drawing.Color.White);


#if DEBUG
            //test only
            GLBitmapGlyphTextPrinter.s_dbugDrawTechnique    = DrawTextTechnique;
            GLBitmapGlyphTextPrinter.s_dbugUseVBO           = UseVbo;
            GLBitmapGlyphTextPrinter.s_dbugShowGlyphTexture = ShowGlyphTexture;
            GLBitmapGlyphTextPrinter.s_dbugShowMarkers      = ShowMarkers;
#endif

            //-------------------------------

            PixelFarm.Drawing.Color fillColor = PixelFarm.Drawing.Color.Black;
            switch (DrawTextColor)
            {
            case T110_DrawTextColor.Blue:
                fillColor = PixelFarm.Drawing.Color.Blue;
                break;

            case T110_DrawTextColor.Green:
                fillColor = PixelFarm.Drawing.Color.Green;
                break;

            case T110_DrawTextColor.Magenta:
                fillColor = PixelFarm.Drawing.Color.Magenta;
                break;

            case T110_DrawTextColor.Red:
                fillColor = PixelFarm.Drawing.Color.Red;
                break;

            case T110_DrawTextColor.Yellow:
                fillColor = PixelFarm.Drawing.Color.Yellow;
                break;
            }


            int line_top = 500;
            _painter.FontFillColor = fillColor;


            _painter.DrawString("aftjypqkx", 0, line_top);

            //
            line_top = 550;
            _painter.DrawString("1234567890 ABCD", 0, line_top);
            //-------------------------------
            line_top = 570;
            if (!string.IsNullOrEmpty(UserText))
            {
                _painter.DrawString(UserText, 0, line_top);
            }

            SwapBuffers();
        }
コード例 #11
0
 static SKColor ConvToSkColor(PixelFarm.Drawing.Color c)
 {
     return(new SKColor(c.R, c.G, c.B, c.A));
 }