当前位置: 首页>>代码示例>>C#>>正文


C# Bitmap.Clone方法代码示例

本文整理汇总了C#中System.Drawing.Bitmap.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.Clone方法的具体用法?C# Bitmap.Clone怎么用?C# Bitmap.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Bitmap的用法示例。


在下文中一共展示了Bitmap.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddImage

        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;
        }
开发者ID:colintho,项目名称:RequestReduce,代码行数:29,代码来源:SpriteContainer.cs

示例2: RealizarTrabalho

        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;
        }
开发者ID:andrepontesmelo,项目名称:imjoias,代码行数:33,代码来源:TratamentoRemoverFundoComparando.cs

示例3: HandMask

        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;
        }
开发者ID:SukriyeAkkaya,项目名称:HandMove,代码行数:29,代码来源:HandMask.cs

示例4: btn_submit_Click

        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)
            {

            }
        }
开发者ID:shareen1412,项目名称:GitHubVS2013_ISSECS,代码行数:34,代码来源:SteganographyText.aspx.cs

示例5: frmGrayscalePreview

 public frmGrayscalePreview(Bitmap image)
 {
     InitializeComponent();
     pbxOrg.Image = (Bitmap)image.Clone();
     pbxPreview.Image = (Bitmap)image.Clone();
     libImage.GrayScale((Bitmap)pbxPreview.Image);
 }
开发者ID:helenclarko,项目名称:labelcreator,代码行数:7,代码来源:frmGrayscalePreview.cs

示例6: Process

        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);
            
        }
开发者ID:Soothsilver,项目名称:megajewel,代码行数:60,代码来源:Processing.cs

示例7: GenerateGrayScale

 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;
 }
开发者ID:jpdante,项目名称:TextureMap-Pro,代码行数:33,代码来源:GrayScale.cs

示例8: copyPartOfBitmap

 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;
 }
开发者ID:npwolfeg,项目名称:HandwrittingRecognition,代码行数:10,代码来源:BmpProcesser.cs

示例9: buttonOpenImage_Click

        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;
            }
        }
开发者ID:vitiaaap29,项目名称:TextRecognition,代码行数:12,代码来源:MainForm.cs

示例10: Apply

        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;
        }
开发者ID:rombolshak,项目名称:Gredactor,代码行数:52,代码来源:SobelFilter.cs

示例11: SeparateNumbersWithWhiteColumnsAsDelimiter

        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;
        }
开发者ID:MPeloquin,项目名称:NMZPointsPerHour,代码行数:14,代码来源:OpticalNumberSeparator.cs

示例12: Form1_MouseUp

 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();
 }
开发者ID:honux77,项目名称:prostar,代码行数:14,代码来源:Form1.cs

示例13: Crop

        /// <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));
            }
        }
开发者ID:kindredagency,项目名称:Imaging,代码行数:33,代码来源:ImageManipulation.cs

示例14: CropImage

 public static Image CropImage(Image img, Rectangle cropArea)
 {
     Bitmap bmpImage = new Bitmap(img);
     Bitmap bmpCrop = bmpImage.Clone(cropArea,
     bmpImage.PixelFormat);
     return (Image)(bmpCrop);
 }
开发者ID:jmlsmn,项目名称:theShirtOff,代码行数:7,代码来源:ImageUtilities.cs

示例15: Form1_DragDrop

        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);
        }
开发者ID:miwarin,项目名称:kancolle-hensei,代码行数:27,代码来源:Form1.cs


注:本文中的System.Drawing.Bitmap.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。