Clone() public method

Creates a copy of the section of this Bitmap defined by Rectangle structure and with a specified PixelFormat enumeration.
public Clone ( Rectangle rect, PixelFormat pixelFormat ) : Bitmap
rect Rectangle Rect.
pixelFormat PixelFormat Pixel format.
return Bitmap
        public void AddImage(BackgroundImageClass image)
        {
            var imageBytes = webClientWrapper.DownloadBytes(image.ImageUrl);
            Bitmap bitmap = null;
            using (var originalBitmap = new Bitmap(new MemoryStream(imageBytes)))
            {
                using (var writer = new SpriteWriter(image.Width ?? originalBitmap.Width, image.Height ?? originalBitmap.Height))
                {
                    var width = image.Width ?? originalBitmap.Width;
                    if (width > originalBitmap.Width)
                        width = originalBitmap.Width;
                    var height = image.Height ?? originalBitmap.Height;
                    if (height > originalBitmap.Height)
                        height = originalBitmap.Height;
                    var x = image.XOffset.Offset < 0 ? Math.Abs(image.XOffset.Offset) : 0;
                    var y = image.YOffset.Offset < 0 ? Math.Abs(image.YOffset.Offset) : 0;

                    writer.WriteImage(originalBitmap.Clone(new Rectangle(x, y, width, height), originalBitmap.PixelFormat));
                    bitmap = writer.SpriteImage;
                    if ((originalBitmap.Width * originalBitmap.Height) > (bitmap.Width * bitmap.Height))
                        Size += writer.GetBytes("image/png").Length;
                    else
                        Size += imageBytes.Length;
                }
            }
            images.Add(bitmap);
            Width += bitmap.Width;
            if (Height < bitmap.Height) Height = bitmap.Height;
        }
        public override Bitmap RealizarTrabalho(Bitmap imagem)
        {
            Bitmap final;
            Bitmap processamento = new Bitmap((Image)imagem.Clone());

			/* Verifica-se todos os pixels da imagem, eliminando
			* as cores de fundo
			*/
            for (int y = 0; y < processamento.Height && !cancelado; y+= 1)
				for (int x = 0; x < processamento.Width && !cancelado; x+= 1)
				{
					Color cor = processamento.GetPixel(x, y);
                    Color fundo = this.fundo.GetPixel(x, y);
                    float diferença;

                    diferença = (Math.Abs(cor.R - fundo.R)
                        + Math.Abs(cor.G - fundo.G)
                        + Math.Abs(cor.B - fundo.B)) / 3f;

                    if (diferença <= tolerância)
						processamento.SetPixel(x, y, Color.FromArgb(0, cor));
				}

            if (cancelado)
                return null;

			// Suavizar transparência
            final = SuavizarTransparência(processamento);
			
            final.Tag = imagem.Clone();

			return final;
        }
