Ejemplo n.º 1
0
        public void FromBuffer(GR.Memory.ByteBuffer Data)
        {
            if (Data == null)
            {
                return;
            }
            GR.IO.MemoryReader memIn = Data.MemoryReader();

            int w = memIn.ReadInt32();
            int h = memIn.ReadInt32();

            System.Drawing.Imaging.PixelFormat pf = (System.Drawing.Imaging.PixelFormat)memIn.ReadUInt32();

            Create(w, h, pf);

            int numEntries = memIn.ReadInt32();

            for (int i = 0; i < numEntries; ++i)
            {
                byte r = memIn.ReadUInt8();
                byte g = memIn.ReadUInt8();
                byte b = memIn.ReadUInt8();

                SetPaletteColor(i, r, g, b);
            }
        }
        /// <summary>
        /// Splits image to small block.
        /// </summary>
        /// <param name="inputBitmap">Input image.</param>
        /// <param name="blockSize">Block size</param>
        /// <returns>Blocks.</returns>
        public static Bitmap[] SplitImg(Bitmap inputBitmap, int blockSize)
        {
            /*
             * _____________________
             * |  1  |  2   |  3   |
             * |_____|______|______|
             * |  4  |  5   |  6   |
             * |_____|______|______|
             * |  7  |  8   |  9   |
             * |_____|______|______|
             * |  10 |  11  |  12  |
             * |_____|______|______|
             *
             * Each ind represented one block.
             */
            int column = inputBitmap.Width / blockSize;
            int row    = inputBitmap.Height / blockSize;

            var result = new Bitmap[row * column];

            int i = 0;

            System.Drawing.Imaging.PixelFormat format = inputBitmap.PixelFormat;
            for (int y = 0; y < row; y++)
            {
                for (int x = 0; x < column; x++)
                {
                    RectangleF cloneRect = new RectangleF(x * blockSize, y * blockSize, blockSize, blockSize);
                    result[i++] = inputBitmap.Clone(cloneRect, format);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public int GetEntryImage(int iCombo, int iIndex, out int piImageIndex)
        {
            piImageIndex = 0;

            var targetGlyph = GetSelectedItem(iCombo, iIndex).Glyph;

            if (targetGlyph == null)
            {
                return(VSConstants.S_FALSE);
            }

            int index;

            if (!_glyphIndexes.TryGetValue(targetGlyph, out index))
            {
                index = -1;

                // add the image to the image list
                BitmapSource bitmapSource = targetGlyph as BitmapSource;
                if (bitmapSource != null)
                {
                    if (bitmapSource.Format != PixelFormats.Pbgra32 && bitmapSource.Format != PixelFormats.Bgra32)
                    {
                        var formattedBitmapSource = new FormatConvertedBitmap();
                        formattedBitmapSource.BeginInit();
                        formattedBitmapSource.Source            = bitmapSource;
                        formattedBitmapSource.DestinationFormat = PixelFormats.Pbgra32;
                        formattedBitmapSource.EndInit();

                        bitmapSource = formattedBitmapSource;
                    }

                    int    bytesPerPixel = bitmapSource.Format.BitsPerPixel / 8;
                    byte[] data          = new byte[bitmapSource.PixelWidth * bitmapSource.PixelHeight * bytesPerPixel];
                    int    stride        = bitmapSource.PixelWidth * bytesPerPixel;
                    bitmapSource.CopyPixels(data, stride, 0);
                    IntPtr nativeData = Marshal.AllocHGlobal(data.Length);
                    try
                    {
                        Marshal.Copy(data, 0, nativeData, data.Length);
                        PixelFormat pixelFormat = (bitmapSource.Format == PixelFormats.Bgra32) ? PixelFormat.Format32bppArgb : PixelFormat.Format32bppPArgb;
                        Bitmap      bitmap      = new Bitmap(bitmapSource.PixelWidth, bitmapSource.PixelHeight, stride, pixelFormat, nativeData);
                        _imageList.Images.Add(bitmap);
                        index = _imageList.Images.Count - 1;
                        _glyphIndexes.Add(targetGlyph, index);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(nativeData);
                    }
                }
            }

            if (index >= 0)
            {
                piImageIndex = index;
            }

            return(index >= 0 ? VSConstants.S_OK : VSConstants.S_FALSE);
        }
Ejemplo n.º 4
0
        public void HeadAnimate()
        {
            Bitmap     initPicture = new Bitmap(Properties.Resources.Snake_sprite_sheet);
            RectangleF cloneRect   = new RectangleF(1, 43, 40, 40);

            System.Drawing.Imaging.PixelFormat format = initPicture.PixelFormat;
            Bitmap head1 = initPicture.Clone(cloneRect, format);

            switch (turningJoints[0])
            {
            case MoveDirection.Left:
                head1.RotateFlip(RotateFlipType.Rotate90FlipNone);
                break;

            case MoveDirection.Right:
                head1.RotateFlip(RotateFlipType.Rotate270FlipNone);
                break;

            case MoveDirection.Up:
                head1.RotateFlip(RotateFlipType.Rotate180FlipNone);
                break;

            case MoveDirection.Down:
                head1.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                break;
            }

            snakePixels[0].Image    = head1;
            snakePixels[0].SizeMode = PictureBoxSizeMode.StretchImage;
        }
Ejemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            //轉灰階
            orignGrayImage = new int[bitmap.Width, bitmap.Height];
            imageGray      = new int[bitmap.Width, bitmap.Height];
            BoardKeypoint  = new int[bitmap.Width, bitmap.Height];
            Color tempColor;

            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    int tempGray;
                    tempColor            = bitmap.GetPixel(i, j);
                    tempGray             = toGray(tempColor.R, tempColor.G, tempColor.B);
                    orignGrayImage[i, j] = imageGray[i, j] = tempGray;
                    bitmap.SetPixel(i, j, Color.FromArgb(tempGray, tempGray, tempGray));
                }
            }

            orignBitmap = new Bitmap(myImage);

            format    = orignBitmap.PixelFormat;
            cloneRect = new Rectangle(0, 0, orignBitmap.Width, orignBitmap.Height);
            grayImage = bitmap.Clone(cloneRect, format);

            label1.Text       = "灰階";
            grayFinish        = true;
            pictureBox1.Image = bitmap;
        }
