Exemplo n.º 1
0
        public static Pixbuf ConvertToPixbuf(BitmapEx bmpEx)
        {
            int  bitspersample;
            bool HasAlpha;

            if (bmpEx.BitDepth == ImageType.RGB8)
            {
                bitspersample = 8; HasAlpha = false;
            }
            else if (bmpEx.BitDepth == ImageType.RGBA8)
            {
                bitspersample = 8; HasAlpha = true;
            }
            else if (bmpEx.BitDepth == ImageType.RGB16)
            {
                bitspersample = 16; HasAlpha = false;
            }
            else if (bmpEx.BitDepth == ImageType.RGBA16)
            {
                bitspersample = 16; HasAlpha = true;
            }
            else
            {
                throw new ArgumentException("Bitdepth not supported");
            }

            byte[] data = new byte[bmpEx.Height * bmpEx.Stride];
            bmpEx.LockBits();
            unsafe { System.Runtime.InteropServices.Marshal.Copy(bmpEx.Scan0, data, 0, data.Length); }
            bmpEx.UnlockBits();

            return(new Pixbuf(data, HasAlpha, bitspersample, (int)bmpEx.Width, (int)bmpEx.Height, (int)bmpEx.Stride));
        }
Exemplo n.º 2
0
        public void TestBitmapResize()
        {
            Color green = Color.FromArgb(0, 200, 0);
            Color red   = Color.FromArgb(200, 0, 0);

            using (var bitmap = new Bitmap(20, 20))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                    using (var gBrush = new SolidBrush(green))
                        using (var rBrush = new SolidBrush(red))
                        {
                            graphics.FillRectangle(gBrush, 0, 0, 10, 20);
                            graphics.FillRectangle(rBrush, 10, 0, 10, 20);
                        }

                using (var sourceRepresentation = new BitmapRepresentation(bitmap))
                    using (var sourceBitmapEx = sourceRepresentation.CreateBitmap())
                        using (var destinationBitmapEx = new BitmapEx(10, 10))
                        {
                            BitmapHelpers.ResizeBitmap(sourceBitmapEx, destinationBitmapEx);
                            var bmp = destinationBitmapEx.GetInternal();
                            {
                                var green2 = bmp.GetPixel(3, 5);
                                var red2   = bmp.GetPixel(7, 5);
                                Assert.AreEqual(true, CompareColors(green, green2, 5));
                                Assert.AreEqual(true, CompareColors(red, red2, 5));
                            }
                        }
            }
        }
Exemplo n.º 3
0
 public LayoutDrawElement(Location location, BitmapEx bitmap, TransitionInfo transitionInfo = default(TransitionInfo))
 {
     Location             = location;
     TransitionInfo       = transitionInfo;
     BitmapRepresentation = new BitmapRepresentation(bitmap);
     bitmap.Dispose();
 }
Exemplo n.º 4
0
        internal static void DrawElements(BitmapEx bitmap, params TextDrawElement[] elements)
        {
            using (var graphics = bitmap.CreateGraphics())
            {
                int yPosition = 0;
                for (var index = 0; index < elements.Length; index++)
                {
                    TextDrawElement element = elements[index];

                    var maxHeight  = bitmap.Height * element.Percentage / 100;
                    var textHeight = (element.Text != null)?FontEstimation.EstimateFontSize(bitmap, element.FontFamily, element.Text, alterHeight: maxHeight):0;

                    using (var brush = new SolidBrush(element.Color))
                        using (Font textFont = (textHeight > 0)?new Font(element.FontFamily, textHeight, GraphicsUnit.Pixel): null)
                        {
                            var size = graphics.MeasureString(element.Text, textFont);

                            float x = 0;
                            if (element.Alignment == StringAlignment.Center)
                            {
                                x = (bitmap.Width - size.Width) / 2;
                            }
                            else if (element.Alignment == StringAlignment.Far)
                            {
                                x = (bitmap.Width - size.Width);
                            }

                            graphics.DrawString(element.Text, textFont, brush, x, yPosition + (maxHeight - size.Height) / 2);
                        }

                    yPosition += maxHeight;
                }
            }
        }