Example #3
0
        public HandMask( Bitmap Otsu)
        {
            //resmin kendisi

               // this.img = (Bitmap)bmp.Clone();

            _LOCK = new object();

            bmp1 = (Bitmap)Otsu.Clone();
            bmp2 = (Bitmap)Otsu.Clone();
            bmp3 = (Bitmap)Otsu.Clone();
            bmp4 = (Bitmap)Otsu.Clone();

            LeftHis = new int[Otsu.Width];
            RightHis = new int[Otsu.Width];
            DownHis = new int[Otsu.Height];
            UpHis = new int[Otsu.Height];

            Koordinat = new int[4];

            Array.Clear(LeftHis, 0, LeftHis.Length);
            Array.Clear(DownHis, 0, DownHis.Length);
            Array.Clear(RightHis, 0, RightHis.Length);
            Array.Clear(UpHis, 0, UpHis.Length);

            setoff_bilek = Otsu.Width / 20;
            setoff_y = Otsu.Height / 100;
            setoff_x = Otsu.Width / 100;
        }
        protected void btn_submit_Click(object sender, EventArgs e)
        {
            org = System.Drawing.Image.FromStream(fileUpload_Steg.PostedFile.InputStream);
            OriginalImage = (Bitmap)org;

            // Copy the original message.
            EncodedImage = (Bitmap)OriginalImage.Clone();
            MarkedImage = (Bitmap)OriginalImage.Clone();

            // Encode.
            try
            {
                string fileName = fileUpload_Steg.PostedFile.FileName;
                EncodeMessageInImage(EncodedImage, MarkedImage,
                    tb_pw.Text, tb_textToHide.Text);

                afterEncode = (System.Drawing.Image)EncodedImage;
                afterEncode.Save(Path.Combine(Server.MapPath(null), fileName));

                fileName = Path.Combine(Server.MapPath(null), fileName);
                //string fileName = img_userImage.ImageUrl;

                Response.ContentType = "image/JPEG";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + "watermarked_" + fileName.Remove(0, 15));

                Response.TransmitFile(fileName);
                Response.End();

            }
            catch (Exception ex)
            {

            }
        }
 public frmGrayscalePreview(Bitmap image)
 {
     InitializeComponent();
     pbxOrg.Image = (Bitmap)image.Clone();
     pbxPreview.Image = (Bitmap)image.Clone();
     libImage.GrayScale((Bitmap)pbxPreview.Image);
 }
Example #6
0
        public void Process(Bitmap fullScreenshot)
        {
            Mode mode = Form.CurrentMode;
            Bitmap field = fullScreenshot.Clone(mode.GetField(), fullScreenshot.PixelFormat);
            if (Form.CurrentMode.GetType() == typeof(DiamondMine))
            {
                Bitmap cleared = fullScreenshot.Clone(new Rectangle(582, 788, 875, 6), fullScreenshot.PixelFormat);
                Color averageColor = Histograms.GetAverageColor(cleared);
                if (averageColor.R >= 200 && averageColor.G >= 200)
                {
                    DiamondMineCleared = true;
                    DiamondMineLastCleared = DateTime.Now;
                }
                else
                {
                    if (DiamondMineLastCleared.AddSeconds(1) < DateTime.Now)
                    {
                        DiamondMineCleared = false;
                    }
                }
                cleared.Dispose();
            }
            
            
            // Update Grid from image
            for (int x = 0; x < 8; x++)
            {
                for (int y= 0;y <8;y++)
                {
                    Bitmap thisGem = field.Clone(new Rectangle(x * 112, y * 112, 112, 112), field.PixelFormat);
                    Grid[x, y] = new Gem(GemColor.Unrecognized, thisGem, x, y);
                }
            }

            // Recognize
            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    Grid[x, y].GemColor = Form.RecognitionStrategy.GetColor(Grid[x, y]);
                }
            }

            // Find options
            Predictor.Predict(Grid);

            // Update Field Image
            if (Form.pictureBoxField.Image != null)
            {
                Form.pictureBoxField.Image.Dispose();
            }
            Form.pictureBoxField.Image = field;
            // Update Grid based on Grid
            Action a = () =>
            {
                Form.pictureBoxGrid.Refresh();
            };
            Form.pictureBoxGrid.Invoke(a);
            
        }
