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


C# Bitmap.GetResized方法代码示例

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


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

示例1: generateThumbnail

 private static void generateThumbnail(string imagePath, string thumbnailPath, int size, ThumbnailClip clip)
 {
     var dir = new DirectoryInfo(Path.GetDirectoryName(thumbnailPath));
     dir.Create(true);
     Bitmap bmp = new Bitmap(imagePath);
     Bitmap resizedBmp = clip == ThumbnailClip.Square ? bmp.GetSquare((int)size) : bmp.GetResized((int)size);
     string thumbnailTempPath = thumbnailPath + ".tmp";
     resizedBmp.Save(thumbnailTempPath, ImageFormat.Png);
     File.Move(thumbnailTempPath, thumbnailPath);
 }
开发者ID:BackupTheBerlios,项目名称:molecule-svn,代码行数:10,代码来源:ThumbnailService.cs

示例2: GenerateGalaxyImage

        //
        // GET: /Campaign/

        /// <summary>
        /// Makes an image: campaign background with planet images drawn on it (cheaper than rendering each planet individually)
        /// </summary>
        public Bitmap GenerateGalaxyImage(int campaignID, double zoom = 1, double antiAliasingFactor = 4) {
            zoom *= antiAliasingFactor;
            using (var db = new ZkDataContext()) {
                Campaign camp = db.Campaigns.Single(x => x.CampaignID == campaignID);

                using (Image background = Image.FromFile(Server.MapPath("/img/galaxies/" + camp.MapImageName))) {
                    Bitmap im = new Bitmap((int)(background.Width*zoom), (int)(background.Height*zoom));
                    using (Graphics gr = Graphics.FromImage(im)) {
                        gr.DrawImage(background, 0, 0, im.Width, im.Height);

                        foreach (CampaignPlanet p in camp.CampaignPlanets) {
                            string planetIconPath = null;
                            Resource map = db.Resources.FirstOrDefault(m => m.InternalName == p.Mission.Map);
                            try {
                                planetIconPath = "/img/planets/" + (map.MapPlanetWarsIcon ?? "1.png"); // backup image is 1.png
                                using (Image pi = Image.FromFile(Server.MapPath(planetIconPath))) {
                                    double aspect = pi.Height/(double)pi.Width;
                                    var width = (int)(map.PlanetWarsIconSize * zoom);
                                    var height = (int)(width*aspect);
                                    gr.DrawImage(pi, (int)(p.X*im.Width) - width/2, (int)(p.Y*im.Height) - height/2, width, height);
                                }
                            } catch (Exception ex) {
                                throw new ApplicationException(
                                    string.Format("Cannot process planet image {0} for planet {1} map {2}",
                                                  planetIconPath,
                                                  p.PlanetID,
                                                  map.ResourceID),
                                    ex);
                            }
                        }
                        if (antiAliasingFactor == 1) return im;
                        else {
                            zoom /= antiAliasingFactor;
                            return im.GetResized((int)(background.Width*zoom), (int)(background.Height*zoom), InterpolationMode.HighQualityBicubic);
                        }
                    }
                }
            }
        }
开发者ID:DeinFreund,项目名称:Zero-K-Infrastructure,代码行数:45,代码来源:CampaignController.cs