Ejemplo n.º 6
0
        public static Bitmap getDefaultSprite(Bitmap spriteCollection)
        {
            Rectangle cloneRect = new Rectangle(0, 0, 25, 31);

            System.Drawing.Imaging.PixelFormat format = spriteCollection.PixelFormat;
            return(spriteCollection.Clone(cloneRect, format));
        }
        public static bool PureGreenInSubRectangle(Bitmap img, int top, int left, int height, int width, bool saveSubSnap = false)
        {
            Rectangle cloneRect = new Rectangle(left, top, width, height);

            System.Drawing.Imaging.PixelFormat format = img.PixelFormat;
            using (Bitmap cloneBitmap = img.Clone(cloneRect, format))//could iterate through the original bitmap but this is more clear.
            {
                if (saveSubSnap)
                {
                    try
                    {
                        cloneBitmap.Save(@"C:\users\dave\desktop\subpic.png"); //if this doesn't contain the autoprogress arrow, that's the issue.
                    }
                    catch (Exception ex) { Console.WriteLine(ex); }
                }

                int greenToArgb = Color.FromArgb(255, 0, 255, 0).ToArgb();//this pure green appears to be used for the autoprogress toggle, and nowhere else on the UI.  Could give false positives?
                for (int x = 0; x < cloneBitmap.Width; x++)
                {
                    for (int y = 0; y < cloneBitmap.Height; y++)
                    {
                        Color c = cloneBitmap.GetPixel(x, y);
                        if (c.ToArgb() == greenToArgb)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Converts from a system pixel format into a Psi.Imaging pixel format.
        /// </summary>
        /// <param name="pixelFormat">System pixel format to be converted.</param>
        /// <returns>Psi.Imaging pixel format that matches the specified system pixel format.</returns>
        internal static PixelFormat FromSystemPixelFormat(System.Drawing.Imaging.PixelFormat pixelFormat)
        {
            if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            {
                return(PixelFormat.BGR_24bpp);
            }

            if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppRgb)
            {
                return(PixelFormat.BGRX_32bpp);
            }

            if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                return(PixelFormat.Gray_8bpp);
            }

            if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format16bppGrayScale)
            {
                return(PixelFormat.Gray_16bpp);
            }

            if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            {
                return(PixelFormat.BGRA_32bpp);
            }

            if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format64bppArgb)
            {
                return(PixelFormat.RGBA_64bpp);
            }

            throw new NotSupportedException($"The {pixelFormat} pixel format is not currently supported by {nameof(Microsoft.Psi.Imaging)}.");
        }
        private void CbNumDepredadoras_SelectedIndexChanged(object sender, EventArgs e)
        {
            LimpiarBitmap(Animacion, Color.Transparent);
            Rectangle Dimensiones = new Rectangle(0, 0, Picture.Width, Picture.Height);

            System.Drawing.Imaging.PixelFormat Formato = Picture.PixelFormat;
            Grafo = copia.Clone(Dimensiones, Formato);
            pictureBox1.BackgroundImage = Grafo;
            pictureBox1.Refresh();
            this.CbNumPresas.Items.Clear();
            int Elegido   = this.CbNumDepredadoras.SelectedIndex + 1;
            int Sobrantes = G.getLv().Count - Elegido;

            for (int i = 1; i <= Sobrantes; i++)
            {
                this.CbNumPresas.Items.Add(i);
            }
            if (CbNumPresas.Text != "" && CbNumDepredadoras.Text != "")
            {
                this.BtnIngresarAgentes.Enabled = true;
            }
            Inserciones          = false;
            ContVertices         = 0;
            this.NumAgentes.Text = ContVertices.ToString();
            Usados.Clear();
            ListaDepredadores.Items.Clear();
            ListaRadar.Items.Clear();
        }
