Exemplo n.º 1
0
 public void Dispose()
 {
     if (ImageBitmap != null)
     {
         ImageBitmap.Dispose();
         ImageBitmap = null;
     }
 }
Exemplo n.º 2
0
        public override int DrawBatch(int maxBlocksToDraw)
        {
            int blocksDone = 0;

            //byte sid = 255;
            for (; imageX <= maxX; imageX++)
            {
                for (; imageY <= maxY; imageY++)
                {
                    // find matching palette entry
                    System.Drawing.Color color = ImageBitmap.GetPixel(imageX, imageY);
                    drawBlocks = Palette.FindBestMatch(color);
                    Coords.Z   = coordOffsets.Z - (imageY - minY);
                    // draw layers
                    for (; layer < Palette.Layers; layer++)
                    {
                        Coords.X = (imageX - minX) * coordMultiplierX + coordOffsets.X + layerVector.X * layer;
                        Coords.Y = (imageX - minX) * coordMultiplierY + coordOffsets.Y + layerVector.Y * layer;
                        if (DrawOneBlock())
                        {
                            blocksDone++;

                            /*BoundingBox placetobuild = new BoundingBox(Coords.X, Coords.Y, Coords.Z, Coords.X, Coords.Y, Coords.Z);
                             * string rtn = "" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
                             * Block newBlock = Player.WorldMap.GetBlock(placetobuild.XMin, placetobuild.YMin, placetobuild.ZMin);
                             * if (newBlock != Block.Air)
                             * {
                             *  Player.Send(Packet.MakeMakeSelection(sid, "DrawImage" + sid, placetobuild, rtn, 255));
                             *  if (sid == 0) {
                             *      sid = 255;
                             *  } else {
                             *      sid--;
                             *  }
                             * }*/
                            if (blocksDone >= maxBlocksToDraw)
                            {
                                layer++;
                                return(blocksDone);
                            }
                        }
                    }
                    layer = 0;
                }
                imageY = minY;
                if (TimeToEndBatch)
                {
                    imageX++;
                    return(blocksDone);
                }
            }
            IsDone = true;
            return(blocksDone);
        }
Exemplo n.º 3
0
 /// <summary>
 /// カードをひっくり返す。
 /// </summary>
 public void ReverseCard()
 {
     if (side == Side.front)
     {
         side = Side.back;
         IntPtr hbitmap = backImageBitmap.GetHbitmap();
         imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
         DeleteObject(hbitmap);
     }
     else
     {
         side = Side.front;
         IntPtr hbitmap = ImageBitmap.GetHbitmap();
         imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
         DeleteObject(hbitmap);
     }
 }
Exemplo n.º 4
0
        public static Bitmap backImageBitmap;//裏面のビットマップ。裏面は共通なのでクラス変数にする。
        /// <summary>
        /// コンストラクタで画像イメージを設定する。
        /// 全絵柄の1枚絵をクラス変数に保持して部分イメージを切り出して割り当てる。
        /// </summary>
        /// <param name="suit"></param>
        /// <param name="number"></param>
        public Card(Suit suit, int number)
        {
            this.suit   = suit;
            this.number = number;
            this.side   = Side.back;
            const int width = 60; //カード1枚の幅
            const int hidth = 90; //カード1枚の高さ

            if (originalBitmap == null)
            {
                originalBitmap = new Bitmap(480, 630);
                var originalImage = Image.FromFile(imgURL);
                originalBitmap  = (Bitmap)originalImage;
                backImageBitmap = ImageRoi(originalBitmap, new Rectangle(7 * width, 6 * hidth, width, hidth));
            }

            int x;
            int y;

            if (suit.Equals(Suit.jocker))
            {
                x = 4;
                y = 6;
            }
            else
            {
                if (number < 8)
                {
                    x = (int)suit;
                    y = number - 1;
                }
                else
                {      //元画像が8から次の列になっているので読み込み位置をずらす
                    x = (int)suit + 4;
                    y = number - 8;
                }
            }
            ImageBitmap = ImageRoi(originalBitmap, new Rectangle(x * width, y * hidth, width, hidth));//一枚あたりの大きさ
            IntPtr hbitmap = ImageBitmap.GetHbitmap();

            imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            DeleteObject(hbitmap);
        }
Exemplo n.º 5
0
        private static void CleanupBitmapMemory()
        {
            if (ImageBitmap != null)
            {
                ImageBitmapCleanup?.Invoke(null, EventArgs.Empty);

                // Recycle and Dispose the bitmap
                if (!ImageBitmap.IsRecycled)
                {
                    ImageBitmap.Recycle();
                }
                ImageBitmap.Dispose();
                ImageBitmap = null;
            }
            if (ImageOptions != null)
            {
                ImageOptions.Dispose();
                ImageBitmap = null;
            }
        }
