Beispiel #1
0
        private void JPGGenerator()
        {
            ListService service = new ListService(new Reader_HSK());

            var includedWords = service.GetAllWords(1);

            List <Word> arrayIncluded = ToList(includedWords);

            int index = 1;

            foreach (Word_HSK w in arrayIncluded.OrderBy(x => x.NumberPinyin))

            {
                //FANGSONG
                //	KAITI
                //	SIMHEI
                //DengXian

                string sIndex = NumeroCuadrado(index, 3);

                BitmapService.GenerateBitmapfromFontChar(w.Character, "FangSong", FontStyle.Regular, sIndex);
                BitmapService.GenerateBitmapfromFontChar(w.Character, "Kaiti", FontStyle.Regular, sIndex);

                index++;
            }
        }
Beispiel #2
0
        public void SetDesktopCaptureBitmap(Bitmap originalDesktopBitmap, Rectangle desktopArea)
        {
            originalDesktopCaptureBitmap = originalDesktopBitmap;
            // Get a darker version of the bitmap to display
            darkDesktopCaptureBitmap = BitmapService.ModifyBitmap(originalDesktopCaptureBitmap, 0.9f, 0.9f, 1.0f);

            int screenLeft   = SystemInformation.VirtualScreen.Left;
            int screenTop    = SystemInformation.VirtualScreen.Top;
            int screenWidth  = SystemInformation.VirtualScreen.Width;
            int screenHeight = SystemInformation.VirtualScreen.Height;

            // Setup this form so it covers the entire desktop area, spanning all monitors
            FormBorderStyle = FormBorderStyle.None;
            WindowState     = FormWindowState.Normal;

            Size     = new Size(screenWidth, screenHeight);
            Location = new Point(screenLeft, screenTop);

            // Update the pixture box to show the darker desktop bitmap
            pictureBox.Size     = new Size(screenWidth, screenHeight);
            pictureBox.Location = new Point(0, 0);
            pictureBox.Image    = darkDesktopCaptureBitmap;
            pictureBox.Invalidate();

            Cursor = Cursors.Cross;
        }
        public void CreateNewScreenshot()
        {
            if (!GetIsSelectedRectangleValid())
            {
                Close();
                return;
            }

            // Only get the rectangle portion of the dekstop we want
            Bitmap croppedBitmap = BitmapService.CropBitmap(OriginalScreenBitmap, GetSelectedCaptureArea());

            // When creating the new Screenshot form, make sure to place it on the relevant part of the desktop
            var topLeftPoint = GetTopLeftPoint();

            // Apply offset
            var leftMostScreen   = Screen.AllScreens.OrderBy(s => s.Bounds.Left).First();
            var leftMostLocation = leftMostScreen.Bounds.Location;

            topLeftPoint.X += DesktopRectangle.X;
            topLeftPoint.Y += DesktopRectangle.Y;

            // TODO: Add Screenshots to groups (for grouped moving etc.)
            var screenshotModel     = new ScreenshotModel(croppedBitmap, topLeftPoint);
            var newScreenshotForm   = new ScreenshotView();
            var screenshotPresenter = new ScreenshotPresenter(newScreenshotForm, screenshotModel);

            newScreenshotForm.SetBitmap(croppedBitmap, topLeftPoint);
            newScreenshotForm.Show();

            Close();
        }
Beispiel #4
0
        private static void AnalyzeImage(InkCanvas canvas)
        {
            Bitmap bitmap = BitmapService.ResizeImage(BitmapService.GetInputImage(
                                                          BitmapService.GetImageByCanvas(canvas)), 28, 28);

            ResultView rv = new ResultView(bitmap);

            rv.ShowDialog();
        }
Beispiel #5
0
        private void UpdatePreviewBitmap()
        {
            // The preview bitmap is always at the location of the end click (this is where the pointer currently 'is')
            var previewWidth          = previewSize.Width / previewScale;
            var previewHeight         = previewSize.Height / previewScale;
            var lPreviewAreaRectangle = new Rectangle((int)(StopClickPoint.X - previewWidth / 2), (int)(StopClickPoint.Y - previewHeight / 2), (int)previewWidth, (int)previewHeight);

            previewBitmap = BitmapService.CropBitmap(originalDesktopCaptureBitmap, lPreviewAreaRectangle);
            previewBitmap.SetPixel((int)(previewWidth * 0.5f) + 1, (int)(previewHeight * 0.5f) + 1, Color.Red);
        }
