Exemplo n.º 1
0
 public void LoadBitmapTag(HaloMap Map, int TagIndex)
 {
     map = Map;
     Map.OpenIO();
     map.RawInformation.ExternalMaps.CreateIOs();
     map.RawInformation.ExternalMaps.OpenIOs();
     tagIndex = TagIndex;
     bi       = BitmapFunctions.GetBitmapInfo(map, tagIndex);
     listView1.Items.Clear();
     for (int i = 0; i < bi.bitmapList.Count; i++)
     {
         string[]     items = new string[] { i.ToString(), bi.bitmapList[i].Height.ToString(), bi.bitmapList[i].Width.ToString(), $"0x{bi.bitmapList[i].RawLength:X}", bi.bitmapList[i].Format.ToString(), bi.bitmapList[i].Type.ToString() };
         ListViewItem item  = new ListViewItem(items)
         {
             Tag = i
         };
         listView1.Items.Add(item);
     }
     if (listView1.Items.Count > 0)
     {
         listView1.FocusedItem = listView1.Items[0];
         listView1_SelectedIndexChanged(null, null);
     }
     map.RawInformation.ExternalMaps.CloseIOs();
     Map.CloseIO();
 }
    public Bitmap DeskewImage(Bitmap image, int type, int binarizeThreshold)
    {
        Size oldSize = image.Size;

        _internalBmp = BitmapFunctions.Resize(image, new Size(1000, 1000), true, image.PixelFormat);
        Binarize(_internalBmp, binarizeThreshold);


        return(Rotate(image, GetSkewAngle()));
    }
        /// <summary>
        /// Tests whether the glyph height of the capital letter X using the selected font is larger than the default glyph height.
        /// </summary>
        /// <returns>Returns false if the user cancels the operation.</returns>
        private bool TestGlyphSize()
        {
            Grid testGrid = new Grid();
            int  fontSize = Math.Max(FontSettings.FontSize, FontSettings.KanjiFontSize);
            Run  testRun  = new Run
            {
                Text       = "X",
                FontFamily = FontSettings.FontFamily,
                FontSize   = fontSize,
                FontWeight = FontSettings.FontWeight,
                Foreground = Brushes.Red
            };

            TextBlock testText = new TextBlock(testRun)
            {
                Margin = new Thickness(GlyphHorizontalMargin, 0, GlyphHorizontalMargin, 0),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center
            };

            testGrid.Children.Add(testText);
            testGrid.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            testGrid.Arrange(new Rect(testGrid.DesiredSize));

            BitmapSource glyphBitmap = BitmapFunctions.CaptureScreen(testGrid, 96.0, 96.0);
            Rect         innerRect   = DetectInnerRectFromPixels(glyphBitmap, new Rect(0.0, 0.0, testGrid.ActualWidth, testGrid.ActualHeight));

            //if (testGrid.ActualHeight > GlyphHeight)
            if (innerRect.Height > GlyphHeight)
            {
                int newGlyphHeight = (int)Math.Ceiling(innerRect.Height);

                string message = Properties.Resources.Error_Generation_GlyphSizeTooLargeMessage +
                                 Environment.NewLine + Environment.NewLine +
                                 string.Format(Properties.Resources.Error_Generation_GlyphSizeConfirmation, newGlyphHeight);

                var answer = MessageBox.Show(
                    message,
                    Properties.Resources.Error_Generation_GlyphSizeTooLargeTitle,
                    MessageBoxButton.YesNo,
                    MessageBoxImage.Information);

                if (answer == MessageBoxResult.No)
                {
                    return(false);
                }
                else
                {
                    GlyphHeight = newGlyphHeight;
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public override string ToString()
        {
            battleTag = BattleTag.ReadFromMemory();
            duration  = (int)timer.Elapsed.TotalSeconds;

            foreach (HeroPlayed hero in heroesPlayed)
            {
                if (hero.RolePlayed() == "tank")
                {
                    startRating = startRatings.tank;
                    endRating   = currentRatings.tank;
                    break;
                }
                else if (hero.RolePlayed() == "damage")
                {
                    startRating = startRatings.damage;
                    endRating   = currentRatings.damage;
                    break;
                }
                else if (hero.RolePlayed() == "support")
                {
                    startRating = startRatings.support;
                    endRating   = currentRatings.support;
                    break;
                }
            }
            if (AppData.settings.uploadScreenshot && playerListImage != null)
            {
                playerListImageBase64 = Convert.ToBase64String(BitmapFunctions.BitmapToBytes(BitmapFunctions.ReduceBitmapSize(playerListImage, 70)));
            }
            if (players.Count != 12)
            {
                players.Clear();
            }

            return(JsonConvert.SerializeObject(this, Formatting.None));
        }
        private void AddInnerRect(string glyph, Grid glyphGrid, TextBlock innerText, double x, double y)
        {
            Rect         innerRect;
            BitmapSource glyphBitmap = BitmapFunctions.CaptureScreen(glyphGrid, 96.0, 96.0);

            if (string.IsNullOrWhiteSpace(glyph) || glyphBitmap == null || !UseAccurateInnerRects)
            {
                double innerWidth = innerText.ActualWidth + SpacingAdjustment;
                if (innerWidth < 0)
                {
                    innerWidth = 0;
                }

                innerRect = CreateInnerRect(
                    x: x,
                    y: y,
                    outerHeight: OuterRects[glyph].Height,
                    innerWidth: innerWidth,
                    innerHeight: innerText.ActualHeight);
            }
            else
            {
                innerRect = DetectInnerRectFromPixels(glyphBitmap, OuterRects[glyph]);

                // Create new outer rect to keep horizontal margin constant
                OuterRects[glyph] = new Rect(
                    innerRect.X - GlyphHorizontalMargin,
                    OuterRects[glyph].Y,
                    innerRect.Width + (GlyphHorizontalMargin * 2),
                    OuterRects[glyph].Height);

                RectCanvas.Children.RemoveAt(RectCanvas.Children.Count - 1);
                CreateOuterRectangleForCanvas(glyph, OuterRects[glyph]);
            }

            /*if(inner.Height > DefaultGlyphHeight)
             * {
             *  var answer = MessageBox.Show(
             *      "The glyph height for the selected font is larger than the default (52 pixels).\n\n",
             *      "Glyph Size Too Large");
             * }*/

            Brush rectBrush = Brushes.DarkViolet;
            Rect  outer     = OuterRects[glyph];

            // Check if the inner rect is larger than the outer
            if (innerRect.Top < outer.Top ||
                innerRect.Left < outer.Left ||
                innerRect.Bottom > outer.Bottom ||
                innerRect.Right > outer.Right)
            {
                if (!RectErrorMessageShown)
                {
                    MessageBox.Show(Properties.Resources.Error_Generation_OverlappingBoundingRects, Properties.Resources.Error_Warning);
                    RectErrorMessageShown = true;
                }

                // Resize the width of the inner rect to fit inside the outer
                if (innerRect.Right > outer.Right)
                {
                    innerRect = new Rect(
                        innerRect.X,
                        innerRect.Y,
                        innerRect.Width - (outer.Right - innerRect.Right),
                        innerRect.Height);
                }

                rectBrush = Brushes.Red;
            }

            InnerRects.Add(glyph, innerRect);

            CreateInnerRectangleForCanvas(innerRect, rectBrush);
        }