示例3: GenerateGalaxyImage

        /// <summary>
        /// Makes an image: galaxy background with planet images drawn on it (cheaper than rendering each planet individually)
        /// </summary>
        // FIXME: having issues with bitmap parameters; setting AA factor to 1 as fallback (was 4)
        public Bitmap GenerateGalaxyImage(int galaxyID, double zoom = 1, double antiAliasingFactor = 1)
        {
            zoom *= antiAliasingFactor;
            using (var db = new ZkDataContext())
            {
                Galaxy gal = db.Galaxies.Single(x => x.GalaxyID == galaxyID);

                using (Image background = Image.FromFile(Server.MapPath("/img/galaxies/" + gal.ImageName)))
                {
                    //var im = new Bitmap((int)(background.Width*zoom), (int)(background.Height*zoom));
                    var im = new Bitmap(background.Width, background.Height);
                    using (Graphics gr = Graphics.FromImage(im))
                    {
                        gr.DrawImage(background, 0, 0, im.Width, im.Height);

                        /*
						using (var pen = new Pen(Color.FromArgb(255, 180, 180, 180), (int)(1*zoom)))
						{
							foreach (var l in gal.Links)
							{
								gr.DrawLine(pen,
								            (int)(l.PlanetByPlanetID1.X*im.Width),
								            (int)(l.PlanetByPlanetID1.Y*im.Height),
								            (int)(l.PlanetByPlanetID2.X*im.Width),
								            (int)(l.PlanetByPlanetID2.Y*im.Height));
							}
						}*/

                        foreach (Planet p in gal.Planets)
                        {
                            string planetIconPath = null;
                            try
                            {
                                planetIconPath = "/img/planets/" + (p.Resource.MapPlanetWarsIcon ?? "1.png"); // backup image is 1.png
                                using (Image pi = Image.FromFile(Server.MapPath(planetIconPath)))
                                {
                                    double aspect = pi.Height / (double)pi.Width;
                                    var width = (int)(p.Resource.PlanetWarsIconSize * zoom);
                                    var height = (int)(width * aspect);
                                    gr.DrawImage(pi, (int)(p.X * im.Width) - width / 2, (int)(p.Y * im.Height) - height / 2, width, height);
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new ApplicationException(
                                    string.Format("Cannot process planet image {0} for planet {1} map {2}",
                                                  planetIconPath,
                                                  p.PlanetID,
                                                  p.MapResourceID),
                                    ex);
                            }
                        }
                        if (antiAliasingFactor == 1) return im;
                        else
                        {
                            zoom /= antiAliasingFactor;
                            return im.GetResized((int)(background.Width * zoom), (int)(background.Height * zoom), InterpolationMode.HighQualityBicubic);
                        }
                    }
                }
            }
        }
开发者ID:Jamanno,项目名称:Zero-K-Infrastructure,代码行数:66,代码来源:PlanetwarsController.cs

示例4: generatePhotoFile

 private static void generatePhotoFile(string imagePath, string resizedPath, PhotoFileSize size,
     PhotoFileClip clip)
 {
     var dir = new DirectoryInfo(Path.GetDirectoryName(resizedPath));
     dir.Create(true);
     using (Bitmap bmp = new Bitmap(imagePath))
     {
         bmp.AutoRotate();
         using (BitmapEx resizedBmp = clip == PhotoFileClip.Square ? bmp.GetSquare((int)size) : bmp.GetResized((int)size))
         {
             string thumbnailTempPath = resizedPath + ".tmp";
             var encodeParams = new EncoderParameters(1);
             encodeParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, instance.qualityLevel);
             resizedBmp.Bitmap.Save(thumbnailTempPath, jgpEncoder, encodeParams);
             File.Move(thumbnailTempPath, resizedPath);
         }
     }
 }
开发者ID:BackupTheBerlios,项目名称:molecule-svn,代码行数:18,代码来源:PhotoFileProvider.cs

示例5: saveCoverArt

        private static void saveCoverArt(string artist, string albumTitle, string sourceUrl, string destination)
        {
            if (sourceUrl != null)
            {
                string destinationDirectory = Directory.GetParent(destination).FullName;
                // if the destination directory doesn't exist
                if( !Directory.Exists( destinationDirectory ))
                {
                    Directory.CreateDirectory(destinationDirectory);
                }
                WebClient client = new WebClient();
                Stream imgStream;
                try
                {
                    imgStream = client.OpenRead(sourceUrl);
                }
                catch (WebException ex)
                {
                    if (log.IsErrorEnabled)
                        log.Error(ex.Message, ex.InnerException);
                    return;
                }

                using (Bitmap bmp = new Bitmap(System.Drawing.Image.FromStream(imgStream)))
                {
                    using (BitmapEx resizedBmp = bmp.GetResized(imageSize))
                    {
                        resizedBmp.Bitmap.Save(destination, ImageFormat.Jpeg);
                    }
                }
            }
        }
开发者ID:BackupTheBerlios,项目名称:molecule-svn,代码行数:32,代码来源:CoverArtService.cs


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