Exemplo n.º 5
0
 public static void SelectElement(BitmapEx bitmap, ThemeOptions themeOptions)
 {
     using (var graphics = bitmap.CreateGraphics())
         using (var pen = new Pen(themeOptions.ForegroundColor, 3))
         {
             graphics.DrawRectangle(pen, 0, 0, bitmap.Width, bitmap.Height);
         }
 }
Exemplo n.º 6
0
        private void DrawLine(Queue <int> queue, BitmapEx bitmap, Color color)
        {
            while (queue.Count > bitmap.Width)
            {
                queue.Dequeue();
            }

            if (queue.Count > 1)
            {
                var array = queue.ToArray();

                DefaultDrawingAlgs.DrawPlot(bitmap, color, array, 0, bitmap.Height, minValue: 0, maxValue: 100);
            }
        }
Exemplo n.º 7
0
 internal void MainTable_SelectionChanged(object sender, EventArgs e)
 {
     try
     {
         if (MainTable.SelectedRows.Count > 0)
         {
             BitmapEx tmpBmp = ProjectManager.CurrentProject.GetThumb(MainTable.SelectedRows[0].Index);
             if (tmpBmp != null)
             {
                 ThumbViewList.Image = WinFormHelper.ConvertToBitmap(tmpBmp);
             }
         }
     }
     catch (Exception ex) { Error.Report("MainTable_SelectionChanged", ex); }
 }
Exemplo n.º 8
0
        public static void DrawTexts(BitmapEx bitmap, FontFamily fontFamily, string l1, string l2, string textExample, Color color)
        {
            var textHeight = FontEstimation.EstimateFontSize(bitmap, fontFamily, textExample);

            using (var graphics = bitmap.CreateGraphics())
                using (var whiteBrush = new SolidBrush(color))
                    using (var textFont = new Font(fontFamily, textHeight, GraphicsUnit.Pixel))
                    {
                        var size = graphics.MeasureString(l1, textFont);
                        graphics.DrawString(l1, textFont, whiteBrush, bitmap.Width - size.Width, 0);

                        size = graphics.MeasureString(l2, textFont);
                        graphics.DrawString(l2, textFont, whiteBrush, bitmap.Width - size.Width, bitmap.Height / 2);
                    }
        }
Exemplo n.º 9
0
        public static void DrawIconAndText(BitmapEx bitmap, FontFamily iconFontFamily, string iconSymbol, FontFamily textFontFamily, string text, string textExample, Color color)
        {
            var textHeight  = (text != null)?FontEstimation.EstimateFontSize(bitmap, textFontFamily, textExample):0;
            var imageHeight = (int)(bitmap.Height * 0.9 - textHeight);

            using (var graphics = bitmap.CreateGraphics())
                using (var whiteBrush = new SolidBrush(color))
                    using (Font textFont = (textHeight > 0)?new Font(textFontFamily, textHeight, GraphicsUnit.Pixel): null)
                        using (Font imageFont = new Font(iconFontFamily, imageHeight, GraphicsUnit.Pixel))
                        {
                            var size = graphics.MeasureString(text, textFont);
                            graphics.DrawString(text, textFont, whiteBrush, bitmap.Width - size.Width, bitmap.Height - size.Height);

                            graphics.DrawString(iconSymbol, imageFont, whiteBrush, 0, 0);
                        }
        }