Example #7
0
 public unsafe Bitmap GenerateGrayScale(Bitmap src_bmp, float type)
 {
     try
     {
         frames = int.Parse(Settings.SettingsCache.getConfig("RefreshDelay"));
     }
     catch (Exception ex)
     {
         Environment.Exit(ex.GetHashCode());
     }
     Bitmap dst_bmp = new Bitmap(src_bmp);
     UpdateStatus(0, (Bitmap)dst_bmp.Clone());
     for (int y = 0; y < dst_bmp.Height; y++) {
         delay++;
         if (delay >= frames)
         {
             UpdateStatus((y * 100) / dst_bmp.Height, (Bitmap)dst_bmp.Clone());
             delay = 0;
         }
         else
         {
             UpdateStatus((y * 100) / dst_bmp.Height, null);
         }
         for (int x = 0; x < dst_bmp.Width; x++)
         {
             Color c = dst_bmp.GetPixel(x, y);
             int rgb = (int)((c.R + c.G + c.B) / 3);
             dst_bmp.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb));
         }
     }
     UpdateStatus(100, (Bitmap)dst_bmp.Clone());
     return dst_bmp;
 }
 public static Bitmap copyPartOfBitmap(Bitmap bmp, Rectangle cloneRect)
 {
     System.Drawing.Imaging.PixelFormat format = bmp.PixelFormat;
     Bitmap result;
     if (cloneRect.Width <= 0 || cloneRect.Height <= 0)
         result = (Bitmap)bmp.Clone();
     else
         result = bmp.Clone(cloneRect, format);
     return result;
 }
Example #9
0
        private void buttonOpenImage_Click(object sender, EventArgs e)
        {
            var dialogResult = _openFileDialog.ShowDialog();
            if (dialogResult == DialogResult.OK)
            {
                var image = new Bitmap(_openFileDialog.FileName);
                _pictureBox.Image = image.Clone() as Image;

                _sourceImage = image.Clone() as Bitmap;
                buttonHistogram.Enabled = true;
            }
        }
Example #10
0
        public Bitmap Apply(Bitmap original)
        {
            GrayscaleEffect.Grasycale gray = new GrayscaleEffect.Grasycale();
            if (!notGray) original = gray.Apply(original);

            FilterProcessor processor = new FilterProcessor();

            processor.SetMatrix(new double[][] { new double[] { 1, 2, 1 }, new double[] { 0, 0, 0 }, new double[] { -1, -2, -1 } });
            Bitmap Gx = processor.Process((Bitmap)original.Clone());

            processor.SetMatrix(new double[][] { new double[] { 1, 0, -1 }, new double[] { 2, 0, -2 }, new double[] { 1, 0, -1 } });
            Bitmap Gy = processor.Process((Bitmap)original.Clone());

            Rectangle rect = new Rectangle(0, 0, original.Width, original.Height);

            #region Initialization
            System.Drawing.Imaging.BitmapData bmpDataX = Gx.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            IntPtr ptrX = bmpDataX.Scan0;
            int bytesX = Math.Abs(bmpDataX.Stride) * bmpDataX.Height;
            byte[] valuesGx = new byte[bytesX];
            System.Runtime.InteropServices.Marshal.Copy(ptrX, valuesGx, 0, bytesX);
            Gx.UnlockBits(bmpDataX);

            System.Drawing.Imaging.BitmapData bmpDataY = Gy.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            IntPtr ptrY = bmpDataY.Scan0;
            int bytesY = Math.Abs(bmpDataY.Stride) * bmpDataY.Height;
            byte[] valuesGy = new byte[bytesY];
            System.Runtime.InteropServices.Marshal.Copy(ptrY, valuesGy, 0, bytesY);
            Gy.UnlockBits(bmpDataY);

            System.Drawing.Imaging.BitmapData bmpData = original.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            IntPtr ptr = bmpData.Scan0;
            int bytes = Math.Abs(bmpData.Stride) * bmpData.Height;
            byte[] values = new byte[bytes];
            System.Runtime.InteropServices.Marshal.Copy(ptr, values, 0, bytes);
            #endregion

            for (int i = 0; i < values.Length; i += 3)
            {
                if (i + 2 >= values.Length) break;
                double r = Math.Sqrt((double)valuesGx[i + 2] * (double)valuesGx[i + 2] + (double)valuesGy[i + 2] * (double)valuesGy[i + 2]);
                double g = Math.Sqrt((double)valuesGx[i + 1] * (double)valuesGx[i + 1] + (double)valuesGy[i + 1] * (double)valuesGy[i + 1]);
                double b = Math.Sqrt((double)valuesGx[i + 0] * (double)valuesGx[i + 0] + (double)valuesGy[i + 0] * (double)valuesGy[i + 0]);
                values[i + 0] = (byte)(r / Math.Sqrt(2));
                values[i + 1] = (byte)(g / Math.Sqrt(2));
                values[i + 2] = (byte)(b / Math.Sqrt(2));
            }

            System.Runtime.InteropServices.Marshal.Copy(values, 0, ptr, bytes);
            original.UnlockBits(bmpData);
            return original;
        }
        private static List<Bitmap> SeparateNumbersWithWhiteColumnsAsDelimiter(Bitmap img, List<Tuple<bool, int>> whiteColumns)
        {
            List<Bitmap> result = new List<Bitmap>
            {
                img.Clone(Rectangle.FromLTRB(0, 0, whiteColumns[1].Item2, img.Height), img.PixelFormat)
            };

            for (int i = 1; i < whiteColumns.Count - 1; i++)
            {
                result.Add(img.Clone(Rectangle.FromLTRB(whiteColumns[i].Item2, 0, whiteColumns[i + 1].Item2, img.Height),
                    img.PixelFormat));
            }
            return result;
        }
