當前位置: 首頁>>代碼示例>>C#>>正文


C# Bitmap.ResizeImage方法代碼示例

本文整理匯總了C#中System.Drawing.Bitmap.ResizeImage方法的典型用法代碼示例。如果您正苦於以下問題:C# Bitmap.ResizeImage方法的具體用法?C# Bitmap.ResizeImage怎麽用?C# Bitmap.ResizeImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.Bitmap的用法示例。


在下文中一共展示了Bitmap.ResizeImage方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ImageImport

        public static bool ImageImport(this DeviceModel deviceModel, Stream ImageStream)
        {
            try
            {
                using (Bitmap inputBitmap = new Bitmap(ImageStream))
                {
                    using (Image outputBitmap = inputBitmap.ResizeImage(256, 256))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            outputBitmap.SavePng(ms);
                            ms.Position = 0;

                            var deviceModelImagePath = deviceModel.ImageFilePath();


                            using (var storeStream = new FileStream(deviceModelImagePath, FileMode.Create, FileAccess.Write, FileShare.None))
                            {
                                ms.CopyTo(storeStream);
                            }
                            //deviceModel.Image = ms.ToArray();
                        }
                    }
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
開發者ID:garysharp,項目名稱:Disco,代碼行數:31,代碼來源:DeviceDataStoreExtensions.cs

示例2: TestResizeImageToMaximumDimension

        public void TestResizeImageToMaximumDimension()
        {
            using (var image = new Bitmap(ImageLocation))
            {
                var resizedImage = image.ResizeImage(90);

                Assert.AreEqual(90, resizedImage.Width);

                resizedImage.Dispose();
            }
        }
開發者ID:comsechq,項目名稱:sugar,代碼行數:11,代碼來源:BitmapExtensionsTest.cs

示例3: TestResizeImage

        public void TestResizeImage()
        {
            using (var image = new Bitmap(ImageLocation))
            {
                var resizedImage = image.ResizeImage(320, 200);

                Assert.AreEqual(320, resizedImage.Width);
                Assert.AreEqual(200, resizedImage.Height);

                resizedImage.Dispose();
            }
        }
開發者ID:comsechq,項目名稱:sugar,代碼行數:12,代碼來源:BitmapExtensionsTest.cs

示例4: ResizeImage

 public static byte[] ResizeImage(this byte[] imageBytes, int width, int height)
 {
     try
     {
         using (MemoryStream streamInput = new MemoryStream(imageBytes))
         {
             System.Drawing.Image image = new Bitmap(streamInput);
             ImageFormat oldFormat = image.RawFormat;
             image = image.ResizeImage(width, height);
             byte[] result = image.GetBytes(oldFormat);
             return result;
         }
     }
     catch (Exception ex)
     {
         return imageBytes;
     }
 }
開發者ID:jakforest,項目名稱:WCFImage,代碼行數:18,代碼來源:ImageHelper.cs

示例5: Image

 public ActionResult Image(string imageFile, int? width, int? height, int? id)
 {
     var memoryStream = new MemoryStream();
     var image = new Bitmap(ObjectsRepository.CatalogFolder + imageFile.Replace("___", "/"));
     if (width != null && height != null)
     {
         image = image.Clip10X15();
         image = image.ResizeImage(width.Value, height.Value);
     }
     if (id != null)
     {
         image = image.AddBluredRect(30);
         var htmlText = ObjectsRepository.GetObjectDescription(id.Value);
         if (!string.IsNullOrEmpty(htmlText))
         {
             image = image.AddText(30, 0, htmlText);
         }
         //var backImage = new Bitmap(Server.MapPath("~\\Content\\images\\keyend.png"));
         //image = image.AddBackBitmap(backImage);
     }
     image.Save(memoryStream, ImageFormat.Jpeg);
     memoryStream.Seek(0, SeekOrigin.Begin);
     return File(memoryStream, "image/jpeg");
 }
開發者ID:SergeyMironchuk,項目名稱:Agentstvo,代碼行數:24,代碼來源:HomeController.cs

示例6: PasteScaledBitmapImageToTileByLatLon

        void PasteScaledBitmapImageToTileByLatLon(int zoom, double Lon, double Lat, int xTile, int yTile, double scale, Bitmap iconImage)
        {
            int width = iconImage.Width;
            int height = iconImage.Height;
            if (scale != 1.0)
            {
                width = (int)(width * scale);
                height = (int)(height * scale);

            }
            CopyRegionIntoImage(iconImage.ResizeImage((width), (height )), new Rectangle(0, 0, width, height), GetTargetBound(zoom, Lon, Lat, xTile, yTile, width, height));
        }
開發者ID:MoonDav,項目名稱:TileRendering,代碼行數:12,代碼來源:Icon2TileRendering.cs

示例7: PasteIcon

        void PasteIcon(Bitmap icon, int x, int y, double scale)
        {
            int width = icon.Width;
            int height = icon.Height;
            if (scale != 1.0)
            {
                icon.ResizeImage((int)(width * scale), (int)(height * scale));
                width = (int)(width * scale);
                height = (int)(height * scale);
            }

            CopyRegionIntoImage(icon, new Rectangle(0, 0, width, height),  new Rectangle(x, y, width, width));
        }
開發者ID:MoonDav,項目名稱:TileRendering,代碼行數:13,代碼來源:Icon2TileRendering.cs

示例8: LoadExternalMugshots

        /// <summary>
        /// Load all external mugshots into the cache.
        /// </summary>
        private static void LoadExternalMugshots()
        {
            string mugshotFolder = Path.Combine(CIX.HomeFolder, "Mugshots");
            if (Directory.Exists(mugshotFolder))
            {
                string[] allFiles = Directory.GetFiles(mugshotFolder);
                foreach (string filename in allFiles)
                {
                    try
                    {
                        string username = Path.GetFileNameWithoutExtension(filename);
                        Image mugshotImage = new Bitmap(filename);
                        mugshotImage = mugshotImage.ResizeImage(MaxMugshotWidth, MaxMugshotHeight);

                        if (username != null && mugshotImage != null)
                        {
                            Mugshot mugshot = new Mugshot();

                            ImageConverter converter = new ImageConverter();
                            mugshot.Image = (byte[])converter.ConvertTo(mugshotImage, typeof(byte[]));
                            mugshot.Username = username;

                            Cache[username] = mugshot;
                        }
                    }
                    catch (Exception e)
                    {
                        LogFile.WriteLine("Error loading {0} : {1}", filename, e.Message);
                    }
                }
            }
        }
開發者ID:cixonline,項目名稱:cixreader,代碼行數:35,代碼來源:Mugshot.cs


注:本文中的System.Drawing.Bitmap.ResizeImage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。