Exemplo n.º 10
0
        private async void ProcessDraw()
        {
            try
            {
                var from = DateTime.Now.Subtract(_options.ExpiredMeetingTolerance);
                var to   = from.AddDays(2).Date;

                _appointments = _calendarServices.SelectMany(c => c.GetCalendar(from, to)).OrderBy(c => c.FromDateTime).ToArray();

                var rows    = _layoutContext.ButtonCount.Height;
                var columns = _layoutContext.ButtonCount.Width;
                LayoutDrawElement[] result = new LayoutDrawElement[columns * rows];

                for (byte i = 0; i < Math.Min(_layoutContext.ButtonCount.Height, _appointments.Length); i++)
                {
                    result[i * columns]     = new LayoutDrawElement(new Location(0, i), DrawText(FormatDateTime(_appointments[i].FromDateTime, _appointments[i].ToDateTime), _layoutContext));
                    result[i * columns + 1] = new LayoutDrawElement(new Location(2, i), DrawText(_appointments[i].Location, _layoutContext));
                    result[i * columns + 2] = new LayoutDrawElement(new Location(1, i), DrawText(_appointments[i].Organiser, _layoutContext));

                    byte firstNameIndex  = 3;
                    byte textButtonCount = (byte)(columns - firstNameIndex);
                    if (textButtonCount > 0)
                    {
                        using (var bitmap = new BitmapEx(_layoutContext.IconSize.Width * textButtonCount, _layoutContext.IconSize.Height))
                        {
                            bitmap.MakeTransparent();
                            DefaultDrawingAlgs.DrawText(bitmap, _layoutContext.Options.Theme.FontFamily, _appointments[i].Subject, _layoutContext.Options.Theme.ForegroundColor);
                            var elements = BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textButtonCount, 1), firstNameIndex, i, _layoutContext);
                            int j        = firstNameIndex;
                            foreach (var e in elements)
                            {
                                result[i * columns + j] = e;
                                j++;
                            }
                        }
                    }
                }

                DrawLayout?.Invoke(this, new DrawEventArgs(result));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception during weather station layout drawing: {ex}");
            }
        }
Exemplo n.º 11
0
        private async void ProcessDraw()
        {
            try
            {
                List <LayoutDrawElement> result = new List <LayoutDrawElement>(14);

                var weather = await _weatherStationService.GetHistorical();

                var values = weather.Union(new[] { await _weatherStationService.GetData() }).Select(m => _element.GetFunc(m)).ToArray();

                var currentValue = values.Last();
                var minValue     = values.Min();
                var maxValue     = values.Max();
                var avgValue     = values.Average();

                var color = _layoutContext.Options.Theme.ForegroundColor;

                result.Add(GetHeaderElement(0, 0, "Min", color));
                result.Add(GetHeaderElement(1, 0, "Avg", color));
                result.Add(GetHeaderElement(2, 0, "Max", color));
                result.Add(GetHeaderElement(3, 0, "Cur", color));

                result.Add(GetHeaderElement(0, 1, _element.TransformFunc(minValue), color));
                result.Add(GetHeaderElement(1, 1, _element.TransformFunc(avgValue), color));
                result.Add(GetHeaderElement(2, 1, _element.TransformFunc(maxValue), color));
                result.Add(GetHeaderElement(3, 1, _element.TransformFunc(currentValue), color));

                result.Add(GetHeaderElement(4, 1, _element.Suffix, color));

                var deviceWidth = _layoutContext.ButtonCount.Width;
                using (var bitmap = new BitmapEx(_layoutContext.IconSize.Width * deviceWidth, _layoutContext.IconSize.Height))
                {
                    bitmap.MakeTransparent();
                    DefaultDrawingAlgs.DrawPlot(bitmap, color, values, 0, bitmap.Height);
                    result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(deviceWidth, 1), 0, 2, _layoutContext));
                }

                DrawLayout?.Invoke(this, new DrawEventArgs(result.ToArray()));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception during weather station layout drawing: {ex}");
            }
        }
Exemplo n.º 12
0
        public static IEnumerable <LayoutDrawElement> ExtractLayoutDrawElements(BitmapEx source, DeviceSize deviceSize, byte left, byte top, LayoutContext layoutContext, TransitionInfo transitionInfo = default(TransitionInfo))
        {
            var itemWidth  = source.Width / deviceSize.Width;
            var itemHeight = source.Height / deviceSize.Height;

            for (byte x = 0; x < deviceSize.Width; x++)
            {
                for (byte y = 0; y < deviceSize.Height; y++)
                {
                    var part = layoutContext.CreateBitmap();

                    using (Graphics grD = part.CreateGraphics())
                    {
                        grD.DrawImage(source.GetInternal(), new Rectangle(0, 0, itemWidth, itemHeight), new Rectangle(x * itemWidth, y * itemHeight, itemWidth, itemHeight), GraphicsUnit.Pixel);
                    }

                    yield return(new LayoutDrawElement(new Location(left + x, top + y), part, transitionInfo));
                }
            }
        }