Example #12
0
 private void Form1_MouseUp(object sender, MouseEventArgs e)
 {
     Image i1 = Properties.Resources.background;
     Bitmap bmp = new Bitmap(Properties.Resources.cha);
     Rectangle r = new Rectangle(0,0, 64,64);
     Rectangle r2 = new Rectangle(64, 0, 64, 64);
     Bitmap bmp2 = bmp.Clone(r, bmp.PixelFormat);
     Bitmap bmp3 = bmp.Clone(r2, bmp.PixelFormat);
     Graphics g = this.CreateGraphics();
     g.DrawImage(i1, 0, 0);
     g.DrawImage(bmp2, Width/2, Height/2);
     g.DrawImage(bmp3, Width / 2 +100, Height / 2);
     g.Dispose();
 }
        /// <summary>
        /// Crops the specified raw image.
        /// </summary>
        /// <param name="rawImage">The raw image.</param>
        /// <param name="topLeft">The top left.</param>
        /// <param name="newSize">The new size.</param>
        /// <returns>Image.</returns>
        public Image Crop(Image rawImage, Point topLeft, Size newSize)
        {
            try
            {
                if (rawImage.Width < (topLeft.X + newSize.Width))
                {
                    newSize.Width = rawImage.Width - topLeft.X;
                }

                if (rawImage.Height < (topLeft.Y + newSize.Height))
                {
                    newSize.Height = rawImage.Height - topLeft.Y;
                }

                Bitmap clippedImage = new Bitmap(rawImage);

                clippedImage = clippedImage.Clone(new Rectangle(topLeft.X, topLeft.Y, newSize.Width, newSize.Height),
                    rawImage.PixelFormat);

                return clippedImage;
            }
            catch (Exception ex)
            {
                return new Bitmap(ImageFactory.Draw(ex.Message));
            }
        }
Example #14
0
 public static Image CropImage(Image img, Rectangle cropArea)
 {
     Bitmap bmpImage = new Bitmap(img);
     Bitmap bmpCrop = bmpImage.Clone(cropArea,
     bmpImage.PixelFormat);
     return (Image)(bmpCrop);
 }
Example #15
0
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            int fileCount = files.Count();
            if( fileCount > 6 )
            {
                fileCount = 6;
            }
            Bitmap henseiBitmap = new Bitmap(488 * 2, 376 * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Graphics henseiGraphics = Graphics.FromImage(henseiBitmap);

            List<String> fl = LoadFilePath(files);
            fl.Sort();
            for (int i = 0; i < fileCount; i++)
            {
                Console.WriteLine(fl[i]);
                Bitmap orig = new Bitmap(fl[i].ToString());
                Bitmap copy = orig.Clone(new Rectangle(312, 94, 488, 376), orig.PixelFormat);
                henseiGraphics.DrawImage(copy, henseiPosition[i, 0], henseiPosition[i, 1], copy.Width, copy.Height);
                orig.Dispose();

            }
            henseiGraphics.Dispose();
            String outPath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "hensei.png");
            henseiBitmap.Save(outPath);
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(outPath);
        }
