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


C# System.Drawing.Bitmap.Clone方法代码示例

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


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

示例1: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            // Create an instance of the open file dialog box.
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog1.Filter = "All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;

            openFileDialog1.Multiselect = true;

            // Call the ShowDialog method to show the dialog box.
            bool? userClickedOK = openFileDialog1.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == true)
            {
                AllocConsole();
                //Run alg

                Console.WriteLine("Load original...");
                System.Drawing.Bitmap org = new System.Drawing.Bitmap(openFileDialog1.FileName);
                Original = org.Clone(new System.Drawing.Rectangle(0, 0, org.Width, org.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                //Convert to grayscale
                Console.WriteLine("Convert original to grayscale");
                for (int i = 0; i < Original.Width; i++)
                {
                    for (int x = 0; x < Original.Height; x++)
                    {
                        System.Drawing.Color oc = Original.GetPixel(i, x);
                        int grayScale = (int)((oc.R * 0.3) + (oc.G * 0.59) + (oc.B * 0.11));
                        System.Drawing.Color nc = System.Drawing.Color.FromArgb(oc.A, grayScale, grayScale, grayScale);
                        Original.SetPixel(i, x, nc);
                    }
                }

                PerformAlgorithm();

                this.ImgOrg.Source = BitmapToImageSource(Original);
               // FreeConsole();
            }
            else
            {
                this.Close();
            }
        }
开发者ID:Lowhuhn,项目名称:LaserControl,代码行数:48,代码来源:MainWindow.xaml.cs

示例2: Refresh

        public void Refresh(TileSheet tileSheet)
        {
            try
            {
                System.Drawing.Bitmap tileSheetBitmap = null;

                // copy bitmap in memory, otherwise Clone() method forces
                // a reload of the image on every call!
                using (System.Drawing.Bitmap tileSheetBitmapDisk
                    = new System.Drawing.Bitmap(tileSheet.ImageSource))
                {
                    tileSheetBitmap = new System.Drawing.Bitmap(tileSheetBitmapDisk);
                }

                int tileCount = tileSheet.TileCount;
                System.Drawing.Bitmap[] tileBitmaps = new System.Drawing.Bitmap[tileCount];
                Size tileSize = tileSheet.TileSize;

                System.Drawing.Rectangle destRect
                    = new System.Drawing.Rectangle(0, 0, tileSize.Width, tileSize.Height);

                System.Drawing.Rectangle srcRect
                    = new System.Drawing.Rectangle(destRect.Location, destRect.Size);

                for (int tileIndex = 0; tileIndex < tileCount; tileIndex++)
                {
                    Rectangle tileRectangle = tileSheet.GetTileImageBounds(tileIndex);
                    srcRect.X = tileRectangle.Location.X;
                    srcRect.Y = tileRectangle.Location.Y;
                    srcRect.Width = tileRectangle.Size.Width;
                    srcRect.Height = tileRectangle.Size.Height;

                    System.Drawing.Bitmap tileBitmap = tileSheetBitmap.Clone(
                         srcRect, tileSheetBitmap.PixelFormat);

                    tileBitmaps[tileIndex] = tileBitmap;
                }

                m_bitmapCache[tileSheet] = tileBitmaps;
            }
            catch (Exception innerException)
            {
                Exception exception = new Exception(
                    "Unable to load tile sheet '" + tileSheet.Id + "' with image source '" + tileSheet.ImageSource + "'",
                    innerException);
                throw exception;
            }
        }
开发者ID:dekk7,项目名称:xEngine,代码行数:48,代码来源:TileImageCache.cs

示例3: DoEffect


//.........这里部分代码省略.........
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);
                                byte gray = (byte)(.299 * c.R + .587 * c.G + .114 * c.B);
                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, gray, 0, gray));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.SNOW: //Snow
                    {
                        double density = parameter;
                        if (density <= 0) density = pEffect[(int)_effect];
                        Random rand = new Random();
                        System.Drawing.Color c;
                        int i, j;
                        FastPixel fp = new FastPixel(bmap);
                        for (int ii = 0; ii < fp.Width * fp.Height / density; ii++)
                        {
                            i = rand.Next(fp.Width);
                            j = rand.Next(fp.Height);
                            c = fp.GetPixel(i, j);
                            fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, 255, 255, 255));
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.FUZZY: //Fuzzy
                    {
                        Random rand = new Random();
                        System.Drawing.Color c;
                        System.Drawing.Bitmap copy = (System.Drawing.Bitmap)bmap.Clone();
                        FastPixel fpCopy = new FastPixel(copy);
                        int ii, jj;
                        int x = parameter;
                        if (x <= 0) x = pEffect[(int)_effect];
                        int y = 2 * x + 1;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                ii = System.Math.Max(0, System.Math.Min(fp.Width - 1, i + rand.Next(y) - x));
                                jj = System.Math.Max(0, System.Math.Min(fp.Height - 1, j + rand.Next(y) - x));
                                c = fpCopy.GetPixel(ii, jj);
                                fp.SetPixel(i, j, c);
                            }
                        }
                        fpCopy.Unlock(false);
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.CONTRAST: //Contrast
                    {
                        double contrast = parameter;
                        if (contrast <= 0) contrast = pEffect[(int)_effect];
                        System.Drawing.Color c;
                        double R, G, B;

                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
开发者ID:litdev1,项目名称:LitDev,代码行数:67,代码来源:WebCam.cs

示例4: AddAnimatedImage

        /// <summary>
        /// Creates an animation from a single image with multiple images on one layer.  
        /// Do not add a very large number of these or performance may be degraded.
        /// </summary>
        /// <param name="imageName">
        /// The image file (local or network) to load.
        /// Can also be an ImageList image.
        /// </param>
        /// <param name="repeat">
        /// Continuously repeat the animation "True" or "False".
        /// </param>
        /// <param name="countX">
        /// The number of sub-images in the X direction.
        /// </param>
        /// <param name="countY">
        /// The number of sub-images in the Y direction.
        /// </param>
        /// <returns>
        /// The animated shape name.
        /// </returns>
        public static Primitive AddAnimatedImage(Primitive imageName, Primitive repeat, Primitive countX, Primitive countY)
        {
            GraphicsWindow.Show();
            Type ShapesType = typeof(Shapes);
            Type ImageListType = typeof(ImageList);
            Dictionary<string, BitmapSource> _savedImages;
            BitmapSource img;
            Canvas _mainCanvas;
            string shapeName;

            try
            {
                _savedImages = (Dictionary<string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_savedImages.TryGetValue((string)imageName, out img))
                {
                    imageName = ImageList.LoadImage(imageName);
                    if (!_savedImages.TryGetValue((string)imageName, out img))
                    {
                        return "";
                    }
                }

                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "Image" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        //System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imageName);
                        System.Drawing.Bitmap bitmap;
                        using (MemoryStream outStream = new MemoryStream())
                        {
                            BitmapEncoder enc = new PngBitmapEncoder();
                            enc.Frames.Add(BitmapFrame.Create(img));
                            enc.Save(outStream);
                            bitmap = new System.Drawing.Bitmap(outStream);
                        }

                        int frameCount = countX * countY;

                        if (frameCount > 1)
                        {
                            Animated anim = new Animated();
                            animated.Add(anim);
                            anim.name = shapeName;
                            anim.frames = new Frame[frameCount];
                            anim.repeat = repeat;

                            int w = bitmap.Width / countX;
                            int h = bitmap.Height / countY;

                            for (int j = 0; j < countY; j++)
                            {
                                for (int i = 0; i < countX; i++)
                                {
                                    System.Drawing.RectangleF cloneRect = new System.Drawing.RectangleF(w * i, h * j, w, h);
                                    System.Drawing.Bitmap crop = bitmap.Clone(cloneRect, bitmap.PixelFormat);

                                    System.IO.MemoryStream stream = new System.IO.MemoryStream();
                                    new System.Drawing.Bitmap(crop).Save(stream, System.Drawing.Imaging.ImageFormat.Png);

                                    BitmapImage bi = new BitmapImage();
                                    bi.BeginInit();
                                    bi.StreamSource = stream;
                                    bi.EndInit();

                                    anim.frames[j * countX + i] = new Frame(0, bi);
                                }
                            }

                            Image shape = new Image();
                            shape.Source = anim.frames[0].bi;
                            shape.Stretch = Stretch.Fill;
                            shape.Name = shapeName;
//.........这里部分代码省略.........
开发者ID:litdev1,项目名称:LitDev,代码行数:101,代码来源:Shapes.cs

示例5: CropImage

            public string CropImage(int x, int y, int w, int h, string imagePath)
            {
                var pathImage = Server.MapPath(imagePath);
                Image img = Image.FromFile(pathImage);
                Bitmap newBitmap = null;
                using (System.Drawing.Bitmap _bitmap = new System.Drawing.Bitmap(w, h))
                {
                    _bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
                    using (Graphics _graphic = Graphics.FromImage(_bitmap))
                    {
                        _graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        _graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        _graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                        _graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

                        _graphic.DrawImage(img, 0, 0, w, h);
                        _graphic.DrawImage(img, new Rectangle(0, 0, w, h), x, y, w, h, GraphicsUnit.Pixel);
                    }
                    var objImg = _bitmap.Clone();
                    newBitmap = (Bitmap)objImg;

                }
                var fileName = Path.GetFileNameWithoutExtension(imagePath) + "_Cropped" + Path.GetExtension(imagePath);
                newBitmap.Save(Server.MapPath("/Uploads/Temp/") + fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                return fileName;
            }
开发者ID:ramonrepositorio,项目名称:CareFit,代码行数:26,代码来源:ImagesController.cs

示例6: AutoResize

        private System.Drawing.Image AutoResize(System.Drawing.Image originalImg)
        {
            double resizeFactor = 1;
            double MAX_DIMENSION = 100;
            int newWidth = originalImg.Width;
            int newHeight = originalImg.Height;

            // if image is bigger then MAX_DIMENSION x MAX_DIMENSION
            // calculates the new dimensiom
            if (originalImg.Width > MAX_DIMENSION || originalImg.Height > MAX_DIMENSION) {

                // use the lowest dimension to calculate the resize factor
                if (originalImg.Width < originalImg.Height)
                    resizeFactor = (double)(MAX_DIMENSION / originalImg.Width);
                else
                    resizeFactor = (double)(MAX_DIMENSION / originalImg.Height);

                newWidth = (int)(originalImg.Width * resizeFactor);
                newHeight = (int)(originalImg.Height * resizeFactor);

            }

            // Resize the image
            System.Drawing.Bitmap newImg = new System.Drawing.Bitmap(originalImg, newWidth, newHeight);

            // Now crop it
            int m;
            System.Drawing.Rectangle crop;
            if (newImg.Width < newImg.Height) {
                m = (newImg.Height - newImg.Width) / 2;
                crop = new System.Drawing.Rectangle(0, m, newImg.Width, newImg.Width);
            } else {
                m = (newImg.Width - newImg.Height) / 2;
                crop = new System.Drawing.Rectangle(m, 0, newImg.Height, newImg.Height);
            }

            return newImg.Clone(crop, newImg.PixelFormat);
        }
开发者ID:klot-git,项目名称:scrum-factory,代码行数:38,代码来源:MemberViewModel.cs

示例7: getScreenshot

        /// <summary>Gets the screenshot of the current element</summary>
        /// <returns>Image</returns>
        public Image getScreenshot() {
            /*
            OpenQA.Selenium.Screenshot ret = ((OpenQA.Selenium.ITakesScreenshot)this.webElement).GetScreenshot();
            if (ret == null) throw new ApplicationException("Method <getScreenshot> failed !\nReturned value is empty");
            return new Image(ret.AsByteArray);
            */

            System.Drawing.Rectangle cropRect = new System.Drawing.Rectangle(_webElement.Location, _webElement.Size);
            byte[] imageBytes = ((OpenQA.Selenium.ITakesScreenshot)_webDriver).GetScreenshot().AsByteArray;
            if (imageBytes == null) throw new ApplicationException("Method <captureScreenshotToPdf> failed !\nReturned value is empty");

            System.Drawing.Image srcImage;
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(imageBytes))
                srcImage = System.Drawing.Image.FromStream(ms);
            using (System.Drawing.Bitmap srcBitmap = new System.Drawing.Bitmap(srcImage))
            using (System.Drawing.Bitmap bmpCrop = srcBitmap.Clone(cropRect, srcBitmap.PixelFormat))
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
                bmpCrop.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                return new Image(ms.ToArray());
            }
        }
开发者ID:ubuetake,项目名称:selenium-vba,代码行数:23,代码来源:WebElement.cs

示例8: refreshImagePack

        private static void refreshImagePack(
			string xmlPath,
			bool isRePack,
			out Dictionary<string, System.Drawing.Rectangle> mapImgRect,
			out System.Drawing.Bitmap tgaImg,
			out int imgWidth,
			out int imgHeight)
        {
            string pngPath = xmlPath.Remove(xmlPath.LastIndexOf("."));
            string tgaPath = pngPath + ".tga";
            string bmpPath = pngPath + ".bmp";
            string targetPath;

            if (System.IO.File.Exists(xmlPath))
            {
                XmlDocument docXml = new XmlDocument();

                try
                {
                    docXml.Load(xmlPath);
                }
                catch
                {
                    mapImgRect = null;
                    tgaImg = null;
                    imgWidth = 0;
                    imgHeight = 0;

                    return;
                }
                getMapImgRect(docXml, out mapImgRect, out imgWidth, out imgHeight);

                tgaImg = new System.Drawing.Bitmap(imgWidth, imgHeight);
                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(tgaImg);
                g.Clear(System.Drawing.Color.FromArgb(0x00, 0x00, 0x00, 0x00));

                IncludeFile imageRootFolder = IncludeFile.getImageRootFolder();

                if (isRePack == true)
                {
                    s_countFF = 0;
                    s_countNotFF = 0;
                    foreach (KeyValuePair<string, System.Drawing.Rectangle> pairImgRect in mapImgRect)
                    {
                        refreshAlphaCount(pngPath + "\\" + pairImgRect.Key + ".png",
                            pairImgRect.Value);
                        addPicToGraphics(
                            pngPath + "\\" + pairImgRect.Key + ".png",
                            pairImgRect.Value,
                            g);
                    }
                    g.Dispose();
                    if (System.IO.File.Exists(tgaPath))
                    {
                        System.IO.File.Delete(tgaPath);
                    }
                    if (System.IO.File.Exists(bmpPath))
                    {
                        System.IO.File.Delete(bmpPath);
                    }
                    if (s_countNotFF != 0)
                    {
                        targetPath = tgaPath;
                        DevIL.DevIL.SaveBitmap(targetPath, tgaImg);
                    }
                    else
                    {
                        targetPath = bmpPath;
                        System.Drawing.Bitmap bmpImg = tgaImg.Clone(new System.Drawing.Rectangle(0, 0, tgaImg.Width, tgaImg.Height),
                            System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                        bmpImg.Save(targetPath, System.Drawing.Imaging.ImageFormat.Bmp);
                        tgaImg = bmpImg;
                    }
                    double perUse = (double)(s_countFF + s_countNotFF) / (double)(tgaImg.Width * tgaImg.Height) * 100.0f;
                    Public.ResultLink.createResult("\r\n<" + System.IO.Path.GetFileName(targetPath) + ">",
                        Public.ResultType.RT_INFO, xmlPath, true);
                    Public.ResultLink.createResult("\t尺寸:" + tgaImg.Width + " x " + tgaImg.Height +
                        "\t无alpha:" + s_countFF + "\t有alpha:" + s_countNotFF + "\t利用率:" + String.Format("{0:F}", perUse) + "%",
                        Public.ResultType.RT_INFO, null, true);

                    IncludeFile tgaFileDef;

                    if (!MainWindow.s_pW.m_mapIncludeFiles.TryGetValue(targetPath, out tgaFileDef))
                    {
                        imageRootFolder.Items.Add(new IncludeFile(targetPath));
                    }

                    IncludeFile xmlFileDef;

                    if (!MainWindow.s_pW.m_mapIncludeFiles.TryGetValue(xmlPath, out xmlFileDef))
                    {
                        imageRootFolder.Items.Add(new IncludeFile(xmlPath));
                    }
                }
                else
                {
                    if (System.IO.File.Exists(tgaPath))
                    {
                        targetPath = tgaPath;
//.........这里部分代码省略.........
开发者ID:jaffrykee,项目名称:ui,代码行数:101,代码来源:PackImage.xaml.cs

示例9: LoadImage

 private System.Drawing.Image LoadImage(string file)
 {
     if (System.IO.File.Exists(file))
     {
         System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(file);
         System.Drawing.Bitmap result = (System.Drawing.Bitmap)bmp.Clone();
         bmp.Dispose(); bmp = null;
         return result;
     }
     return null;
 }
开发者ID:faze79,项目名称:rmo-rugbymania,代码行数:11,代码来源:MyButton.cs

示例10: ImageInfo

        /// <summary>
        /// this construr gets the _imGray of an ImageInfo in order to get another object
        /// of that image without any more data, can be used when running filters on images
        /// </summary>
        /// <param name="imGray"></param>
        private ImageInfo(Bitmap imGray)
        {
            _disposed = false;

            _path = null;
            _hist = null;
            _imf = null;
            _imGray = (Bitmap)imGray.Clone();
            _width = _imGray.Width;
            _height = _imGray.Height;
        }
开发者ID:esheleg,项目名称:PhotoSelect,代码行数:16,代码来源:ImageInfo.cs

示例11: _screenshot

        private void _screenshot()
        {
            RenderTarget2D renderTarget = new RenderTarget2D(
_graphics.GraphicsDevice,
_graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
_graphics.GraphicsDevice.PresentationParameters.BackBufferHeight);
            GameStatus temp = _status;
            _status = GameStatus.NoRedraw;
            _graphics.GraphicsDevice.SetRenderTarget(renderTarget);
            _mainmap1.Draw(new GameTime());
            _graphics.GraphicsDevice.SetRenderTarget(null);
            _status = temp;

            byte[] pixelData = new byte[renderTarget.Width * renderTarget.Height * 4];

            renderTarget.GetData(pixelData);
            for (int i = 0; i < pixelData.Length - 3; i += 4)
            {
                byte tmp = pixelData[i];
                pixelData[i] = pixelData[i + 2];
                pixelData[i + 2] = tmp;
            }
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(renderTarget.Width, renderTarget.Height, renderTarget.Width * 4, System.Drawing.Imaging.PixelFormat.Format32bppRgb, System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(pixelData, 0));
            int _width = renderTarget.Width - 5;
            int _height = renderTarget.Height - 145;
            int _left = 5;
            int _top = 5;
            if (_width > _height)
            {
                _left += (_width - _height) / 2;
                _width = _height;
            }
            else
            {
                _top += (_height - _left) / 2;
                _height = _width;
            }
            System.Drawing.Bitmap cropped = bitmap.Clone(new System.Drawing.Rectangle(_left, _top, _width, _height), bitmap.PixelFormat);

            bitmap.Dispose();
            bitmap = new System.Drawing.Bitmap(cropped, new System.Drawing.Size(200, 200));

            //Unlock the pixels
            //bmp.UnlockBits(bmpData);
            bitmap.Save("save\\screen.png", System.Drawing.Imaging.ImageFormat.Png);
            bitmap.Dispose();
            cropped.Dispose();


        }
开发者ID:propra13-orga,项目名称:gruppe22,代码行数:50,代码来源:GameWin.cs

示例12: RenderImageGallery

 /// <summary>
 /// Renders the image gallery.
 /// </summary>
 /// <param name="_galleryId">The _gallery id.</param>
 /// <param name="progressInfoId">The progress info id.</param>
 /// <returns></returns>
 public static Dictionary<string, object> RenderImageGallery( string _galleryId, string progressInfoId )
 {
     ( "FUNCTION /w SP,fileSystem renderImageGallery" ).Debug( 10 );
     Guid id = new Guid( progressInfoId );
     ProgressInfo u = new ProgressInfo( id );
     if( !Main.ProgressInfos.ContainsKey( id ) ) {
         Main.ProgressInfos.Add( id, u );
     } else {
         Main.ProgressInfos[ id ] = u;
     }
     u.CurrentItemName = "Calculating work size please wait...";
     u.TotalItemCount = 0;
     u.Started = DateTime.Now;
     Dictionary<string, object> j = new Dictionary<string, object>();
     List<object> errors = new List<object>();
     j.Add( "error", 0 );
     j.Add( "description", "" );
     List<Dictionary<Int64, object>> entries = new List<Dictionary<Int64, object>>();
     try {
         using(Impersonation imp = new Impersonation()) {
             Guid galleryId = new Guid(_galleryId);
             using(SqlConnection cn = Site.CreateConnection(true, true)) {
                 cn.Open();
                 using(SqlCommand cmd = new SqlCommand("getRotatorCategory @imageRotatorCategoryId", cn)) {
                     cmd.Parameters.Add("@imageRotatorCategoryId", SqlDbType.UniqueIdentifier).Value = new Guid(galleryId.ToString());
                     using(SqlDataReader d = cmd.ExecuteReader()) {
                         while(d.Read()) {
                             Dictionary<Int64, object> i = new Dictionary<Int64, object>();
                             i.Add(1, d.GetString(1));
                             i.Add(2, (Int64)d.GetInt32(2));
                             i.Add(3, (Int64)d.GetInt32(3));
                             i.Add(5, d.GetGuid(5));
                             i.Add(6, d.GetGuid(6));
                             i.Add(7, d.GetGuid(7));
                             i.Add(8, d.GetGuid(8));
                             i.Add(9, d.GetGuid(9));
                             i.Add(15, d.GetString(15));
                             i.Add(14, d.GetGuid(14));
                             i.Add(18, (Int64)d.GetInt32(18));
                             i.Add(19, (Int64)d.GetInt32(19));
                             i.Add(20, (Int64)d.GetInt32(20));
                             i.Add(21, (Int64)d.GetInt32(21));
                             i.Add(22, (Int64)d.GetInt32(22));
                             i.Add(23, (Int64)d.GetInt32(23));
                             i.Add(24, (Int64)d.GetInt32(24));
                             i.Add(25, (Int64)d.GetInt32(25));
                             entries.Add(i);
                             u.CurrentItemName = String.Format("Adding item {0}", Path.GetFileName((string)i[15]));
                             u.TotalItemCount++;
                         }
                     }
                 }
             }
             u.CurrentItemCount = 0;
             foreach(Dictionary<Int64, object> i in entries) {
                 u.CurrentItemName = String.Format("Working on item {0}", Path.GetFileName((string)i[15]));
                 u.CurrentItemCount++;
                 string categoryDirectory = Main.PhysicalApplicationPath + "img\\gallery\\" + i[1];
                 string srcFilePath = (string)i[15];
                 string outputFileName = ((Guid)i[14]).ToFileName();
                 /* create gallery directory */
                 if(!Directory.Exists(categoryDirectory)) {
                     Directory.CreateDirectory(categoryDirectory);
                 }
                 /* get the input file */
                 using(System.Drawing.Bitmap srcImg = new System.Drawing.Bitmap(srcFilePath)) {
                     /* for each type of image create a file with a special suffix */
                     /* the rotator template is special, it gets the gallery method then the rotator template */
                     System.Drawing.Bitmap b;
                     using(b = (System.Drawing.Bitmap)srcImg.Clone()) {
                         b = Admin.GalleryCrop(b, (Int64)i[18], (Int64)i[19], (Int64)i[21], (Int64)i[20],
                         (Int64)i[22], (Int64)i[23], (Int64)i[25], (Int64)i[24], (Int64)i[3], (Int64)i[2]);
                         b = Admin.ExecuteImageTemplate(b, i[5].ToString(), ref errors);/*5=rotator template */
                         b.SaveJpg(categoryDirectory + "\\" + outputFileName + "r.jpg", 90L);
                     }
                     using(b = (System.Drawing.Bitmap)srcImg.Clone()) {
                         b = Admin.ExecuteImageTemplate(b, i[6].ToString(), ref errors);/*6=thumb template */
                         b.SaveJpg(categoryDirectory + "\\" + outputFileName + "t.jpg", 90L);
                     }
                     using(b = (System.Drawing.Bitmap)srcImg.Clone()) {
                         b = Admin.ExecuteImageTemplate(b, i[7].ToString(), ref errors);/*7=fullsize template */
                         b.SaveJpg(categoryDirectory + "\\" + outputFileName + "f.jpg", 90L);
                     }
                     using(b = (System.Drawing.Bitmap)srcImg.Clone()) {
                         b = Admin.ExecuteImageTemplate(b, i[8].ToString(), ref errors);/*8=portfolio template */
                         b.SaveJpg(categoryDirectory + "\\" + outputFileName + "p.jpg", 90L);
                     }
                     using(b = (System.Drawing.Bitmap)srcImg.Clone()) {
                         b = Admin.ExecuteImageTemplate(b, i[9].ToString(), ref errors);/*9=Blog template */
                         b.SaveJpg(categoryDirectory + "\\" + outputFileName + "b.jpg", 90L);
                     }
                 }
             }
             u.Complete = true;
//.........这里部分代码省略.........
开发者ID:CorbinDallas,项目名称:Rendition,代码行数:101,代码来源:Gallery.cs


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