Exemplo n.º 13
0
        public static void DrawPlot(BitmapEx bitmap, Color color, double[] values, int fromY, int toY, int startIndex = 0, double?minValue = null, double?maxValue = null)
        {
            var min = double.MaxValue;
            var max = double.MinValue;

            if (minValue == null || maxValue == null)
            {
                for (int i = startIndex; i < values.Length; i++)
                {
                    if (min > values[i])
                    {
                        min = values[i];
                    }

                    if (max < values[i])
                    {
                        max = values[i];
                    }
                }
            }

            min = minValue ?? min;
            max = maxValue ?? max;

            var coef = (max != min) ? ((toY - fromY) / ((max - min))) : 0;

            var midY     = (toY + fromY) / 2;
            var midValue = (max + min) / 2.0;

            Point[] points = new Point[values.Length - startIndex];
            for (int i = startIndex; i < values.Length; i++)
            {
                points[i - startIndex] = new Point(i - startIndex, (int)(midY - (values[i] - midValue) * coef));
            }

            using (var graphics = bitmap.CreateGraphics())
                using (var pen = new Pen(color))
                {
                    graphics.DrawCurve(pen, points);
                }
        }
Exemplo n.º 14
0
        internal void SetImage(Location location, BitmapEx bitmap)
        {
            Action action = () =>
            {
                var picBox = Controls.OfType <PictureBox>().FirstOrDefault(p => (Location)p.Tag == location);
                if (picBox != null)
                {
                    picBox.Image?.Dispose();
                    picBox.Image = (Image)bitmap.GetInternal().Clone();
                }
            };

            if (InvokeRequired)
            {
                Invoke(action);
            }
            else
            {
                action();
            }
        }
Exemplo n.º 15
0
 //附加图片
 private void attributeBtn_Click(object sender, EventArgs e)
 {
     openFileDialog1.Filter           = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif|PNG Image|*.png|All files (*.*)|*.*";
     openFileDialog1.FilterIndex      = 1;
     openFileDialog1.RestoreDirectory = true;
     openFileDialog1.FileName         = string.Empty;
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         _asIcon = radioButton2.Checked;
         String fileName = openFileDialog1.FileName;
         var    x        = 190;
         var    y        = 190;
         if (_asIcon)
         {
             x = 30;
             y = 30;
         }
         _attrBitmap          = BitmapEx.GetThumbnailImage(fileName, x, y);
         attrPictureBox.Image = _attrBitmap;
     }
 }
Exemplo n.º 16
0
        public static BitmapEx CreateBitmap(this IDevice device, ThemeOptions options)
        {
            var iconSize = device.IconSize;
            var result   = new BitmapEx(iconSize.Width, iconSize.Height, PixelFormat.Format24bppRgb);

            if (options.BackgroundBitmapRepresentation == null)
            {
                using (var graphics = result.CreateGraphics())
                    using (var brush = new SolidBrush(options.BackgroundColor))
                    {
                        graphics.FillRectangle(brush, 0, 0, result.Width, result.Height);
                    }
            }
            else
            {
                using (var sourceBitmap = options.BackgroundBitmapRepresentation.CreateBitmap())
                    BitmapHelpers.ResizeBitmap(sourceBitmap, result);
            }

            return(result);
        }
Exemplo n.º 17
0
        private BitmapEx DrawLevel(bool muted, double volume, float peakValue)
        {
            var bitmap = new BitmapEx(LayoutContext.IconSize.Width * ButtonCount.Width, LayoutContext.IconSize.Height * ButtonCount.Height);

            bitmap.MakeTransparent();

            var delta           = 50;
            var volumePeakWidth = bitmap.Width / 3;
            var selectorWidth   = bitmap.Width - volumePeakWidth;

            var baseColor = muted ? GlobalContext.Options.Theme.WarningColor : GlobalContext.Options.Theme.LevelColor;


            Color color1 = Color.FromArgb(baseColor.A, Math.Min(byte.MaxValue, baseColor.R + delta), Math.Min(byte.MaxValue, baseColor.G + delta), Math.Min(byte.MaxValue, baseColor.B + delta));
            Color color2 = Color.FromArgb(baseColor.A, Math.Max(0, baseColor.R - delta), Math.Max(0, baseColor.G - delta), Math.Max(0, baseColor.B - delta));

            using (var graphics = bitmap.CreateGraphics())
                using (var brush = new LinearGradientBrush(new Point(0, 0), new Point(0, bitmap.Height), color1, color2))
                    using (var pen = new Pen(baseColor, 2))
                    {
                        if (_mediaDeviceService.HasDevice)
                        {
                            var top  = (int)(bitmap.Height * (1 - volume));
                            var left = (int)(selectorWidth * (1 - volume));

                            var pointsCurrent = new [] { new Point(selectorWidth, bitmap.Height), new Point(selectorWidth, top), new Point(left, top) };
                            var pointsFull    = new [] { new Point(selectorWidth, bitmap.Height), new Point(selectorWidth, 0), new Point(0, 0) };

                            graphics.FillPolygon(brush, pointsCurrent);
                            graphics.DrawPolygon(pen, pointsFull);

                            var selectorTop = (int)(bitmap.Height * (1 - peakValue));

                            selectorWidth += bitmap.Width / 10;
                            graphics.FillPolygon(brush, new [] { new Point(selectorWidth, bitmap.Height), new Point(bitmap.Width, bitmap.Height), new Point(bitmap.Width, selectorTop), new Point(selectorWidth, selectorTop) });
                        }
                    }

            return(bitmap);
        }