Ejemplo n.º 10
0
        private void loadPreview()
        {
            Bitmap resizedImage = new Bitmap(imageToUse, new Size(200, 200));

            if (imageLoaded)
            {
                cleanPbArray();
            }
            pbArray  = new PictureBox[optObj.size, optObj.size];
            prevSize = optObj.size;
            int tileSize = (int)Math.Floor((float)resizedImage.Width / optObj.size);

            for (int x = 0; x < optObj.size; x++)
            {
                for (int y = 0; y < optObj.size; y++)
                {
                    Rectangle cloneRect = new Rectangle(tileSize * x, tileSize * y, tileSize, tileSize);
                    System.Drawing.Imaging.PixelFormat format = resizedImage.PixelFormat;
                    Bitmap tile = resizedImage.Clone(cloneRect, format);
                    pbArray[x, y] = new PictureBox();
                    Controls.Add(pbArray[x, y]);
                    pbArray[x, y].Name                  = "pbArray_" + x + "_" + y;
                    pbArray[x, y].Size                  = new Size(tileSize, tileSize);
                    pbArray[x, y].BackColor             = Color.White;
                    pbArray[x, y].BackgroundImageLayout = ImageLayout.Stretch;
                    pbArray[x, y].Location              = new Point(grpTab.Location.X + tileSize * x + 5 * x + (grpTab.Width - (tileSize + 5) * optObj.size) / 2, grpTab.Location.Y + 260 + 5 * y + tileSize * y);
                    pbArray[x, y].Anchor                = AnchorStyles.Left;
                    pbArray[x, y].Visible               = true;
                    pbArray[x, y].BringToFront();
                    pbArray[x, y].Image = tile;
                }
            }
            imageLoaded = true;
        }
Ejemplo n.º 11
0
        private void GetBitmapRectangle()
        {
            // Define format, manipulation mode and area to modify
            System.Drawing.Imaging.PixelFormat   pxf = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
            System.Drawing.Imaging.ImageLockMode ilm = System.Drawing.Imaging.ImageLockMode.ReadWrite;
            Rectangle r = new Rectangle(0, 0, bm.Width, bm.Height);

            // Lock the bitmap bits
            System.Drawing.Imaging.BitmapData bmData = this.bm.LockBits(r, ilm, pxf);

            // Get the address of the first line
            IntPtr ptr = bmData.Scan0;

            // Declare an array to hold the bytes of the bitmap
            int numBytes = bm.Width * bm.Height * 3;

            byte[] rgbValues = new byte[numBytes];

            // Copy the RGB values into the array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, numBytes);

            // Manipulate the bitmap, such as changing the
            // blue value for every other pixel in the bitmap.
            for (int counter = 0; counter < rgbValues.Length; counter += 6)
            {
                rgbValues[counter] = 200;
            }

            // Copy the RGB values back to the bitmap
            System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, numBytes);

            // Unlock the bits
            bm.UnlockBits(bmData);
        }
Ejemplo n.º 12
0
    void FilerImage()
    {
        // Copy Image to Bitmap
        System.Drawing.Rectangle             ImageBounds = new System.Drawing.Rectangle(0, 0, Bitmap.Width, Bitmap.Height);
        System.Drawing.Imaging.ImageLockMode Mode        = System.Drawing.Imaging.ImageLockMode.ReadWrite;
        System.Drawing.Imaging.PixelFormat   Format      = Bitmap.PixelFormat;
        System.Drawing.Imaging.BitmapData    BitmapData  = Bitmap.LockBits(ImageBounds, Mode, Format);

        System.IntPtr ptr = BitmapData.Scan0;

        System.Runtime.InteropServices.Marshal.Copy(FilterdAndCroppedDepthImage, 0, ptr, FilterdAndCroppedDepthImage.Length);

        Bitmap.UnlockBits(BitmapData);

        //Apply Filter
        Blur.ApplyInPlace(Bitmap);

        //Copy Bitmap back to Image
        BitmapData = Bitmap.LockBits(ImageBounds, Mode, Format);

        ptr = BitmapData.Scan0;
        System.Runtime.InteropServices.Marshal.Copy(ptr, FilterdAndCroppedDepthImage, 0, FilterdAndCroppedDepthImage.Length);

        Bitmap.UnlockBits(BitmapData);
    }
Ejemplo n.º 13
0
        public static Bitmap ToBitmap(this BitmapSource bitmapSource, System.Drawing.Imaging.PixelFormat pixelFormat)
        {
            int    width  = bitmapSource.PixelWidth;
            int    height = bitmapSource.PixelHeight;
            int    stride = width * ((bitmapSource.Format.BitsPerPixel + 7) / 8); // 行の長さは色深度によらず8の倍数のため
            IntPtr intPtr = IntPtr.Zero;

            try
            {
                intPtr = Marshal.AllocCoTaskMem(height * stride);
                bitmapSource.CopyPixels(new Int32Rect(0, 0, width, height), intPtr, height * stride, stride);
                using (var bitmap = new Bitmap(width, height, stride, pixelFormat, intPtr))
                {
                    // IntPtrからBitmapを生成した場合、Bitmapが存在する間、AllocCoTaskMemで確保したメモリがロックされたままとなる
                    // (FreeCoTaskMemするとエラーとなる)
                    // そしてBitmapを単純に開放しても解放されない
                    // このため、明示的にFreeCoTaskMemを呼んでおくために一度作成したBitmapから新しくBitmapを
                    // 再作成し直しておくとメモリリークを抑えやすい
                    return(new Bitmap(bitmap));
                }
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(intPtr);
                }
            }
        }
