Exemplo n.º 1
0
        private void ConvertMosaic()
        {
            if (this.mosaicBitmap?.Source != null)
            {
                int x1, x2, y1, y2;
                if (this.clickPos.X < this.dragPos.X)
                {
                    x1 = (int)Math.Floor((this.clickPos.X + this.horizontalBar.Value) / (this.zoom / 100.0));
                    x2 = (int)Math.Ceiling((this.dragPos.X + this.horizontalBar.Value) / (this.zoom / 100.0));
                }
                else
                {
                    x1 = (int)Math.Floor((this.dragPos.X + this.horizontalBar.Value) / (this.zoom / 100.0));
                    x2 = (int)Math.Ceiling((this.clickPos.X + this.horizontalBar.Value) / (this.zoom / 100.0));
                }
                if (this.clickPos.Y < this.dragPos.Y)
                {
                    y1 = (int)Math.Floor((this.clickPos.Y + this.verticalBar.Value) / (this.zoom / 100.0));
                    y2 = (int)Math.Ceiling((this.dragPos.Y + this.verticalBar.Value) / (this.zoom / 100.0));
                }
                else
                {
                    y1 = (int)Math.Floor((this.dragPos.Y + this.verticalBar.Value) / (this.zoom / 100.0));
                    y2 = (int)Math.Ceiling((this.clickPos.Y + this.verticalBar.Value) / (this.zoom / 100.0));
                }

                var size   = mosaicTile[this.szindex];
                var bitmap = new Bitmap(this.mosaicBitmap.Source);
                var data   = bitmap.LockBits(
                    new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                    System.Drawing.Imaging.ImageLockMode.ReadWrite,
                    System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                var buf = new byte[bitmap.Width * bitmap.Height * 4];
                Marshal.Copy(data.Scan0, buf, 0, buf.Length);

                for (int y = y1; y < bitmap.Height && y < y2; y += size)
                {
                    for (int x = x1; x < bitmap.Width && x < x2; x += size)
                    {
                        this.AvePixel(bitmap, data, buf, x, y, size);
                    }
                }

                Marshal.Copy(buf, 0, data.Scan0, buf.Length);
                bitmap.UnlockBits(data);

                this.mainControl.Remove(BITMAP_NAME);
                this.mosaicBitmap = this.mainControl.CreateBitmap(BITMAP_NAME, bitmap);
                this.mainControl.Rebuild();
            }
        }
Exemplo n.º 2
0
        private void SetModifiImage()
        {
            try {
                // クリップボードの画像を取得する
                var bitmap = this.ReadClipBoard();

                this.mainControl.Remove(BITMAP_NAME);
                this.mosaicBitmap = this.mainControl.CreateBitmap(BITMAP_NAME, bitmap);
                this.mainControl.Rebuild();
                this.CalcScrollBar();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private void mainControl_DragDrop(object sender, DragEventArgs e)
        {
            var fileName = (string[])e.Data.GetData(DataFormats.FileDrop, false);

            if (fileName.Length > 0 && System.IO.File.Exists(fileName[0]))
            {
                try {
                    var bitmap = new Bitmap(fileName[0]);
                    this.mainControl.Remove(BITMAP_NAME);
                    this.mosaicBitmap = this.mainControl.CreateBitmap(BITMAP_NAME, bitmap);
                    this.mainControl.Rebuild();
                    this.CalcScrollBar();
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 4
0
        private void openBtn_Click(object sender, EventArgs e)
        {
            using (var dialog = new OpenFileDialog()) {
                dialog.RestoreDirectory = true;
                dialog.Filter           = "画像ファイル|*.bmp;*.jpeg;*.png";
                dialog.Filter           = "全てのファイル|*.*";
                dialog.FilterIndex      = 0;
                dialog.Title            = "画像を選択";
                dialog.Multiselect      = false;

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var bitmap = new Bitmap(dialog.FileName);
                    this.mainControl.Remove(BITMAP_NAME);
                    this.mosaicBitmap = this.mainControl.CreateBitmap(BITMAP_NAME, bitmap);
                    this.mainControl.Rebuild();
                    this.CalcScrollBar();
                }
            }
        }