Example #16
0
 public static void LoadSprites()
 {
     SpriteList.Clear();
     Stream stream;
     if (File.Exists("sprites.png"))
     {
         stream = File.OpenRead("sprites.png");
     }
     else
     {
         var assembly = Assembly.GetExecutingAssembly();
         stream = assembly.GetManifestResourceStream("scmpoo.resources.sprites.png");
     }
     Bitmap loadedfile = new Bitmap(Image.FromStream(stream));
     int count = loadedfile.Width / loadedfile.Height;
     for (int n = 0; n < count; n++)
     {
         SpriteList.Add(loadedfile.Clone(new Rectangle(n * loadedfile.Height, 0, loadedfile.Height, loadedfile.Height), loadedfile.PixelFormat));
     }
     for (int n = 0; n < count; n++)
     {
         Bitmap b = (Bitmap)SpriteList[n].Clone();
         b.RotateFlip(RotateFlipType.RotateNoneFlipX);
         SpriteList.Add(b);
     }
 }
Example #17
0
        public List<double[]> extract(Bitmap image, string detector)
        {
            SCD_Descriptor scdLocal = new SCD_Descriptor();
            Bitmap bmpImage = new Bitmap(image);

            createPoints pointsCreator = new createPoints();
            List<Keypoint> keypointsList = null;
            if (detector == "SURF")
                keypointsList = pointsCreator.usingSurf(image);
            else if (detector == "SIFT")
                keypointsList = pointsCreator.usingSift(image);
            else
                throw new Exception("Cannot recognize Detector");

            #region SCD_Local
            Rectangle cloneRect;
            Bitmap bmpCrop;
            double[] scdDescriptor = new double[256];
            List<double[]> tilesDescriptors = new List<double[]>();

            foreach (Keypoint myKeypoint in keypointsList)
            {
                cloneRect = new Rectangle((int)(myKeypoint.X - (int)myKeypoint.Size / 2), (int)(myKeypoint.Y - (int)myKeypoint.Size / 2), (int)myKeypoint.Size, (int)myKeypoint.Size);
                bmpCrop = new Bitmap(bmpImage.Clone(cloneRect, bmpImage.PixelFormat));

                scdLocal.Apply(new Bitmap(bmpCrop), 256, 0);
                scdDescriptor = scdLocal.Norm4BitHistogram;
                tilesDescriptors.Add(scdDescriptor);
            }
            #endregion

            return tilesDescriptors;
        }