Ejemplo n.º 14
0
        public static ImageDatatype ImagingPixelFormatToDatatype(ImagingPixelFormat pixelFormat)
        {
            if (!Supported(pixelFormat))
            {
                throw new ArgumentException("Pixel format is not supported.", "pixelFormat");
            }

            // TODO:  Not tested exhaustively
            switch (pixelFormat)
            {
            case ImagingPixelFormat.Format16bppRgb555:
                return(ImageDatatype.UnsignedShort5551);

            case ImagingPixelFormat.Format16bppRgb565:
                return(ImageDatatype.UnsignedShort565);

            case ImagingPixelFormat.Format24bppRgb:
            case ImagingPixelFormat.Format32bppRgb:
            case ImagingPixelFormat.Format32bppArgb:
                return(ImageDatatype.UnsignedByte);

            case ImagingPixelFormat.Format48bppRgb:
            case ImagingPixelFormat.Format64bppArgb:
                return(ImageDatatype.UnsignedShort);

            case ImagingPixelFormat.Format16bppArgb1555:
                return(ImageDatatype.UnsignedShort1555Reversed);
            }

            throw new ArgumentException("pixelFormat");
        }
Ejemplo n.º 15
0
        private void Preparacion()
        {
            Identificador = 0;
            Pos           = 1;
            Y             = 0;
            Semilla       = Environment.TickCount;
            Procesos.Clear();
            Lista.Clear();
            Terminados.Clear();
            TablaPocisiones.Rows.Clear();
            TablaPocisiones.Refresh();
            Picture = global::Actividad_1_FCFS.Properties.Resources.Pasto;
            TablaPocisiones.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            Rectangle Dimensiones = new Rectangle(0, 0, Picture.Width, Picture.Height);

            System.Drawing.Imaging.PixelFormat Formato = Picture.PixelFormat;
            Animacion = Picture.Clone(Dimensiones, Formato);
            Animacion.MakeTransparent();
            pictureBox1.Image                 = Animacion;
            pictureBox1.BackgroundImage       = Picture;
            pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            Graphics Grafico = Graphics.FromImage(Animacion);

            Grafico.DrawImage(Caballo, 10, 0);
            Grafico.DrawImage(Caballo, 10, 100);
            Grafico.DrawImage(Caballo, 10, 200);
            Grafico.DrawImage(Caballo, 10, 300);
            Grafico.DrawImage(Caballo, 10, 400);
            pictureBox1.Refresh();
        }
Ejemplo n.º 16
0
        private void frmMenu_Load(object sender, EventArgs e)
        {
            btnPlay.FlatAppearance.MouseDownBackColor    = Color.Transparent;
            btnPlay.FlatAppearance.MouseOverBackColor    = Color.Transparent;
            btnOptions.FlatAppearance.MouseDownBackColor = Color.Transparent;
            btnOptions.FlatAppearance.MouseOverBackColor = Color.Transparent;
            btnScore.FlatAppearance.MouseDownBackColor   = Color.Transparent;
            btnScore.FlatAppearance.MouseOverBackColor   = Color.Transparent;
            btnOut.FlatAppearance.MouseDownBackColor     = Color.Transparent;
            btnOut.FlatAppearance.MouseOverBackColor     = Color.Transparent;
            bmpArray = new Bitmap[size, size];
            Bitmap resizedImage = new Bitmap(imageToUse, new Size(300, 300));

            bmpArray = new Bitmap[size, size];
            int tileSize = (int)Math.Floor((float)resizedImage.Width / size);

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    Rectangle cloneRect = new Rectangle(tileSize * x, tileSize * y, tileSize, tileSize);
                    System.Drawing.Imaging.PixelFormat format = resizedImage.PixelFormat;
                    Bitmap tile = resizedImage.Clone(cloneRect, format);
                    bmpArray[x, y] = tile;
                }
            }
        }
Ejemplo n.º 17
0
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            if (AggSystemWindow != null)
            {
                System.Drawing.Imaging.PixelFormat format = System.Drawing.Imaging.PixelFormat.Undefined;
                switch (AggSystemWindow.BitDepth)
                {
                case 24:
                    format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
                    break;

                case 32:
                    format = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
                    break;

                default:
                    throw new NotImplementedException();
                }
                var clientSize = this.ClientSize;

                int bitDepth = System.Drawing.Image.GetPixelFormatSize(format);
                bitmapBackBuffer.Initialize((int)clientSize.Width, (int)clientSize.Height, bitDepth);
                NewGraphics2D().Clear(new ColorF(1, 1, 1, 1));
            }
        }