Exemplo n.º 18
0
        public static void DrawText(BitmapEx bitmap, FontFamily fontFamily, string text, Color color)
        {
            var height = FontEstimation.EstimateFontSize(bitmap, fontFamily, text);

            using (var graphics = bitmap.CreateGraphics())
                using (var whiteBrush = new SolidBrush(color))
                    using (var font = new Font(fontFamily, height, GraphicsUnit.Pixel))
                    {
                        var size = graphics.MeasureString(text, font);
                        if (size.Width / size.Height > 5)
                        {
                            var splittedText = SplitText(text);
                            if (splittedText != text)
                            {
                                DrawText(bitmap, fontFamily, splittedText, color);
                                return;
                            }
                        }

                        graphics.DrawString(text, font, whiteBrush, (bitmap.Width - size.Width) / 2, (bitmap.Height - size.Height) / 2);
                    }
        }
Exemplo n.º 19
0
        public static void ResizeBitmap(BitmapEx source, BitmapEx destination, Rectangle destRectangle, ColorMatrix colorMatrix = null)
        {
            using (var graphics = destination.CreateGraphics())
            {
                graphics.CompositingMode    = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);

                    if (colorMatrix != null)
                    {
                        wrapMode.SetColorMatrix(colorMatrix);
                    }

                    graphics.DrawImage(source.GetInternal(), destRectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }
        }
Exemplo n.º 20
0
 public override Renderer ConstructBitmapEx(
     LWF lwf, int objectId, BitmapEx bitmapEx)
 {
     return(new BitmapRenderer(lwf, m_bitmapExContexts[objectId]));
 }
Exemplo n.º 21
0
            public override Renderer ConstructBitmapEx(
		LWF lwf, int objectId, BitmapEx bitmapEx)
            {
                return new BitmapRenderer(lwf, m_bitmapExContexts[objectId]);
            }
Exemplo n.º 22
0
            public virtual Renderer ConstructBitmapEx(LWF lwf,
		int objectId, BitmapEx bitmapEx)
            {
                return null;
            }
Exemplo n.º 23
0
 public virtual Renderer ConstructBitmapEx(LWF lwf,
                                           int objectId, BitmapEx bitmapEx)
 {
     return(null);
 }
Exemplo n.º 24
0
 public static void DrawPlot(BitmapEx bitmap, Color color, int[] values, int fromY, int toY, int startIndex = 0, double?minValue = null, double?maxValue = null)
 {
     DrawPlot(bitmap, color, values.Select(v => (double)v).ToArray(), fromY, toY, startIndex, minValue, maxValue);
 }
Exemplo n.º 25
0
        public static void ResizeBitmap(BitmapEx source, BitmapEx destination, ColorMatrix colorMatrix = null)
        {
            var destRect = new Rectangle(0, 0, destination.Width, destination.Height);

            ResizeBitmap(source, destination, destRect, colorMatrix);
        }