Example #18
0
        public Stroke(Bitmap bitmap,Color color,float a,float b,float c,float soft,bool flat,bool square)
        {
            //Create shape
            shape=(Bitmap)bitmap.Clone();
            for(int i=0;i<shape.Width;i++)
            {
                for(int j=0;j<shape.Height;j++)
                {
                    float x=(float)(i-shape.Width/2);
                    float y=(float)(j-shape.Height/2);
                    float len2=x*x+y*y;
                    float r=Math.Min(shape.Width/2,shape.Height/2);
                    float r2=r*r;
                    if(square||len2<=r2)
                    {
                        Color col=shape.GetPixel(i,j);
                        float ii=(((float)(col.R+col.G+col.B))/3f)/255f;
                        int aa=(int)(((a*ii*ii+b*ii+c)*(((float)color.A)/255f)*255f));
                        if(aa<0)
                            aa=0;
                        if(aa>255)
                            aa=255;
                        float sa=1f;
                        if(soft>0f)
                        {
                            sa=1f-(len2/r2)*soft;
                            if(sa<0f)
                                sa=0f;
                            if(sa>1f)
                                sa=1f;
                        }
                        if(flat)
                            shape.SetPixel(i,j,Color.FromArgb((int)(((float)aa)*sa),color));
                        else
                        {
                            Color cc=shape.GetPixel(i,j);
                            int rr=(int)((((float)cc.R)/255f)*(((float)color.R)/255f)*255f);
                            if(rr<0)
                                rr=0;
                            if(rr>255)
                                rr=255;
                            int gg=(int)((((float)cc.G)/255f)*(((float)color.G)/255f)*255f);
                            if(gg<0)
                                gg=0;
                            if(gg>255)
                                gg=255;
                            int bb=(int)((((float)cc.B)/255f)*(((float)color.B)/255f)*255f);
                            if(bb<0)
                                bb=0;
                            if(bb>255)
                                bb=255;
                            shape.SetPixel(i,j,Color.FromArgb((int)(((float)aa)*sa),rr,gg,bb));
                        }

                    }
                    else
                        shape.SetPixel(i,j,Color.FromArgb(0,0,0,0));
                }
            }
        }
Example #19
0
        /// <summary>
        /// Crop an image in the given rectangle.
        /// </summary>
        /// <param name="img"></param>
        /// <param name="cropArea"></param>
        /// <returns></returns>
        public static Image Crop(Image image, Rectangle cropArea)
        {
            Bitmap bmpImage = new Bitmap(image);
            Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);

            return bmpCrop;
        }
Example #20
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Открываем файл картинки...
                System.IO.FileStream fs = new System.IO.FileStream(openFileDialog1.FileName, System.IO.FileMode.Open);
                System.Drawing.Image img = System.Drawing.Image.FromStream(fs);
                fs.Close();
                //Помещаем исходное изображение в PictureBox1
                pictureBox1.Image = img;

                var bmp = new Bitmap(img);
                label1.Text = "";
                label1.Text = label1.Text + DateTime.Now.Second.ToString() + "." + DateTime.Now.Millisecond.ToString() + " - "; //Время начала обработки (секунды и миллисекунды).
                //Преобразуем картинку
                MakeGray(bmp);
                //Crop(bmp, new Rectangle(0, 0, bmp.Height, bmp.Width));
                Bitmap cropBmp = bmp.Clone(new Rectangle(0, 0, bmp.Width / 2, bmp.Height / 2), bmp.PixelFormat);
                label1.Text = label1.Text + DateTime.Now.Second.ToString() + "." + DateTime.Now.Millisecond.ToString(); //Время окончания обработки (секунды и миллисекунды).
                //Помещаем преобразованное изображение в PictureBox2
                pictureBox2.Image = cropBmp;
                Bitmap cropcloneBmp = cropBmp.Clone(new Rectangle(0, 0, cropBmp.Width, cropBmp.Height), cropBmp.PixelFormat);
                MakeGray(cropcloneBmp);
                //Crop(bmp, new Rectangle(0, 0, bmp.Height, bmp.Width));
                Bitmap cropnewBmp = cropcloneBmp.Clone(new Rectangle(0, 0, cropcloneBmp.Width / 2, cropcloneBmp.Height / 2), cropcloneBmp.PixelFormat);
                label1.Text = label1.Text + DateTime.Now.Second.ToString() + "." + DateTime.Now.Millisecond.ToString(); //Время окончания обработки (секунды и миллисекунды).
                //Помещаем преобразованное изображение в PictureBox2
                pictureBox3.Image = cropnewBmp;
            }

        }