Ejemplo n.º 18
0
        public static Bitmap CopyBitmap(Bitmap src, System.Drawing.Imaging.PixelFormat pixelFormat)
        {
            var dest = new Bitmap(src.Width, src.Height, pixelFormat);

            CopyBitmap(src, dest);
            return(dest);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a new instance of an interactive image.
        /// </summary>
        /// <param name="Width">Width of the image.</param>
        /// <param name="Height">Height of the image.</param>
        /// <param name="bytesPixel">Number of bytes per pixel</param>
        public Interactive8BitImage(int Width,
                                    int Height,
                                    System.Drawing.Imaging.PixelFormat Format)
        {
            width  = Width;
            height = Height;

            format = Format;

            SetBytesPixel(format);


            //bytes = width * height * bytesPixel;
            bytesLine = width * bytesPixel;

            // Set the byte boundary
            byteBoundary = (4 - bytesLine % 4) % 4;

            // Calculate total number of bytes used by this 8 bit image
            bytes = bytesLine * height + height * byteBoundary;

            pixels = new byte[bytes];

            for (int i = 0; i < pixels.Length; i++)
            {
                pixels[i] = 150;
            }

            bitImage = new Bitmap(Width, Height, format);
        }
Ejemplo n.º 20
0
        private Bitmap clones(int num)
        {
            System.Drawing.Imaging.PixelFormat format = dices.PixelFormat;
            switch (num)
            {
            case 1:
                clone = dices.Clone(rec[0], format);
                break;

            case 2:
                clone = dices.Clone(rec[1], format);
                break;

            case 3:
                clone = dices.Clone(rec[2], format);
                break;

            case 4:
                clone = dices.Clone(rec[3], format);
                break;

            case 5:
                clone = dices.Clone(rec[4], format);
                break;

            case 6:
                clone = dices.Clone(rec[5], format);
                break;
            }
            return(clone);
        }
Ejemplo n.º 21
0
        public void cutChar(Bitmap img)
        {
            Graphics gp    = Graphics.FromImage(img);
            Bitmap32 bmp32 = new Bitmap32(img);

            System.Drawing.Imaging.PixelFormat format = new System.Drawing.Imaging.PixelFormat();
            Point top, left, bot, right, prect;

            bmp32.LockBitmap();
            top   = bmp32.TopPoint();
            left  = bmp32.LeftPoint();
            bot   = bmp32.BotPoint();
            right = bmp32.RightPoint();
            //bmp32.Vector();
            int of = bmp32.Offset();

            for (int y = 0; y < img.Height; y++)
            {
                for (int x = 0; x < img.Width; x++)
                {
                    bmp32.DrawOutLine(x, y, of);
                }
            }
            bmp32.UnlockBitmap();
            prect = new Point(left.X, top.Y);
            Rectangle rect = new Rectangle(prect, new Size(right.X - left.X, bot.Y - top.Y));
            Bitmap    clone = img.Clone(rect, format);

            gp.DrawRectangle(new Pen(Color.Green), rect);
            picFitter.Image = clone;
        }
Ejemplo n.º 22
0
        public override BitmapInstance Convert(PixelFormat format, bool discardAlpha)
        {
            if (discardAlpha && format != PixelFormat.Argb32)
            {
                throw new InvalidOperationException();
            }

            System.Drawing.Imaging.PixelFormat gdiFormat = format.ToGDIFormat();
            System.Drawing.Bitmap bitmap = Instance.Convert(gdiFormat);

            if (discardAlpha)
            {
                byte[] buffer = bitmap.GetPixels();

                int length = buffer.Length / 4;
                for (int i = 0; i < length; ++i)
                {
                    buffer[i * 4 + 3] = 0;
                }

                bitmap.SetPixels(buffer);
            }

            return(new BitmapInstanceImpl(bitmap));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates an Interactive_Image from a bitmap.
        /// </summary>
        /// <param name="Original"></param>
        public Interactive8BitImage(Bitmap Original)
        {
            width  = Original.Width;
            height = Original.Height;

            format = Original.PixelFormat;

            if (format != System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            {
                throw new System.FormatException("Bitmap was in the wrong format.");
            }

            SetBytesPixel(format);

            bytes     = width * height * bytesPixel;
            bytesLine = width * bytesPixel;

            byte[] pixels_to_copy = new byte[bytes];

            System.Drawing.Imaging.BitmapData bmpData =
                Original.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite,
                                  Original.PixelFormat);

            System.Runtime.InteropServices.Marshal.Copy(bmpData.Scan0, pixels_to_copy, 0, bytes);

            pixels = (byte[])pixels_to_copy.Clone();

            System.Runtime.InteropServices.Marshal.Copy(pixels_to_copy, 0, bmpData.Scan0, bytes);

            Original.UnlockBits(bmpData);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Converts from a system pixel format into a Psi.Imaging pixel format
        /// </summary>
        /// <param name="pf">System pixel format to be converted</param>
        /// <returns>Psi.Imaging pixel format that matches the specified system pixel format</returns>
        public static PixelFormat FromSystemPixelFormat(System.Drawing.Imaging.PixelFormat pf)
        {
            if (pf == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            {
                return(PixelFormat.BGR_24bpp);
            }

            if (pf == System.Drawing.Imaging.PixelFormat.Format32bppRgb)
            {
                return(PixelFormat.BGRX_32bpp);
            }

            if (pf == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                return(PixelFormat.Gray_8bpp);
            }

            if (pf == System.Drawing.Imaging.PixelFormat.Format16bppGrayScale)
            {
                return(PixelFormat.Gray_16bpp);
            }

            if (pf == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            {
                return(PixelFormat.BGRA_32bpp);
            }

            if (pf == System.Drawing.Imaging.PixelFormat.Format64bppArgb)
            {
                return(PixelFormat.RGBA_64bpp);
            }

            throw new Exception("Unsupported pixel format");
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Split an external image into an array of images and store them in the Content Manager
        /// </summary>
        /// <param name="filePath">File path to the image to be split</param>
        /// <param name="numCuts">Number of divisions the image should be cut to</param>
        /// <param name="fileNames">Optional names for the new set of images</param>
        /// <returns>An array of Bitmap images</returns>
        public Bitmap[] SplitImage(string filePath, int numCuts, string fileNames = "file")
        {
            Bitmap orig = new Bitmap(filePath);

            Bitmap[] bmp = new Bitmap[numCuts];

            Rectangle cloneRect = new Rectangle(0, 0, orig.Width / (numCuts / 2), orig.Height / (numCuts / 2));

            System.Drawing.Imaging.PixelFormat format = orig.PixelFormat;
            int   tracker   = 0;
            float cutFactor = numCuts / 2;

            for (int i = 0; i < cutFactor; i++)
            {
                for (int j = 0; j < cutFactor; j++)
                {
                    cloneRect    = new Rectangle((int)(orig.Width * (i / cutFactor)), (int)(orig.Height * (j / cutFactor)), (int)(orig.Width / cutFactor), (int)(orig.Height / cutFactor));
                    bmp[tracker] = orig.Clone(cloneRect, format);
                    tracker++;
                    AddImage(string.Concat(fileNames, tracker.ToString()), bmp[i]);
                }
            }

            return(bmp);
        }
Ejemplo n.º 26
0
        public void BodyAnimate()
        {
            for (int i = 1; i < snakePixels.Count - 1; i++)
            {
                Bitmap     initPicture = new Bitmap(Properties.Resources.Snake_sprite_sheet);
                RectangleF cloneRect   = new RectangleF(85, 85, 40, 40);
                System.Drawing.Imaging.PixelFormat format = initPicture.PixelFormat;
                Bitmap body = initPicture.Clone(cloneRect, format);

                switch (turningJoints[i])
                {
                case MoveDirection.Left:
                case MoveDirection.Right:
                    body.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;

                case MoveDirection.Up:
                case MoveDirection.Down:
                    body.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                    break;
                }

                snakePixels[i].Image    = body;
                snakePixels[i].SizeMode = PictureBoxSizeMode.StretchImage;
            }
        }
Ejemplo n.º 27
0
        public static Image SquareImage(Image Source)
        {
            System.Drawing.Imaging.PixelFormat PixelFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
            if (Source.Height > Source.Width)
            {
                //Retrato
                System.Drawing.Image    Image = new System.Drawing.Bitmap(Source.Width, Source.Width, PixelFormat);
                System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(Image);
                int dif = (Source.Height - Source.Width) / 2;

                System.Drawing.Rectangle srcRect = new System.Drawing.Rectangle(0, dif, Source.Width, Source.Width);
                System.Drawing.Rectangle desRect = new System.Drawing.Rectangle(0, 0, Source.Width, Source.Width);

                g.DrawImage(Source, desRect, srcRect, System.Drawing.GraphicsUnit.Pixel);
                return(Image);
            }
            else
            {
                //Paisagem
                System.Drawing.Image    Image = new System.Drawing.Bitmap(Source.Height, Source.Height, PixelFormat);
                System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(Image);
                int dif = (Source.Width - Source.Height) / 2;

                System.Drawing.Rectangle srcRect = new System.Drawing.Rectangle(dif, 0, Source.Height, Source.Height);
                System.Drawing.Rectangle desRect = new System.Drawing.Rectangle(0, 0, Source.Height, Source.Height);

                g.DrawImage(Source, desRect, srcRect, System.Drawing.GraphicsUnit.Pixel);
                return(Image);
            }
        }
Ejemplo n.º 28
0
 public void Clear()
 {
     m_PixelFormat = System.Drawing.Imaging.PixelFormat.Undefined;
     m_Width       = 0;
     m_Height      = 0;
     m_PaletteData.Clear();
 }
Ejemplo n.º 29
0
        public static Image ResizeImage(Image Source, int Percent, System.Drawing.Imaging.PixelFormat PixelFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb)
        {
            int w = (int)((decimal)Source.Width * (decimal)Percent / 100);
            int h = (int)((decimal)Source.Height * (decimal)Percent / 100);

            return(ResizeImage(Source, w, h, PixelFormat));
        }
Ejemplo n.º 30
0
        internal static PixelFormat GetPixelFormat(this System.Drawing.Imaging.PixelFormat pixelFormat)
        {
            switch (pixelFormat)
            {
            case System.Drawing.Imaging.PixelFormat.Format4bppIndexed:
                return(PixelFormat.Indexed4);

            case System.Drawing.Imaging.PixelFormat.Format8bppIndexed:
                return(PixelFormat.Indexed8);

            case System.Drawing.Imaging.PixelFormat.Format24bppRgb:
                return(PixelFormat.Rgb888);

            case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555:
                return(PixelFormat.Rgba1555);

            case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
                return(PixelFormat.Rgba8888);

            case System.Drawing.Imaging.PixelFormat.Format32bppRgb:
                return(PixelFormat.Rgbx8888);

            default:
                throw new NotImplementedException(
                          $"The pixel format {pixelFormat} is not implemented.");
            }
        }
Ejemplo n.º 31
0
        public static ImageDatatype ImagingPixelFormatToDatatype(ImagingPixelFormat pixelFormat)
        {
            if (!Supported(pixelFormat))
            {
                throw new ArgumentException("Pixel format is not supported.", "pixelFormat");
            }

            // TODO:  Not tested exhaustively
            switch (pixelFormat)
            {
                case ImagingPixelFormat.Format16bppRgb555:
                    return ImageDatatype.UnsignedShort5551;
                case ImagingPixelFormat.Format16bppRgb565:
                    return ImageDatatype.UnsignedShort565;
                case ImagingPixelFormat.Format24bppRgb:
                case ImagingPixelFormat.Format32bppRgb:
                case ImagingPixelFormat.Format32bppArgb:
                    return ImageDatatype.UnsignedByte;
                case ImagingPixelFormat.Format48bppRgb:
                case ImagingPixelFormat.Format64bppArgb:
                    return ImageDatatype.UnsignedShort;
                case ImagingPixelFormat.Format16bppArgb1555:
                    return ImageDatatype.UnsignedShort1555Reversed;
            }

            throw new ArgumentException("pixelFormat");
        }
Ejemplo n.º 32
0
 private QuickDraw(Bitmap bitmap)
 {
     fast = new FastBitmap(bitmap);
     width = bitmap.Width;
     height = bitmap.Height;
     format = bitmap.PixelFormat;
     Bpp = (Image.GetPixelFormatSize(bitmap.PixelFormat) / 8); ;
 }
Ejemplo n.º 33
0
        public BitmapPlus(int width, int height, PixelFormat format)
        {
            Initialize();
            GpBitmap bitmap = new GpBitmap();

            lastResult = GdiPlus.GdipCreateBitmapFromScan0(width,
                                                               height,
                                                               0,
                                                               format,
                                                               IntPtr.Zero,
                                                               out bitmap);

            SetNativeImage((GpImage)(IntPtr)bitmap);
        }
Ejemplo n.º 34
0
 private static bool Supported(ImagingPixelFormat pixelFormat)
 {
     return
         (pixelFormat != ImagingPixelFormat.DontCare) &&
         (pixelFormat != ImagingPixelFormat.Undefined) &&
         (pixelFormat != ImagingPixelFormat.Indexed) &&
         (pixelFormat != ImagingPixelFormat.Gdi) &&
         (pixelFormat != ImagingPixelFormat.Extended) &&
         (pixelFormat != ImagingPixelFormat.Format1bppIndexed) &&
         (pixelFormat != ImagingPixelFormat.Format4bppIndexed) &&
         (pixelFormat != ImagingPixelFormat.Format8bppIndexed) &&
         (pixelFormat != ImagingPixelFormat.Alpha) &&
         (pixelFormat != ImagingPixelFormat.PAlpha) &&
         (pixelFormat != ImagingPixelFormat.Format32bppPArgb) &&
         (pixelFormat != ImagingPixelFormat.Format16bppGrayScale) &&
         (pixelFormat != ImagingPixelFormat.Format64bppPArgb) &&
         (pixelFormat != ImagingPixelFormat.Canonical);
 }
Ejemplo n.º 35
0
public BitmapPlus(
    int width,
    int height,
    int stride,
    PixelFormat format,
    IntPtr scan0
    )
{
    GpBitmap bitmap = new GpBitmap();

    lastResult = NativeMethods.GdipCreateBitmapFromScan0(width,
                                                       height,
                                                       stride,
                                                       format,
                                                       scan0,
                                                       out bitmap);

    SetNativeImage((GpImage)(IntPtr)bitmap);
}
        public void cropImage()
        {
            Bitmap SourceImage = new Bitmap(@"C:\Users\nhonarva\Documents\strabo-command-line-master\strabo-command-line-master\Strabo.CommandLine\data\intermediate\BinaryOutput.png");
            Bitmap Cropped;
            int counter=0;
            for(int i=0;i<54;i++)
            {
                for (int j=0;j<54;j++)
                {

                    Point rectangleLocation=new Point(i*28,j*28);
                    Size rectangleSize=new Size(28,28);
                    Rectangle boundingBox=new Rectangle(rectangleLocation,rectangleSize);
                    System.Drawing.Imaging.PixelFormat format = new System.Drawing.Imaging.PixelFormat();
                    Cropped= SourceImage.Clone(boundingBox, format);
                    counter++;
                    Cropped.Save(@"C:\Users\nhonarva\Documents\MachineLearning\Test&TrainedData\"+counter+".png");
                }
            }
        }
Ejemplo n.º 37
0
        public static ImageFormat ImagingPixelFormatToImageFormat(ImagingPixelFormat pixelFormat)
        {
            if (!Supported(pixelFormat))
            {
                throw new ArgumentException("Pixel format is not supported.", "pixelFormat");
            }

            switch (pixelFormat)
            {
                case ImagingPixelFormat.Format16bppRgb555:
                case ImagingPixelFormat.Format16bppRgb565:
                case ImagingPixelFormat.Format24bppRgb:
                case ImagingPixelFormat.Format32bppRgb:
                case ImagingPixelFormat.Format48bppRgb:
                    return ImageFormat.BlueGreenRed;
                case ImagingPixelFormat.Format16bppArgb1555:
                case ImagingPixelFormat.Format32bppArgb:
                case ImagingPixelFormat.Format64bppArgb:
                    return ImageFormat.BlueGreenRedAlpha;
            }

            throw new ArgumentException("pixelFormat");
        }
Ejemplo n.º 38
0
 public static Bitmap CreateBitmap(int width, int height, PixelFormat config)
 {
     return new Bitmap(width, height, config);
 }
Ejemplo n.º 39
0
        // Privately retrieves the pixel format
        private void retrievePixelFormat()
        {
            // Variables
            int	result;

            if(GdipGetImagePixelFormat(new HandleRef(this, pNativeImage), out result)!= 0)
                result=	0;

            pFormat=	(Sdx.Imaging.PixelFormat)result;
        }
Ejemplo n.º 40
0
        /*{{{*/
        private void loadFromPackFile(BinaryReader binReader, int sn)
        {
            List<MMTextureData> TempSubTextureInfo = new List<MMTextureData>();
            readString(binReader);
            int numEntries = binReader.ReadInt32();
            /* bool mask = */ binReader.ReadInt32()/* != 0*/;
            for (int n = 0; n < numEntries; n++)
            {
                String entryName = readString(binReader);
                int a = binReader.ReadInt32();
                int b = binReader.ReadInt32();
                int c = binReader.ReadInt32();
                int d = binReader.ReadInt32();
                int e = binReader.ReadInt32();
                int f = binReader.ReadInt32();
                int g = binReader.ReadInt32();
                int h = binReader.ReadInt32();
                TempSubTextureInfo.Add(new MMTextureData(a, b, c, d, e, f, g, h, entryName));
            }
            long posPNGstart = binReader.BaseStream.Position;
            binReader.BaseStream.Seek(8, SeekOrigin.Current); //skip header
            //start reading PNG chunks
            int datalen = 0;
            string chunkid = "";
            do
            {
                datalen = this.readInt(binReader.ReadBytes(4));
                this.strBuilder.Clear();
                for (int n = 0; n < 4; n++)
                {
                    this.strBuilder.Append(binReader.ReadChar());
                }
                chunkid = strBuilder.ToString();
                if (chunkid != "IEND") // <- reminder this is advised against
                {
                    binReader.BaseStream.Seek(datalen, SeekOrigin.Current);
                    binReader.BaseStream.Seek(4, SeekOrigin.Current);
                }
                else
                {
                    binReader.BaseStream.Seek(4, SeekOrigin.Current);
                }
            } while (chunkid != "IEND");
            long posPNGend = binReader.BaseStream.Position;

            binReader.BaseStream.Seek(posPNGstart, SeekOrigin.Begin);
            byte[] data = binReader.ReadBytes(Convert.ToInt32(posPNGend - posPNGstart));

            Image img = Image.FromStream(new MemoryStream(data));
            Bitmap bm = new Bitmap(img);
            //bm.Save(OutputDir + "test" + Convert.ToString(sn) + ".png", System.Drawing.Imaging.ImageFormat.Png);
            //if (this.format != bm.PixelFormat)
            //{
                this.format = bm.PixelFormat;
            //}

            foreach (MMTextureData tex in TempSubTextureInfo)
            {
                tex.SetData(bm);
                //add to regular text table
                if (!this.Textures.ContainsKey(tex.name))
                    this.Textures.Add(tex.name, tex);
                //add to sheet
                string[] nameparts = tex.name.Split(new Char[] { '_' });
                if (nameparts.Count() == 1)
                    nameparts = new string[2] { nameparts[0], "1" }; // small fix for some odd sheets
                string sheetname = nameparts[0] + "_" + nameparts[1];
                if (!this.Sheets.ContainsKey(sheetname))
                    this.Sheets.Add(sheetname, new Dictionary<string, MMTextureData>());
                if (!this.Sheets[sheetname].ContainsKey(tex.name))
                    this.Sheets[sheetname].Add(tex.name, tex);
            }

            int id = 0;
            do
            {
                id = binReader.ReadInt32();
            } while (id != -559038737);
        }
Ejemplo n.º 41
0
 private PixelInternalFormat TextureFormatForBitmapFormat(BitmapPixelFormat format)
 {
     switch (format) {
         case BitmapPixelFormat.Format16bppGrayScale: return PixelInternalFormat.Luminance;
         //case Format.GrayscaleAlpha: return PixelInternalFormat.LuminanceAlpha;
         case BitmapPixelFormat.Format24bppRgb: return PixelInternalFormat.Rgb;
         case BitmapPixelFormat.Format32bppArgb: return PixelInternalFormat.Rgba;
         default: throw new Exception("Unrecognised Bitmap.Format");
     }
 }
Ejemplo n.º 42
0
public GpStatus LockBits(
    GpRect rect,
    uint flags,
    PixelFormat format,
    BitmapData lockedBitmapData
)
{
    return SetStatus(NativeMethods.GdipBitmapLockBits(
                                    (GpBitmap)(IntPtr)nativeImage,
                                    rect,
                                    flags,
                                    format,
                                    lockedBitmapData));
}
Ejemplo n.º 43
0
 public void LockBits(Rectangle rect, uint flags, PixelFormat format, BitmapData lockedBitmapData)
 {
     SetStatus(GdiPlus.GdipBitmapLockBits(
                                     (GpBitmap)(IntPtr)nativeImage,
                                     rect,
                                     flags,
                                     format,
                                     lockedBitmapData));
 }