Exemplo n.º 26
0
        public static Bitmap ConvertToBitmap(BitmapEx bmpEx)
        {
            uint        depth = 0;
            bool        HasAlpha;
            PixelFormat format;

            if (bmpEx.BitDepth == ImageType.RGB8)
            {
                format = PixelFormat.Format24bppRgb; depth = 3; HasAlpha = false;
            }
            else if (bmpEx.BitDepth == ImageType.RGBA8)
            {
                format = PixelFormat.Format32bppArgb; depth = 4; HasAlpha = true;
            }
            else if (bmpEx.BitDepth == ImageType.RGB16)
            {
                format = PixelFormat.Format48bppRgb; depth = 6; HasAlpha = false;
            }
            else if (bmpEx.BitDepth == ImageType.RGBA16)
            {
                format = PixelFormat.Format64bppArgb; depth = 8; HasAlpha = true;
            }
            else
            {
                throw new ArgumentException("Bitdepth not supported");
            }

            Bitmap     outBmp = new Bitmap((int)bmpEx.Width, (int)bmpEx.Height, format);
            BitmapData bmd    = outBmp.LockBits(new System.Drawing.Rectangle(0, 0, outBmp.Width, outBmp.Height), ImageLockMode.WriteOnly, outBmp.PixelFormat);

            bmpEx.LockBits();

            unsafe
            {
                byte *pixIn  = (byte *)bmpEx.Scan0;
                byte *pixOut = (byte *)bmd.Scan0;
                long  idx;
                uint  x, y;
                int   resV = (int)(bmd.Stride - bmpEx.Stride);
                int   res  = 0;
                for (y = 0; y < bmd.Height; y++)
                {
                    for (x = 0; x < bmd.Stride; x += depth)
                    {
                        idx             = y * bmd.Stride + x;
                        pixOut[idx + 2] = pixIn[idx - res];
                        pixOut[idx + 1] = pixIn[idx + 1 - res];
                        pixOut[idx]     = pixIn[idx + 2 - res];
                        if (HasAlpha)
                        {
                            pixOut[idx + 3] = pixIn[idx + 3 - res];
                        }
                    }
                    res += resV;
                }
            }
            outBmp.UnlockBits(bmd);
            bmpEx.UnlockBits();

            return(outBmp);
        }
