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


C# Bitmap.Resize方法代码示例

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


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

示例1: button_Click

        private void button_Click(object sender, EventArgs e)
        {
            Stream stream = null;

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((stream = openFileDialog.OpenFile()) != null)
                    {
                        using (stream)
                        {
                            string pathName = openFileDialog.FileName;

                            Bitmap image = new Bitmap(pathName);

                            pictureBox1.Image = image.Resize(pictureBox1.Width, pictureBox1.Height);

                            Histogram histogram1 = new Histogram();

                            histogram1.SetIntensities(image);

                            histogram1.DrawHistogram(chart1);

                            chart1.Visible = true;

                            this.Controls.Add(chart1);

                            Histogram histogram2 = new Histogram();

                            image = histogram1.BalanceImage(image);

                            pictureBox2.Image = image.Resize(pictureBox2.Width, pictureBox2.Height);

                            histogram2.SetIntensities(image);

                            histogram2.DrawHistogram(chart2);

                            chart2.Visible = true;

                            this.Controls.Add(chart2);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
开发者ID:pkt-fit-knu,项目名称:I21-07,代码行数:57,代码来源:Form1.cs

示例2: ResizeDown

        public void ResizeDown()
        {
            Image image = new Bitmap(500, 500);

            var newImage = image.Resize(100, 200);

            Assert.AreEqual(newImage.Width, 100);
            Assert.AreEqual(newImage.Height, 200);
        }
开发者ID:rrreese,项目名称:Utilities,代码行数:9,代码来源:ResizeImage.cs

示例3: ChooseImage

        public void ChooseImage(int id)
        {
            var filePaths = Directory.GetFiles(string.Format(@"C:\Users\Dimitar\Pictures\FilterIT\{0}\", User.Identity.Name), "*.png");
            var img = new Bitmap(filePaths[id]);

            int height = (int)(img.Height / ((float)img.Width / 500f));
            var filteredImages = img.Resize(500, height).ApplyFilters();

            Session["Image"] = img;
            Session["ImageName"] = Path.GetFileName(filePaths[id]);
            Session["FilteredImages"] = filteredImages;
        }
开发者ID:dspankov,项目名称:FilterIT,代码行数:12,代码来源:HistoryController.cs

示例4: button_Click

        private void button_Click(object sender, EventArgs e)
        {
            Stream stream = null;

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((stream = openFileDialog.OpenFile()) != null)
                    {
                        using (stream)
                        {
                            string pathName = openFileDialog.FileName;

                            Bitmap image = new Bitmap(pathName);

                            pictureBox1.Image = image.Resize(pictureBox1.Width, pictureBox1.Height);

                            Mask mask = new Mask(new int[,] { { 1, 1, 1 }, { 1, -8, 1 }, { 1, 1, 1 } });

                            image = LaplacianSharper.SharpImage(image, mask);

                            pictureBox2.Image = image.Resize(pictureBox2.Width, pictureBox2.Height);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
开发者ID:pkt-fit-knu,项目名称:I21-07,代码行数:39,代码来源:Form1.cs

示例5: Resize

 public static bool Resize(this string sourcePath, string destinationPath, Size size)
 {
     if (File.Exists(sourcePath))
     {
         using (Image image = new Bitmap(sourcePath))
         {
             using (Image resized = image.Resize(size))
             {
                 resized.Save(destinationPath, ImageFormat.Jpeg);
             }
         }
         return true;
     }
     return false;
 }
开发者ID:ushahidi,项目名称:Ushahidi_WinMobile,代码行数:15,代码来源:ImageExtensions.cs

示例6: GetThumbnails

        public string GetThumbnails(HttpPostedFileBase fileUpload)
        {
            var stream = fileUpload.InputStream;
            Bitmap img = new Bitmap(stream);

            if(User.Identity.IsAuthenticated)
                SaveImage(fileUpload.FileName, img);

            int height = (int)(img.Height / ((float)img.Width / 500f));
            var filteredImages = img.Resize(500, height).ApplyFilters();

            Session["Image"] = img;
            Session["ImageName"] = fileUpload.FileName;
            Session["FilteredImages"] = filteredImages;

            return filteredImages;
        }
开发者ID:dspankov,项目名称:FilterIT,代码行数:17,代码来源:ImageController.cs

示例7: CreateLastPositionImage

        private static Bitmap CreateLastPositionImage(Bitmap source)
        {
            try
            {
                var img = new Bitmap(source.Width, source.Width);
                var cropRect = new Rectangle(0, 0, source.Width, source.Width);

                using (var sourceImage = source)
                {
                    using (var croppedImage = sourceImage.Clone(cropRect, sourceImage.PixelFormat))
                    {
                        using (var tb = new TextureBrush(croppedImage))
                        {
                            using (var g = Graphics.FromImage(img))
                            {
                                g.FillEllipse(tb, 0, 0, source.Width, source.Width);
                                g.DrawEllipse(
                                    new Pen(Color.FromArgb(86, 86, 86), 6) { Alignment = PenAlignment.Inset }, 0, 0,
                                    source.Width, source.Width);
                            }
                        }
                    }
                }
                return img.Resize(24, 24).Grayscale();
            }
            catch (Exception ex)
            {
                Global.Logger.AddItem(new LogItem(ex));
            }
            return null;
        }
开发者ID:juan2202,项目名称:LeagueSharp-Standalones,代码行数:31,代码来源:ImageLoader.cs

示例8: EvaluateImageInputUsingFeatureVector

        /// <summary>
        /// This method shows how to evaluate a trained image classification model, with
        /// explicitly created feature vectors.
        /// </summary>
        public static List<float> EvaluateImageInputUsingFeatureVector()
        {
            List<float> outputs = null;

            try
            {
                // This example requires the RestNet_18 model.
                // The model can be downloaded from <see cref="https://www.cntk.ai/resnet/ResNet_18.model"/>
                // The model is assumed to be located at: <CNTK>\Examples\Image\Classification\ResNet
                // along with a sample image file named "zebra.jpg".
                Environment.CurrentDirectory = initialDirectory;

                using (var model = new IEvaluateModelManagedF())
                {
                    model.CreateNetwork(string.Format("modelPath=\"{0}\"", resnetModelFilePath), deviceId: -1);

                    // Prepare input value in the appropriate structure and size
                    var inDims = model.GetNodeDimensions(NodeGroup.Input);
                    if (inDims.First().Value != resNetImageSize * resNetImageSize * 3)
                    {
                        throw new CNTKRuntimeException(string.Format("The input dimension for {0} is {1} which is not the expected size of {2}.", inDims.First(), inDims.First().Value, 224 * 224 * 3), string.Empty);
                    }

                    // Transform the image
                    Bitmap bmp = new Bitmap(Bitmap.FromFile(imageFileName));
                    var resized = bmp.Resize(resNetImageSize, resNetImageSize, true);

                    var resizedCHW = resized.ParallelExtractCHW();
                    var inputs = new Dictionary<string, List<float>>() { {inDims.First().Key, resizedCHW } };

                    // We can call the evaluate method and get back the results (single layer output)...
                    var outDims = model.GetNodeDimensions(NodeGroup.Output);
                    outputs = model.Evaluate(inputs, outDims.First().Key);
                }

                // Retrieve the outcome index (so we can compare it with the expected index)
                var max = outputs.Select((value, index) => new { Value = value, Index = index })
                    .Aggregate((a, b) => (a.Value > b.Value) ? a : b)
                    .Index;

                Console.WriteLine("EvaluateImageInputUsingFeatureVector: Outcome = {0}", max);
            }
            catch (CNTKException ex)
            {
                OnCNTKException(ex);
            }
            catch (Exception ex)
            {
                OnGeneralException(ex);
            }
            return outputs;
        }
开发者ID:Microsoft,项目名称:CNTK,代码行数:56,代码来源:Program.cs

示例9: Resize

 public void Resize()
 {
     using (Bitmap TestObject = new Bitmap(@"..\..\Data\Image\Lenna.jpg"))
     {
         using (Bitmap Image = Assert.Do<Bitmap>(() => TestObject.Resize(50, Utilities.Media.Image.ExtensionMethods.BitmapExtensions.Quality.Low, @".\Testing\LennaResize.jpg")))
         {
             Assert.NotNull(Image);
             Assert.Equal(50,Image.Width);
             Assert.Equal(50, Image.Height);
         }
     }
 }
开发者ID:gwilkinson,项目名称:Craig-s-Utility-Library,代码行数:12,代码来源:BitmapExtensions.cs

示例10: EvaluateImageClassificationModel

        /// <summary>
        /// This method shows how to evaluate a trained image classification model
        /// </summary>
        public static void EvaluateImageClassificationModel()
        {
            try
            {
                // This example requires the RestNet_18 model.
                // The model can be downloaded from <see cref="https://www.cntk.ai/resnet/ResNet_18.model"/>
                // The model is assumed to be located at: <CNTK>\Examples\Image\Miscellaneous\ImageNet\ResNet 
                // along with a sample image file named "zebra.jpg".
                string workingDirectory = Path.Combine(initialDirectory, @"..\..\Examples\Image\Miscellaneous\ImageNet\ResNet");
                Environment.CurrentDirectory = initialDirectory;

                List<float> outputs;

                using (var model = new IEvaluateModelManagedF())
                {
                    string modelFilePath = Path.Combine(workingDirectory, "ResNet_18.model");
                    model.CreateNetwork(string.Format("modelPath=\"{0}\"", modelFilePath), deviceId: -1);

                    // Prepare input value in the appropriate structure and size
                    var inDims = model.GetNodeDimensions(NodeGroup.Input);
                    if (inDims.First().Value != 224 * 224 * 3)
                    {
                        throw new CNTKRuntimeException(string.Format("The input dimension for {0} is {1} which is not the expected size of {2}.", inDims.First(), inDims.First().Value, 224 * 224 * 3), string.Empty);
                    }

                    // Transform the image
                    string imageFileName = Path.Combine(workingDirectory, "zebra.jpg");
                    Bitmap bmp = new Bitmap(Bitmap.FromFile(imageFileName));

                    var resized = bmp.Resize(224, 224, true);
                    var resizedCHW = resized.ParallelExtractCHW();
                    var inputs = new Dictionary<string, List<float>>() { {inDims.First().Key, resizedCHW } };

                    // We can call the evaluate method and get back the results (single layer output)...
                    var outDims = model.GetNodeDimensions(NodeGroup.Output);
                    outputs = model.Evaluate(inputs, outDims.First().Key);
                }

                // Retrieve the outcome index (so we can compare it with the expected index)
                var max = outputs.Select((value, index) => new { Value = value, Index = index })
                    .Aggregate((a, b) => (a.Value > b.Value) ? a : b)
                    .Index;

                Console.WriteLine("Outcome: {0}", max);
            }
            catch (CNTKException ex)
            {
                Console.WriteLine("Error: {0}\nNative CallStack: {1}\n Inner Exception: {2}", ex.Message, ex.NativeCallStack, ex.InnerException != null ? ex.InnerException.Message : "No Inner Exception");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}\nCallStack: {1}\n Inner Exception: {2}", ex.Message, ex.StackTrace, ex.InnerException != null ? ex.InnerException.Message : "No Inner Exception");
            }
        }
开发者ID:CaffeineForCode,项目名称:CNTK,代码行数:57,代码来源:Program.cs

示例11: Resize

 /// <summary>
 /// Makes a scaled version of an image using BrawlLib's texture converter.
 /// </summary>
 public static Bitmap Resize(Bitmap orig, Size resizeTo)
 {
     return orig.Resize(resizeTo.Width, resizeTo.Height);
 }
开发者ID:liddictm,项目名称:BrawlManagers,代码行数:7,代码来源:BitmapUtilities.cs

示例12: EvaluateCustomDNN

        public async Task<string[]> EvaluateCustomDNN(string imageUrl)
        {
            string domainBaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            string workingDirectory = Environment.CurrentDirectory;

            try
            {
                // This example requires the RestNet_18 model.
                // The model can be downloaded from <see cref="https://www.cntk.ai/resnet/ResNet_18.model"/>
                int numThreads = 1;
                List<float> outputs;

                using (var model = new IEvaluateModelManagedF())
                {
                    // initialize the evaluation engine
                    // TODO: initializing the evaluation engine should be one only once at the beginning
                    var initParams = string.Format("numCPUThreads={0}", numThreads);
                    model.Init(initParams);

                    // load the model
                    string modelFilePath = Path.Combine(domainBaseDirectory, @"CNTK\Models\ResNet_18.model");
                    var modelOption = string.Format("modelPath=\"{0}\"", modelFilePath);
                    model.CreateNetwork(modelOption, deviceId: -1);

                    // Prepare input value in the appropriate structure and size
                    var inDims = model.GetNodeDimensions(NodeGroup.Input);
                    if (inDims.First().Value != 224 * 224 * 3)
                    {
                        throw new CNTKRuntimeException(string.Format("The input dimension for {0} is {1} which is not the expected size of {2}.", inDims.First(), inDims.First().Value, 224 * 224 * 3), string.Empty);
                    }

                    // Transform the image
                    System.Net.Http.HttpClient httpClient = new HttpClient();
                    Stream imageStream = await httpClient.GetStreamAsync(imageUrl);
                    Bitmap bmp = new Bitmap(Bitmap.FromStream(imageStream));

                    var resized = bmp.Resize(224, 224, true);
                    var resizedCHW = resized.ParallelExtractCHW();
                    var inputs = new Dictionary<string, List<float>>() { { inDims.First().Key, resizedCHW } };

                    // We can call the evaluate method and get back the results (single layer output)...
                    var outDims = model.GetNodeDimensions(NodeGroup.Output);
                    outputs = model.Evaluate(inputs, outDims.First().Key);
                }

                List<string> o = new List<string>();

                foreach (float f in outputs)
                {
                    o.Add(f.ToString());
                }

                return o.ToArray<string>();
            }
            catch (Exception ex)
            {
                return new string[] { string.Format("domainBase directory {0}, workingDirectory {1}, exception details: {2}.", domainBaseDirectory, workingDirectory, ex.ToString()) };
            }
        }
开发者ID:shadrack4292,项目名称:CNTK,代码行数:59,代码来源:ValuesController.cs

示例13: GetImage

 protected override void GetImage(out Bitmap bac)
 {
     if (TEXT.IndexOf("Blade") != -1 || TEXT.IndexOf("Swashplate") != -1)
     {
         double time = Game.TIME;
         double angle = time;
         if (TEXT.IndexOf("Blade") != -1)
         {
             double limit = UpgradeInfo.DataBase.BladeUpgradeValues[INDEX];
             if (limit != double.MaxValue)
             {
                 angle %= 2.0 * limit;
                 if (angle > limit) angle = 2.0 * limit - angle;
                 angle -= 0.5 * limit;
             }
             angle *= 2.0;
         }
         else if (TEXT.IndexOf("Swashplate") != -1)
         {
             angle = 0.5 * Math.Cos(Math.PI * time / UpgradeInfo.DataBase.SwashplateUpgradeValues[INDEX]) * Math.PI;
         }
         Bitmap bmp = Pod_Frame.Pod.GenerateImage(angle, Math.PI * Game.TIME);
         BITMAP.New(out bac,50, 50, Color.FromArgb(0, 0, 128));
         bac.Paste(bmp, bac.Half() - bmp.Half(), ImagePasteMode.Transparent);
         bac = bac.Resize(2.0);
         BitmapData data_bac = bac.GetBitmapData();
         DrawLOCKED(data_bac);
         bac.UnlockBits(data_bac);
     }
     else
     {
         Bitmap bmp; base.GetImage(out bmp);
         BITMAP.New(out bac,bmp.Width, bmp.Height, Color.FromArgb(0, 0, 128));
         bac.Paste(bmp, new Point(0, 0), ImagePasteMode.Transparent);
     }
 }
开发者ID:fsps60312,项目名称:Digging-Game-2,代码行数:36,代码来源:Upgrade+Plant.cs

示例14: ImportFromBitmap

        public void ImportFromBitmap(Bitmap bitmap, CompressionMethod compression = CompressionMethod.RLE)
        {
            if (bitmap.Width <= 32 || bitmap.Height <= 32) { bitmap = bitmap.Resize(64, 64); }

            width = bitmap.Width;
            height = bitmap.Height;

            int planeCount = 4;// Image.GetPixelFormatSize(bitmap.PixelFormat) / 8;

            if (bitmap.Width < 8 && bitmap.Height < 8) { planeCount = 1; }

            BitmapData bmpdata = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            byte[] iB = new byte[4 * bmpdata.Width * bmpdata.Height];
            Marshal.Copy(bmpdata.Scan0, iB, 0, bmpdata.Stride * bmpdata.Height);
            bitmap.UnlockBits(bmpdata);

            Parallel.For(0, planeCount,
                i =>
                //for (int i = 0; i < planeCount; i++)
                {
                    var plane = new Plane(i);
                    plane.Data = iB.ToList().Every(planeCount, i).ToArray();
                    plane.Compress(planeCount > 1 ? compression : CompressionMethod.None);
                    planes.Add(plane);
                }
            );

            switch (planeCount)
            {
                case 1:
                    planeFormat = PlaneFormat.Format1planeARGB;
                    break;

                case 3:
                    planeFormat = PlaneFormat.Format4planeXRGB;
                    break;

                case 4:
                    planeFormat = PlaneFormat.Format4planeARGB;
                    break;
            }
        }
开发者ID:DevilboxGames,项目名称:ToxicRagers,代码行数:42,代码来源:sIMG.cs

示例15: CreateSidebarImage

 private static Bitmap CreateSidebarImage(Bitmap source)
 {
     return source.Resize(46, 46);
 }
开发者ID:juan2202,项目名称:LeagueSharp-Standalones,代码行数:4,代码来源:ImageLoader.cs


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