Example #21
0
 private static Image AmazonCut(Image image)
 {
     if (image.Width != image.Height)
         return image;
     var bmp = new Bitmap(image);
     int size = image.Height;
     int white = System.Drawing.Color.FromKnownColor(KnownColor.White).ToArgb();
     int i = 0;
     while (i < size/2)
     {
         if (bmp.GetPixel(i, i).ToArgb() != white)
             break;
         if (bmp.GetPixel(i, size - 1 - i).ToArgb() != white)
             break;
         if (bmp.GetPixel(size - 1 - i, i).ToArgb() != white)
             break;
         if (bmp.GetPixel(size - 1 - i, size - 1 - i).ToArgb() != white)
             break;
         i++;
     }
     if (i > 0)
     {
         i += 8;
         var zone = new Rectangle(i, i, size - 2*i, size - 2*i);
         return bmp.Clone(zone, System.Drawing.Imaging.PixelFormat.DontCare);
     }
     return bmp;
 }
Example #22
0
        public void Crop()
        {
            Bitmap image = new Bitmap(_image.Image.InputStream);

            Rectangle cropArea = new Rectangle();
            cropArea.X = _x;
            cropArea.Y = _y;
            cropArea.Width = _width;
            cropArea.Height = _height;

            Bitmap newImage = image.Clone(cropArea, image.PixelFormat);

            //Create unique name for new image
            string path = @"C:\Images\ProfilePictures\";
            Guid fileName = Guid.NewGuid();

            ImageUrl = path + fileName + ".jpg";

            if (!Directory.Exists(path))
	        {
		        Directory.CreateDirectory(path);
                newImage.Save(path + fileName + ".jpg", ImageFormat.Jpeg);
	        }
            else
            {
                newImage.Save(path + fileName + ".jpg", ImageFormat.Jpeg);
            }            
        }   
