示例#1
0
        public void setPen(int size, Color color, penType type)
        {
            drawing   = false;
            penSize   = size * magfactor;
            penImages = new List <Bitmap>();
            double mult = 1;

            while ((int)(size * mult) >= 0.2)
            {
                if (type == penType.softpen)
                {
                    penImages.Add(getPenImage(penSize + 2, penSize * (float)mult, color, type, mult));
                }
                else
                {
                    penImages.Add(getPenImage(penSize, penSize, color, type, mult));
                }
                //penImages.Add(getPenImage(penSize + 2, (int)(penSize * mult), color, type, 1.0));
                mult -= 0.02;
            }
            this.type = type;
            if (type == penType.highlighter)
            {
                for (int n = 0; n < penImages.Count; n++)
                {
                    int size2 = penImages[n].Width;
                    int fade  = size / 4;
                    if (fade == 0)
                    {
                        fade = 1;
                    }
                    for (int x = 0; x < size2; x++)
                    {
                        for (int y = 0; y < size2; y++)
                        {
                            Color c = penImages[n].GetPixel(x, y);
                            penImages[n].SetPixel(x, y, Color.FromArgb(c.A / fade, c));
                        }
                    }
                }
            }

            /*//Temporary pen test
            *  startDrawing(10, 10, 5);
            *  for(int n = 6; n<= Width -6 ; n++)
            *  {
            *   DrawTo(n, 10, (512 * n / Width));
            *  }
            *  endDrawing();
            *  Graphics g = Graphics.FromImage(activeLayerImg);
            *  for(int n = 0; n< penImages.Count; n++)
            *  {
            *   g.DrawImage(penImages[n], 10 + (Width / penImages.Count) * n, 20);
            *   g.DrawImage(penImages[n], 10 + (Width / penImages.Count) * n, 20);
            *   g.DrawImage(penImages[n], 10 + (Width / penImages.Count) * n, 20);
            *  }
            *  //End temp pen test */
        }
示例#2
0
        /*       public void startTabletCapture()
         *     {
         *         //Here temporally
         *         if (CWintabInfo.IsWintabAvailable())
         *         {
         *             InitDataCapture(200, 200, false);
         *         }
         *     }*/

        public Bitmap getPenImage(int imgsize, float pensize, Color color, penType type, double pressureMultiplier)
        {
            if (pressureMultiplier > 1.0)
            {
                pressureMultiplier = 1.0;
            }
            if (pensize > imgsize)
            {
                pensize = imgsize;
            }
            float  offset = ((float)imgsize - pensize) / 2;
            Bitmap rawPen;

            switch (type)
            {
            case penType.softpen:
                rawPen = new Bitmap(Properties.Resources.softpen);
                break;

            case penType.airbrush:
                rawPen = new Bitmap(Properties.Resources.airbrush);
                break;

            case penType.brush:
                rawPen = new Bitmap(Properties.Resources.brush);
                break;

            case penType.highlighter:
                rawPen = new Bitmap(Properties.Resources.highlighter);
                break;

            case penType.marker:
                rawPen = new Bitmap(Properties.Resources.marker);
                break;

            case penType.spray:
                rawPen = new Bitmap(Properties.Resources.spray);
                break;

            default:     // includes eraser
                rawPen = new Bitmap(Properties.Resources.softpen);
                break;
            }

            /*for (int x = 0; x < rawPen.Width; x++)
             * {
             *  for (int y = 0; y < rawPen.Height; y++)
             *  {
             *      Color c = rawPen.GetPixel(x, y);
             *      int newalpha = (int)((double)c.R * pressureMultiplier);
             *      rawPen.SetPixel(x, y, Color.FromArgb(newalpha, color));
             *  }
             * }*/

            Bitmap   pen = new Bitmap(imgsize, imgsize);
            Graphics g   = Graphics.FromImage(pen);

            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            //g.DrawImage(rawPen, 0, 0, imgsize, imgsize);
            g.DrawImage(rawPen, new RectangleF(offset, offset, pensize, pensize));
            if (type == penType.softpen)
            {
                for (int x = 0; x < imgsize; x++)
                {
                    for (int y = 0; y < imgsize; y++)
                    {
                        Color c        = pen.GetPixel(x, y);
                        int   newalpha = (int)((double)c.R * pressureMultiplier / 3);
                        pen.SetPixel(x, y, Color.FromArgb(newalpha, color));
                    }
                }
            }
            else
            {
                for (int x = 0; x < imgsize; x++)
                {
                    for (int y = 0; y < imgsize; y++)
                    {
                        Color c        = pen.GetPixel(x, y);
                        int   newalpha = (int)((double)c.A * pressureMultiplier / 3);
                        pen.SetPixel(x, y, Color.FromArgb(newalpha, color));
                    }
                }
            }
            return(pen);
        }