Exemplo n.º 6
0
        private void PreviewImage_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed && !IsSorting)
            {
                double imageScale = ImageBitmap.PixelWidth / previewImage.ActualWidth;

                int size = 5;

                int x = (int)(e.GetPosition(previewImage).X *imageScale);
                int y = (int)(e.GetPosition(previewImage).Y *imageScale);

                //ImageBitmap.BlitRender(x2, y2, x, y, x + size, y + size, x2 + size, y2 + size,  System.Windows.Media.Colors.Aquamarine);

                ImageBitmap.Lock();

                var b = new Bitmap(ImageBitmap.PixelWidth,
                                   ImageBitmap.PixelHeight,
                                   ImageBitmap.BackBufferStride,
                                   System.Drawing.Imaging.PixelFormat.Format32bppArgb,
                                   ImageBitmap.BackBuffer);

                using (var bitmapGraphics = System.Drawing.Graphics.FromImage(b))
                {
                    bitmapGraphics.SmoothingMode      = SmoothingMode.HighQuality;
                    bitmapGraphics.InterpolationMode  = InterpolationMode.HighQualityBilinear;
                    bitmapGraphics.CompositingQuality = CompositingQuality.HighQuality;

                    var pen = new Pen(Brushes.Aqua, 5);

                    bitmapGraphics.DrawLine(pen, x2, y2, x, y);
                }

                ImageBitmap.AddDirtyRect(new Int32Rect(0, 0, ImageBitmap.PixelWidth, ImageBitmap.PixelHeight));
                ImageBitmap.Unlock();


                x2 = x;
                y2 = y;
            }
        }
Exemplo n.º 7
0
        public override int DrawBatch(int maxBlocksToDraw)
        {
            int blocksDone = 0;

            for ( ; imageX <= maxX; imageX++)
            {
                for ( ; imageY <= maxY; imageY++)
                {
                    // find matching palette entry
                    System.Drawing.Color color = ImageBitmap.GetPixel(imageX, imageY);
                    drawBlocks = Palette.FindBestMatch(color);
                    Coords.Z   = coordOffsets.Z - (imageY - minY);
                    // draw layers
                    for ( ; layer < Palette.Layers; layer++)
                    {
                        Coords.X = (imageX - minX) * coordMultiplierX + coordOffsets.X + layerVector.X * layer;
                        Coords.Y = (imageX - minX) * coordMultiplierY + coordOffsets.Y + layerVector.Y * layer;
                        if (DrawOneBlock())
                        {
                            blocksDone++;
                            if (blocksDone >= maxBlocksToDraw)
                            {
                                layer++;
                                return(blocksDone);
                            }
                        }
                    }
                    layer = 0;
                }
                imageY = minY;
                if (TimeToEndBatch)
                {
                    imageX++;
                    return(blocksDone);
                }
            }
            IsDone = true;
            return(blocksDone);
        }
Exemplo n.º 8
0
        private void InitializeImage()
        {
            photo    = new Color[Image.Width, Image.Height];
            newPhoto = new Color[Image.Width, Image.Height];

            for (int i = 0; i < Image.Width; i++)
            {
                for (int j = 0; j < Image.Height; j++)
                {
                    if (i < ImageBitmap.Width && j < ImageBitmap.Height)
                    {
                        Color pixel = ImageBitmap.GetPixel(i, j);
                        photo[i, j]    = pixel;
                        newPhoto[i, j] = pixel;
                    }
                    else
                    {
                        photo[i, j]    = Color.White;
                        newPhoto[i, j] = Color.White;
                    }
                }
            }
        }
Exemplo n.º 9
0
        private async void SortButton_Click(object sender, RoutedEventArgs e)
        {
            if (IsSorting)
            {
                wasCancelled = true;
                IsSorting    = false;
                cTokenSource.Cancel();
                return;
            }
            wasCancelled = false;

            if (ImageBitmap == null)
            {
                return;
            }

            tempArray    = ImageBitmap.ToByteArray();
            intTempArray = new int[tempArray.Length / 4];
            hueArray     = new HSBColor[intTempArray.Length];

            for (int i = 0; i < intTempArray.Length; i++)
            {
                intTempArray[i] = BitConverter.ToInt32(tempArray, i * 4);
                var color = Color.FromArgb(intTempArray[i]);
                hueArray[i] = new HSBColor();

                hueArray[i].Saturation = color.GetSaturation();
                hueArray[i].Hue        = color.GetHue();
                hueArray[i].Brightness = color.GetBrightness();



                //=  (color.GetHue() * 10000) + (color.GetBrightness() * 100000) + color.GetSaturation();
            }

            //byte[] byt = new byte[4] { 0, 255, 234, 0 }; //bgra

            //var test = Color.FromArgb(BitConverter.ToInt32(byt, 0));
            //var hue = test.GetHue();

            //var x = Color.Red.GetHue();
            //var y = Color.Green.GetHue();
            //var z = Color.Blue.GetHue();

            screenUpdateTimer.Start();

            SortType srt = (SortType)comboBoxSortType.SelectedValue;


            cTokenSource = new CancellationTokenSource();

            bool hsb = checkBoxHSB.IsChecked ?? false;

            int delay = 0;

            int.TryParse(textBoxDelay.Text, out delay);

            Task sortTask = new Task(() =>
            {
                Sort(intTempArray, srt, cTokenSource.Token, hueArray, hsb, delay);
                ResetSort();
            }, cTokenSource.Token);

            IsSorting          = true;
            SortButton.Content = "Stop";

            labelTime.Foreground = System.Windows.Media.Brushes.Orange;
            labelTime.Content    = "Executing...";

            stopwatch = System.Diagnostics.Stopwatch.StartNew();
            sortTask.Start();
        }
Exemplo n.º 10
0
 private void UpdateBitmap()
 {
     ImageBitmap.WritePixels(new Int32Rect(0, 0, ImageBitmap.PixelWidth, ImageBitmap.PixelHeight), intTempArray, ImageBitmap.PixelWidth * (ImageBitmap.Format.BitsPerPixel) / 8, 0);
 }