Example #23
0
        public static GameData.Image GetImage(string imageValue)
        {
            try
            {
                string[] cloumns = imageValue.Split(':');
                if (cloumns.Length != 2)
                    return null;

                string imagesetName = cloumns[0];
                string imageName = cloumns[1];

                Imageset imageset = ImagesetManager.Instance.Get(imagesetName);
                if (imageset == null)
                    return null;

                GameData.Image image = imageset.Get(imageName);
                if (image.Tag == null)
                {
                    System.Drawing.Image texture = System.Drawing.Image.FromFile(imageset.FileName);
                    Bitmap srcBitmap = new Bitmap(texture);

                    Rectangle rect = new Rectangle(image.X, image.Y, image.Width, image.Height);
                    image.Tag = srcBitmap.Clone(rect, srcBitmap.PixelFormat);
                }

                return image;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }
Example #24
0
        WaveGenerator wave; // The decrypted audio file.

        #endregion Fields

        #region Constructors

        public Encrypted(Bitmap encryptedImage)
        {
            InitializeComponent();
            fileName = "";

            // Convert pixel format
            encryptedImage = encryptedImage.Clone(new Rectangle(0, 0, encryptedImage.Width, encryptedImage.Height), PixelFormat.Format32bppArgb);

            encryptedImageBox.Image = encryptedImage;
            encryptedImageBox.Size = encryptedImage.Size;

            // Resize window
            int newWidth = Math.Max(this.PreferredSize.Width, 305);
            int newHeight = this.PreferredSize.Height;
            newWidth = Math.Min(newWidth, Screen.PrimaryScreen.Bounds.Width * 2 / 3);
            newHeight = Math.Min(newHeight, Screen.PrimaryScreen.Bounds.Height * 2 / 3);
            this.Size = new Size(newWidth, newHeight);

            // Enable buttons
            foreach (Control c in this.Controls)
            {
                if (c is Button)
                    c.Enabled = true;
            }
        }
Example #25
0
        public void UpdateImage(Bitmap bmp, bool cloneBitmap = false)
        {
            try
            {
                CountFps();
                picDesktop.Invoke((MethodInvoker) delegate
                {
                    // get old image to dispose it correctly
                    var oldImage = picDesktop.Image;

                    picDesktop.Image = cloneBitmap ? (Bitmap) bmp.Clone() : bmp;

                    if (oldImage != null)
                        oldImage.Dispose();
                });
            }
            catch (InvalidOperationException)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format(
                        "An unexpected error occurred: {0}\n\nPlease report this as fast as possible here:\\https://github.com/MaxXor/xRAT/issues",
                        ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #26
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap b = new Bitmap(Width, Height);
            Graphics g = Graphics.FromImage(b);

            g.Clear(Color.Gainsboro);

            for (int i = 0; i < this.TabCount; i++)
            {
                Rectangle tabRect = GetTabRect(i);
                if (i == this.SelectedIndex)
                {
                    g.FillRectangle(Brushes.Red, tabRect);
                }
                else
                {
                    g.FillRectangle(Brushes.AliceBlue, tabRect);
                }

                g.DrawString(this.TabPages[i].Text, this.Font, Brushes.White, tabRect, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
            }

            e.Graphics.DrawImage((Bitmap)b.Clone(), 0, 0);

            g.Dispose();
            b.Dispose();
            base.OnPaint(e);
        }
Example #27
0
 public Card(string frontFilename, string backFilename)
 {
     Front = new Bitmap(frontFilename);
     Back = new Bitmap(backFilename);
     FrontOriginal = (Bitmap)Front.Clone();
     BackOriginal = (Bitmap)Back.Clone();
 }
        public void Crop()
        {
            try
            {
                Bitmap postedImage = new Bitmap(_image.InputStream);

                Rectangle cropArea = new Rectangle { X = _x, Y = _y, Width = _width, Height = _height };

                Bitmap newCroppedImage = postedImage.Clone(cropArea, postedImage.PixelFormat);

                Guid fileName = Guid.NewGuid();

                ImageUrl = fileName + ".jpg";

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                    newCroppedImage.Save(path + fileName + ".jpg", ImageFormat.Jpeg);
                }
                else
                {
                    newCroppedImage.Save(path + fileName + ".jpg", ImageFormat.Jpeg);
                }
            }
            catch (OutOfMemoryException ex)
            {
                throw new OutOfMemoryException("Crazy Error", ex);
            }
            
        }
Example #29
0
        public void getScreenshots()
        {
            List<Image> screenshots = new List<Image>();
            for (int i = 0; i < Screen.AllScreens.Length; i++)
            {
                Screen screen = Screen.AllScreens[i];
                using (Bitmap bmpScreenCapture = new Bitmap(screen.Bounds.Width,
                                                screen.Bounds.Height))
                {
                    using (Graphics g = Graphics.FromImage(bmpScreenCapture))
                    {
                        g.CopyFromScreen(screen.Bounds.X,
                                         screen.Bounds.Y,
                                         0, 0,
                                         bmpScreenCapture.Size,
                                         CopyPixelOperation.SourceCopy);
                    }
                    screenshots.Add((Image)bmpScreenCapture.Clone());
                }
            }

            for (int i = 0; i < pictureboxes.Count; i++)
            {
                pictureboxes[i].Image = screenshots[i];
            }
        }
Example #30
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            this.buttonSend.Enabled = false;
            IList<byte[]> imageSlices = new List<byte[]>();
            Bitmap bmp = new Bitmap(this._imageSource);
            double width = (double)bmp.Width / 5;
            double height = (double)bmp.Height / 5;
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    Rectangle rect = new Rectangle(Convert.ToInt32(x * width), Convert.ToInt32(y * height),
                        Convert.ToInt32(width), Convert.ToInt32(height));

                    byte[] data = BitmapToBytes(bmp.Clone(rect, PixelFormat.DontCare));
                    imageSlices.Add(data);
                }
            }

            IImageTransfer proxy = GetProxy();
            proxy.Erase();
            for (int i = 0; i < imageSlices.Count; i++)
            {
                proxy.Transfer(imageSlices[i]);
            }
            this.buttonSend.Enabled = true;
        }