Exemplo n.º 27
0
        private void btnEncode_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (txtEncodeData.Text.Trim() == String.Empty)
                {
                    MessageBox.Show("内容不能为空");
                    return;
                }

                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                String        encoding      = cboEncoding.Text;
                if (encoding == "Byte")
                {
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                }
                else if (encoding == "AlphaNumeric")
                {
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC;
                }
                else if (encoding == "Numeric")
                {
                    qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC;
                }
                try
                {
                    int scale = Convert.ToInt16(txtSize.Text);
                    qrCodeEncoder.QRCodeScale = scale;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误的大小,ex:" + ex.Message);
                    return;
                }
                try
                {
                    int version = Convert.ToInt16(cboVersion.Text);
                    qrCodeEncoder.QRCodeVersion = version;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误的版本,ex:" + ex.Message);
                }

                string errorCorrect = cboCorrectionLevel.Text;
                if (errorCorrect == "L")
                {
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
                }
                else if (errorCorrect == "M")
                {
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                }
                else if (errorCorrect == "Q")
                {
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q;
                }
                else if (errorCorrect == "H")
                {
                    qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
                }
                //
                qrCodeEncoder.QRCodeBackgroundColor = System.Drawing.Color.White;
                qrCodeEncoder.QRCodeForegroundColor = System.Drawing.Color.Black;

                Image image;

                String data = txtEncodeData.Text;

                var qrBitMap = qrCodeEncoder.Encode(data);

                if (radioButton2.Checked)
                {
                    if (_attrBitmap != null && _attrBitmap.Width > 0)
                    {
                        try
                        {
                            if (qrBitMap != null && qrBitMap.Width > 0)
                            {
                                int left = (qrBitMap.Width - _attrBitmap.Width) / 2;
                                int top  = (qrBitMap.Height - _attrBitmap.Height) / 2;
                                for (int i = 0; i < qrBitMap.Width; i++)
                                {
                                    for (int j = 0; j < qrBitMap.Height; j++)
                                    {
                                        if (i >= left && i < left + _attrBitmap.Width)
                                        {
                                            if (j >= top && j < top + _attrBitmap.Height)
                                            {
                                                var color = _attrBitmap.GetPixel(i - left, j - top);

                                                if (color.A != System.Drawing.Color.Transparent.A)
                                                {
                                                    qrBitMap.SetPixel(i, j, _attrBitmap.GetPixel(i - left, j - top));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch { }
                    }
                }
                else
                {
                    if (_attrBitmap != null && _attrBitmap.Width > 0)
                    {
                        var contrast = 200;

                        if (radioButton3.Checked)
                        {
                            var maxColorValue = qrCodeEncoder.QRCodeForegroundColor.R + qrCodeEncoder.QRCodeForegroundColor.B + qrCodeEncoder.QRCodeForegroundColor.G;

                            var qrForegroundArgb = qrCodeEncoder.QRCodeForegroundColor.ToArgb();

                            _attrBitmap = BitmapEx.Luminance(_attrBitmap, -50);

                            for (int i = 0; i < qrBitMap.Width; i++)
                            {
                                for (int j = 0; j < qrBitMap.Height; j++)
                                {
                                    if (qrBitMap.GetPixel(i, j).ToArgb() == qrForegroundArgb)
                                    {
                                        try
                                        {
                                            var attrColor      = _attrBitmap.GetPixel(i, j);
                                            var attrColorValue = attrColor.R + attrColor.G + attrColor.B;
                                            var absDifference  = Math.Abs(maxColorValue - attrColorValue);

                                            if (absDifference < contrast)
                                            {
                                                qrBitMap.SetPixel(i, j, _attrBitmap.GetPixel(i, j));
                                            }
                                            else
                                            {
                                                qrBitMap.SetPixel(i, j, _attrBitmap.GetPixel(i, j));
                                            }
                                        }
                                        catch { }
                                    }
                                }
                            }
                        }
                        else
                        {
                            var maxColorValue = qrCodeEncoder.QRCodeForegroundColor.R + qrCodeEncoder.QRCodeForegroundColor.B + qrCodeEncoder.QRCodeForegroundColor.G;

                            var qrBackgroundArgb = qrCodeEncoder.QRCodeBackgroundColor.ToArgb();

                            _attrBitmap = BitmapEx.Luminance(_attrBitmap, 50);

                            for (int i = 0; i < qrBitMap.Width; i++)
                            {
                                for (int j = 0; j < qrBitMap.Height; j++)
                                {
                                    if (qrBitMap.GetPixel(i, j).ToArgb() == qrBackgroundArgb)
                                    {
                                        try
                                        {
                                            var attrColor      = _attrBitmap.GetPixel(i, j);
                                            var attrColorValue = attrColor.R + attrColor.G + attrColor.B;
                                            var absDifference  = Math.Abs(maxColorValue - attrColorValue);

                                            if (absDifference > contrast)
                                            {
                                                qrBitMap.SetPixel(i, j, _attrBitmap.GetPixel(i, j));
                                            }
                                        }
                                        catch { }
                                    }
                                }
                            }
                        }
                    }
                }
                //像素处理

                image           = qrBitMap;
                picEncode.Image = image;

                sizeLabel.Text = $"W:{this.picEncode.Image.Width}px,H:{this.picEncode.Image.Height}px";
            }
            catch (Exception ex)
            {
                MessageBox.Show("生成失败:" + ex.Message);
            }
        }
Exemplo n.º 28
0
 public Renderer ConstructBitmapEx(LWF lwf, int objId, BitmapEx bitmapEx)
 {
     return(null);
 }
Exemplo n.º 29
0
 public static void DrawCaptionedIcon(BitmapEx bitmap, FontFamily iconFontFamily, string iconSymbol, FontFamily textFontFamily, string text, string textExample, Color color)
 {
     DrawElements(bitmap, new TextDrawElement(iconFontFamily, iconSymbol, color, 70, StringAlignment.Center), new TextDrawElement(textFontFamily, text, color, 30, StringAlignment.Center));
 }
Exemplo n.º 30
0
 public Renderer ConstructBitmapEx(LWF lwf, int objId, BitmapEx bitmapEx)
 {
     return null;
 }
Exemplo n.º 31
0
        public static NSImage ToNSImage(BitmapEx bmpEx)
        {
            bmpEx.LockBits();
            long           bufferLength = bmpEx.Width * bmpEx.Height;
            CGDataProvider provider = new CGDataProvider(bmpEx.Scan0, (int)bufferLength);
            int            bitsPerComponent, bitsPerPixel, bytesPerRow = (int)bmpEx.Stride;
            CGColorSpace   colorSpaceRef = CGColorSpace.CreateDeviceRGB();

            switch (bmpEx.BitDepth)
            {
            case ImageType.RGB16:
                bitsPerComponent = 16;
                bitsPerPixel     = 48;
                bufferLength    *= 3;
                break;

            case ImageType.RGBA16:
                bitsPerComponent = 16;
                bitsPerPixel     = 64;
                bufferLength    *= 4;
                break;

            case ImageType.RGB8:
                bitsPerComponent = 8;
                bitsPerPixel     = 24;
                bufferLength    *= 3;
                break;

            case ImageType.RGBA8:
                bitsPerComponent = 8;
                bitsPerPixel     = 32;
                bufferLength    *= 4;
                break;

            case ImageType.RGB32:
                bitsPerComponent = 32;
                bitsPerPixel     = 96;
                bufferLength    *= 3;
                break;

            case ImageType.RGBA32:
                bitsPerComponent = 32;
                bitsPerPixel     = 128;
                bufferLength    *= 4;
                break;

            case ImageType.RGB64:
                bitsPerComponent = 64;
                bitsPerPixel     = 192;
                bufferLength    *= 3;
                break;

            case ImageType.RGBA64:
                bitsPerComponent = 64;
                bitsPerPixel     = 256;
                bufferLength    *= 4;
                break;

            default:
                throw new ArgumentException("Bitdepth not supported");
            }

            CGImage img = new CGImage((int)bmpEx.Width, (int)bmpEx.Height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, CGBitmapFlags.ByteOrderDefault, provider, null, true, CGColorRenderingIntent.Default);

            bmpEx.UnlockBits();

            return(new NSImage(img, new SizeF(img.Width, img.Height)));
        }
Exemplo n.º 32
0
        private void PerformDraw(PlayingInfo playingInfo)
        {
            byte imageSize = 2;
            byte textSize  = 3;
            var  result    = new List <LayoutDrawElement>();

            if (playingInfo.IsPlaying != _isPlaying)
            {
                _isPlaying = playingInfo.IsPlaying;
                _playPauseButton.ReplaceText(_isPlaying.Value?FontAwesomeRes.fa_pause:FontAwesomeRes.fa_play);
            }

            if (_previousRepresentation != playingInfo?.BitmapRepresentation)
            {
                _previousRepresentation = playingInfo?.BitmapRepresentation;

                using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * imageSize, LayoutContext.IconSize.Height * imageSize))
                {
                    bitmap.MakeTransparent();
                    if (playingInfo?.BitmapRepresentation != null)
                    {
                        using (BitmapEx coverBitmap = playingInfo.BitmapRepresentation.CreateBitmap())
                        {
                            BitmapHelpers.ResizeBitmap(coverBitmap, bitmap);
                        }
                    }

                    result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(imageSize, imageSize), 0, 0, LayoutContext));
                }
            }

            using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height))
            {
                var lineWidth = 0.05;

                bitmap.MakeTransparent();
                var title = playingInfo?.Title;
                DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, title, LayoutContext.Options.Theme.ForegroundColor);

                if (playingInfo != null)
                {
                    using (var graphics = bitmap.CreateGraphics())
                        using (var brush = new SolidBrush(GlobalContext.Options.Theme.ForegroundColor))
                        {
                            var rect = new Rectangle(0, (int)(bitmap.Height * (1 - lineWidth)), (int)(bitmap.Width * playingInfo.CurrentPosition.TotalMilliseconds / playingInfo.DurationSpan.TotalMilliseconds), (int)(bitmap.Height * lineWidth));
                            graphics.FillRectangle(brush, rect);
                        }
                }

                result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 0, LayoutContext));
            }

            using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height))
            {
                bitmap.MakeTransparent();
                var artist = playingInfo?.Artist ?? string.Empty;
                var album  = playingInfo?.Album ?? string.Empty;
                var text   = $"{artist}\n{album}";
                DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, text, GlobalContext.Options.Theme.ForegroundColor);
                result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 1, LayoutContext));
            }

            DrawInvoke(result);
        }