Beispiel #6
0
        private void FrameCapture()
        {
            int Episode = 1;

            numFrame++;
            Bitmap bitmapFromScreen = BitmapService.BitmapFromScreen(CaptureArea.Width, CaptureArea.Height, CaptureArea.Left, CaptureArea.Top, this.comboBoxScreen.SelectedIndex);

            pictureBox1.Image = bitmapFromScreen;

            bitmapFromScreen.Save(@"D:\Addicted\" + Episode.ToString() + @"\" + numFrame.ToString() + ".jpg", ImageFormat.Jpeg);
        }
Beispiel #7
0
        private void PaintCaptureArea(PaintEventArgs e)
        {
            // Get the selected rectangle area from the original (bright) bitmap
            Bitmap adjustedBitmap = BitmapService.CropBitmap(originalDesktopCaptureBitmap, SelectedArea);

            // if no cropping occured, default to the darker capture
            if (adjustedBitmap.Width == originalDesktopCaptureBitmap.Width && adjustedBitmap.Height == originalDesktopCaptureBitmap.Height)
            {
                adjustedBitmap = darkDesktopCaptureBitmap;
            }

            e.Graphics.DrawImage(adjustedBitmap, SelectedArea.X, SelectedArea.Y);
        }
    public void BitmapService_Should_SaveBitmapAsPngImage()
    {
        //Arrange
        var mockedStream   = Mock.Of <Stream>();
        var fileSystemMock = new Mock <IFileSystem>();

        fileSystemMock
        .Setup(_ => _.OpenOrCreateFileStream(It.IsAny <string>()))
        .Returns(mockedStream);
        fileSystemMock.SetupAllProperties();
        var sut          = new BitmapService(fileSystemMock.Object);
        var renderBitmap = new Canvas();
        var path         = new Uri("//A_valid_path");

        //Act
        sut.SaveBitmapAsPngImage(path, renderBitmap);
        //Assert
        Mock.Get(mockedStream).Verify(_ => _.Write(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()));
    }
Beispiel #9
0
        /// <summary>
        /// Creates an XCImage.
        /// NOTE: Entries must not be compressed.
        /// </summary>
        /// <param name="bindata">the uncompressed source data</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="pal">pass in null to *bypass* creating the 'Image'; ie,
        /// the PckImage..cTor has already unravelled the compressed image-data
        /// instead</param>
        /// <param name="terrainId"></param>
        internal XCImage(
            byte[] bindata,
            int width,
            int height,
            Palette pal,
            int terrainId)
        {
            TerrainId = terrainId;

            Bindata = bindata;
            Pal     = pal;

            if (Pal != null)                                                                    // NOTE: this is to check for a call by BitmapService.LoadSprite()
            {
                Image = BitmapService.MakeBitmapTrue(                                           // which is called by
                    width,                                                                      // BitmapService.LoadSpriteset() and
                    height,                                                                     // PckViewForm.OnSpriteAddClick()
                    Bindata,                                                                    // BUT: the call by PckImage..cTor initializer needs to decode
                    Pal.ColorTable);                                                            // the file-data first, then it creates its own 'Image'.
            }
        }                                                                                       // that's why i prefer pizza.
Beispiel #10
0
        /// <summary>
        /// Creates an XCImage.
        /// NOTE: Entries must not be compressed.
        /// </summary>
        /// <param name="bindata">the uncompressed source data</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="pal">pass in null to *bypass* creating the 'Image'; ie,
        /// the PckImage..cTor has already unravelled the compressed image-data
        /// instead</param>
        /// <param name="id"></param>
        internal XCImage(
            byte[] bindata,
            int width,
            int height,
            Palette pal,
            int id)
        {
            TerrainId = id;             // NOTE: Is not necessarily Terrain. Could be Bigobs or Units ...

            Bindata = bindata;
            Pal     = pal;

            if (Pal != null)                                                                            // NOTE: this is to check for a call by BitmapService.CreateSprite()
            {
                Sprite = BitmapService.CreateColorized(                                                 // which is called by
                    width,                                                                              // BitmapService.CreateSpriteset() and
                    height,                                                                             // several PckViewForm contextmenu events
                    Bindata,                                                                            // BUT: the call by PckImage..cTor initializer needs to decode
                    Pal.ColorTable);                                                                    // the file-data first, then it creates its own 'Image'.
            }
        }                                                                                               // that's why i prefer pizza.
        private void ScreenshotView_SaveScreenshotToFile(object sender, EventArgs e)
        {
            var saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.FileName = $"Screenshot_{DateTime.Now.ToString("yyyyMMdd_hhmmfff")}";
            saveFileDialog1.Filter   = "Png Image|*.png|JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
            saveFileDialog1.Title    = "Save to Image File";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK && saveFileDialog1.FileName != "")
            {
                var imageFormat = ImageFormat.Jpeg;

                // Saves the Image via a FileStream created by the OpenFile method.
                var filepath = saveFileDialog1.FileName;

                switch (saveFileDialog1.FilterIndex)
                {
                case 1:
                    imageFormat = ImageFormat.Png;
                    break;

                case 2:
                    imageFormat = ImageFormat.Jpeg;
                    break;

                case 3:
                    imageFormat = ImageFormat.Bmp;
                    break;

                case 4:
                    imageFormat = ImageFormat.Gif;
                    break;
                }

                BitmapService.SaveBitmapToFile(ScreenshotModel.ScreenshotBitmap, filepath, imageFormat);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Changes a clicked pixel's palette-id (color) to whatever the current
        /// 'PaletteId' is in PalettePanel.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (Sprite != null)
            {
                if (e.X > 0 && e.X < XCImage.SpriteWidth * _scale &&
                    e.Y > 0 && e.Y < XCImage.SpriteHeight * _scale)
                {
                    int pixelX = e.X / _scale;
                    int pixelY = e.Y / _scale;

                    int bindataId = pixelY * (Sprite.Bindata.Length / XCImage.SpriteHeight) + pixelX;

                    if (bindataId > -1 && bindataId < Sprite.Bindata.Length)                     // safety.
                    {
                        switch (EditorForm.Mode)
                        {
                        case EditorForm.EditMode.ModeEnabled:                                 // paint ->
                        {
                            int palId = PalettePanel.Instance.PaletteId;
                            if (palId > -1 && palId < PckImage.SpriteTransparencyByte)                                          // NOTE: 0xFE and 0xFF are reserved for special
                            {                                                                                                   // stuff when reading/writing the .PCK file.
//									var color = PckViewForm.Pal[palId];

                                Sprite.Bindata[bindataId] = (byte)palId;
                                Sprite.Image = BitmapService.MakeBitmapTrue(
                                    XCImage.SpriteWidth,
                                    XCImage.SpriteHeight,
                                    Sprite.Bindata,
                                    PckViewForm.Pal.ColorTable);
                                Refresh();
                                PckViewPanel.Instance.Refresh();
                            }
                            else
                            {
                                switch (palId)
                                {
                                case PckImage.SpriteTransparencyByte:                                                   // #254
                                case PckImage.SpriteStopByte:                                                           // #255
                                    MessageBox.Show(
                                        this,
                                        "The colortable indices #254 and #255 are reserved"
                                        + " for reading and writing the .PCK file."
                                        + Environment.NewLine + Environment.NewLine
                                        + "#254 is used for RLE encoding"
                                        + Environment.NewLine
                                        + "#255 is the end-of-sprite marker",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button1,
                                        0);
                                    break;
                                }
                            }
                            break;
                        }

                        case EditorForm.EditMode.ModeLocked:                                 // eye-dropper ->
                            PalettePanel.Instance.SelectPaletteId((int)Sprite.Bindata[bindataId]);
                            break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Not generic enough to call with custom derived classes other than
        /// MapFileChild.
        /// </summary>
        /// <param name="fullpath"></param>
        public void Screenshot(string fullpath)
        {
            var pal = Descriptor.Pal;

//			var pal = GetFirstGroundPalette();
//			if (pal == null)
//				throw new ArgumentNullException("fullpath", "MapFileBase: At least 1 ground tile is required.");
            // TODO: I don't want to see 'ArgumentNullException'. Just say
            // what's wrong and save the technical details for the debugger.

            var width = MapSize.Rows + MapSize.Cols;
            var b     = BitmapService.CreateTransparent(
                width * (XCImage.SpriteWidth / 2),
                (MapSize.Levs - Level) * 24 + width * 8,
                pal.ColorTable);

            var start = new Point(
                (MapSize.Rows - 1) * (XCImage.SpriteWidth / 2),
                -(24 * Level));

            int i = 0;

            if (MapTiles != null)
            {
                for (int lev = MapSize.Levs - 1; lev >= Level; --lev)
                {
                    for (int
                         row = 0,
                         startX = start.X,
                         startY = start.Y + lev * 24;
                         row != MapSize.Rows;
                         ++row,
                         startX -= HalfWidthConst,
                         startY += HalfHeightConst)
                    {
                        for (int
                             col = 0,
                             x = startX,
                             y = startY;
                             col != MapSize.Cols;
                             ++col,
                             x += HalfWidthConst,
                             y += HalfHeightConst,
                             ++i)
                        {
                            var parts = this[row, col, lev].UsedParts;
                            foreach (var part in parts)
                            {
                                var tilepart = part as Tilepart;
                                BitmapService.Draw(                                 // NOTE: not actually drawing anything.
                                    tilepart[0].Sprite,
                                    b,
                                    x,
                                    y - tilepart.Record.TileOffset);
                            }
                        }
                    }
                }
            }

            try
            {
                var rect = BitmapService.GetNontransparentRectangle(b, Palette.TransparentId);
                b = BitmapService.Crop(b, rect);
                b.Save(fullpath, ImageFormat.Png);
            }
            catch             // TODO: Deal with exceptions appropriately.
            {
                b.Save(fullpath, ImageFormat.Png);
                throw;
            }

            if (b != null)
            {
                b.Dispose();
            }
        }
Beispiel #14
0
        /// <summary>
        /// Not generic enough to call with custom derived classes other than
        /// MapFileChild.
        /// </summary>
        /// <param name="fullpath"></param>
        public void SaveGifFile(string fullpath)
        {
            var palette = GetFirstGroundPalette();

            if (palette == null)
            {
                throw new ArgumentNullException("fullpath", "MapFileBase: At least 1 ground tile is required.");
            }
            // TODO: I don't want to see 'ArgumentNullException'. Just say
            // what's wrong and save the technical details for the debugger.

            var rowcols = MapSize.Rows + MapSize.Cols;
            var bitmap  = BitmapService.MakeBitmap(
                rowcols * (XCImage.SpriteWidth / 2),
                (MapSize.Levs - Level) * 24 + rowcols * 8,
                palette.ColorTable);

            var start = new Point(
                (MapSize.Rows - 1) * (XCImage.SpriteWidth / 2),
                -(24 * Level));

            int i = 0;

            if (MapTiles != null)
            {
                for (int lev = MapSize.Levs - 1; lev >= Level; --lev)
                {
                    for (int
                         row = 0,
                         startX = start.X,
                         startY = start.Y + lev * 24;
                         row != MapSize.Rows;
                         ++row,
                         startX -= HalfWidthConst,
                         startY += HalfHeightConst)
                    {
                        for (int
                             col = 0,
                             x = startX,
                             y = startY;
                             col != MapSize.Cols;
                             ++col,
                             x += HalfWidthConst,
                             y += HalfHeightConst,
                             ++i)
                        {
                            var usedParts = this[row, col, lev].UsedTiles;
                            foreach (var usedPart in usedParts)
                            {
                                var part = usedPart as Tilepart;
                                BitmapService.Draw(                                 // NOTE: not actually drawing anything.
                                    part[0].Image,
                                    bitmap,
                                    x,
                                    y - part.Record.TileOffset);
                            }

//							XCBitmap.UpdateProgressBar(i, (MapSize.Levs - Level) * MapSize.Rows * MapSize.Cols);
                        }
                    }
                }
            }

            try
            {
                var rect = BitmapService.GetNontransparentRectangle(bitmap, Palette.TransparentId);
                bitmap = BitmapService.Crop(bitmap, rect);
                bitmap.Save(fullpath, ImageFormat.Gif);
            }
            catch
            {
                bitmap.Save(fullpath, ImageFormat.Gif);
                throw;
            }
        }
Beispiel #15
0
        private void Process()
        {
            Bitmap bitmapFromScreen = BitmapService.BitmapFromScreen(CaptureArea.Width, CaptureArea.Height, CaptureArea.Left, CaptureArea.Top, this.comboBoxScreen.SelectedIndex);

            pictureBox1.Image = bitmapFromScreen;


            projectionBitMapFilter = ProjectionService.ProjectandFilter(SelectedColor, Convert.ToInt32(this.numericUpDownColorMargin.Value), bitmapFromScreen);
            ProjectionsToChartSeries(projectionBitMapFilter);
            ProjectionsToChartSeries(projectionBitMapFilter);
            this.pictureBox2.Image = projectionBitMapFilter.Bitmap;

            projectionBitMapFilter.HorizontalSegments = ProjectionService.ToSegments(projectionBitMapFilter.HorizontalProjection, projectionBitMapFilter.Bitmap.Height);
            projectionBitMapFilter.VerticalSegments   = new List <Segment>();

            if (SubtitlesDetected(projectionBitMapFilter.HorizontalSegments))
            {
                long  Range        = projectionBitMapFilter.HorizontalSegments[0].End - projectionBitMapFilter.HorizontalSegments[0].Starts;
                Int64 AverageRange = MathHelper.Average(Ranges);

                projectionBitMapFilter.VerticalSegments = ProjectionService.ToSegments(projectionBitMapFilter.VerticalProjection, projectionBitMapFilter.Bitmap.Height);

                if (projectionBitMapFilter.VerticalSegments.Count != 0)
                {
                    projectionBitMapFilter = ProjectionService.MaxMinEvaluation(bitmapFromScreen.Height, projectionBitMapFilter);

                    List <Segment> GroupedSegments = SegmentationService.GroupSegments(projectionBitMapFilter.VerticalSegments);

                    Bitmap bitmapInitialSegments = (Bitmap)projectionBitMapFilter.Bitmap.Clone();
                    Bitmap bitmapGroupedSegments = (Bitmap)projectionBitMapFilter.Bitmap.Clone();

                    this.pictureBox2.Image                = BitmapService.DrawSegmentsinBitmap(projectionBitMapFilter.VerticalSegments, bitmapInitialSegments, Brushes.DarkRed);
                    this.pictureBoxGrouped.Image          = BitmapService.DrawSegmentsinBitmap(GroupedSegments, bitmapGroupedSegments, Brushes.Orange);
                    projectionBitMapFilter.CroppedBitmaps = BitmapService.ExtractCropBitmaps(GroupedSegments, projectionBitMapFilter.Bitmap);


                    foreach (Bitmap crop in projectionBitMapFilter.CroppedBitmaps)
                    {
                        var margin = BitmapService.CorrectMargin(crop);

                        projectionBitMapFilter.CorrectedMarginBitmaps.Add(margin);
                    }



                    List <char> predictions = new List <char>();

                    foreach (Bitmap bitmap in projectionBitMapFilter.CorrectedMarginBitmaps)
                    {
                        Bitmap resized = BitmapService.ResizeImage(bitmap, 32, 32);

                        projectionBitMapFilter.ResizedBitmaps.Add(resized);

                        string zerosandones = DatasetGenerator.ToZerosOnesSequence(' ', resized);

                        var c = PredictionService.Predict(zerosandones);
                        predictions.Add(c);

                        x++;
                    }

                    BitmapsToScreen(projectionBitMapFilter.ResizedBitmaps);

                    AddTextBoxToScreen(projectionBitMapFilter.CroppedBitmaps.Count, predictions);
                }
            }
        }