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


C# Bitmap.GetThumbnailImage方法代码示例

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


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

示例1: AddPicture

        public bool AddPicture(string ImagePath)
        {
            Bitmap bm = new Bitmap(ImagePath);
            Label lb =new Label();

            width=0;height=0;
            folderparts= ImagePath.Split('\\');
            PictureBox pb = new PictureBox();
            pb.Name = pictureBoxNumber .ToString();
            pb.BorderStyle = BorderStyle.FixedSingle;
            height=this.Height-50;
            width = height;//Convert.ToInt32(height*0.70);
            pb.Size = new Size(width,height);
            pb.Location = new Point(pictureBoxOffset,5);
            lb.Text = folderparts[folderparts.GetLength(0)-1];
            lb.Size = new Size(width,15);
            lb.Location = new Point(pictureBoxOffset,height+2);
            pb.SizeMode = PictureBoxSizeMode.CenterImage;
            if(bm.Height>bm.Width)
            {
                pb.Image = (Image)bm.GetThumbnailImage(Convert.ToInt32(((float)height/(float)bm.Height)*bm.Width),height,null,IntPtr.Zero);
            }
            else
            {
                pb.Image = (Image)bm.GetThumbnailImage(width,Convert.ToInt32(((float)width/(float)bm.Width)*bm.Height),null,IntPtr.Zero);
            }
            pb.Click +=new EventHandler(Image_Click);
            pictureBoxOffset = pictureBoxOffset + width + 21;
            this.FilmStripPanel.Controls.Add(pb);
            this.FilmStripPanel.Controls.Add(lb);
            pictureBoxNumber++;
            return true;
        }
开发者ID:joelmatton,项目名称:Worship_Media,代码行数:33,代码来源:FilmStrip.cs

示例2: ResizeBitmap

 public static Bitmap ResizeBitmap(Bitmap bitmap, Rectangle srcRect, Size newSize)
 {
     if (srcRect.Size.Height <= 0 || srcRect.Size.Width <= 0)
     {
         throw new ArgumentOutOfRangeException("sourceRectangle.Size", srcRect.Size, "sourceRectangle.Size <= (0,0)");
     }
     if (newSize.Height <= 0 || newSize.Width <= 0)
     {
         throw new ArgumentOutOfRangeException("newSize", newSize, "newSize <= (0,0)");
     }
     if (srcRect.Location.IsEmpty && srcRect.Size == bitmap.Size)
     {
         if (srcRect.Size == newSize)
         {
             return new Bitmap(bitmap);
         }
         using (Image image = bitmap.GetThumbnailImage(newSize.Width, newSize.Height, null, IntPtr.Zero))
         {
             return new Bitmap(image);
         }
     }
     using (Bitmap bmp = new Bitmap(srcRect.Width, srcRect.Height, PixelFormat.Format32bppArgb))
     {
         using (Graphics g = Graphics.FromImage(bmp))
         {
             g.Clear(Color.Transparent);
             g.DrawImage(bitmap, new Rectangle(Point.Empty, srcRect.Size), srcRect, GraphicsUnit.Pixel);
         }
         using (Image image = bmp.GetThumbnailImage(newSize.Width, newSize.Height, null, IntPtr.Zero))
         {
             return new Bitmap(image);
         }
     }
 }
开发者ID:xieguigang,项目名称:Reference_SharedLib,代码行数:34,代码来源:ControlPaint.cs

示例3: GetThumbnail

 public static Bitmap GetThumbnail(int width, int height, string filter, string caption, ImageFormat format, Image b)
 {
     Bitmap source = new Bitmap(b);
     source = new Bitmap(source.GetThumbnailImage(width, height, null, IntPtr.Zero));
     if (format == ImageFormat.Gif)
     {
         source = new OctreeQuantizer(0xff, 8).Quantize(source);
     }
     if ((filter.Length > 0) && filter.ToUpper().StartsWith("SHARPEN"))
     {
         string str = filter.Remove(0, 7).Trim();
         int nWeight = (str.Length > 0) ? Convert.ToInt32(str) : 11;
         BitmapFilter.Sharpen(source, nWeight);
     }
     if (caption.Length <= 0)
     {
         return source;
     }
     using (Graphics graphics = Graphics.FromImage(source))
     {
         StringFormat format2 = new StringFormat();
         format2.Alignment = StringAlignment.Center;
         format2.LineAlignment = StringAlignment.Center;
         using (Font font = new Font("Arial", 12f))
         {
             graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; 
             graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, 0, 0, 0)), 0, source.Height - 20, source.Width, 20);
             graphics.DrawString(caption, font, Brushes.White, 0f, (float)(source.Height - 20));
             return source;
         }
     }
 }
开发者ID:BaoToan94,项目名称:q42.wheels.gimmage,代码行数:32,代码来源:ThumbnailGenerator.cs

示例4: GetThumbnail

 private void GetThumbnail(PaintEventArgs e)
 {
     Image.GetThumbnailImageAbort callback =
         new Image.GetThumbnailImageAbort(ThumbnailCallback);
     if (flag == 1)
     {
         for (int j = 0; j < 4; ++j)
         {
             for (int i = 0; i < 4; ++i)
             {
                 Image image = new Bitmap(filePaths[j * 4 + i]);
                 Image pThumbnail = image.GetThumbnailImage(200, 150, callback, new
                    IntPtr());
                 //label1.Text = filePaths[j*2 +i];
                 e.Graphics.DrawImage(
                    pThumbnail,
                    i * 230 + 20,
                    j * 160 + 10,
                    pThumbnail.Width,
                    pThumbnail.Height);
                 image = null;
                 pThumbnail = null;
                 GC.Collect();
             }
         }
     }
 }
开发者ID:kunalgrover05,项目名称:Windows-Photo-viewer,代码行数:27,代码来源:Form1.cs

示例5: scaleBitmap

        private Bitmap scaleBitmap(Bitmap bmp, PictureBox picBox)
        {
            float ratio = 1.0f;
            int thumbHeight = 0;
            int thumbWidth = 0;

            if (bmp.Height > picBox.Height || bmp.Width > picBox.Width)
            {
                Image.GetThumbnailImageAbort myCallback =
                    new Image.GetThumbnailImageAbort(ThumbnailCallback);

                if (bmp.Height >= bmp.Width)
                {
                    ratio = (((float)bmp.Width) / ((float)bmp.Height));
                    thumbHeight = picBox.Height;
                    thumbWidth = (int)((thumbHeight) * (ratio));
                }
                else
                {
                    ratio = (((float)bmp.Height) / ((float)bmp.Width));
                    thumbWidth = picBox.Width;
                    thumbHeight = (int)((thumbWidth) * (ratio));
                }

                Image myThumbnail = bmp.GetThumbnailImage(thumbWidth, thumbHeight, myCallback, IntPtr.Zero);
                return new Bitmap(myThumbnail);
            }
            return bmp;
        }
开发者ID:radol91,项目名称:BitMapEditorSolution,代码行数:29,代码来源:FormViewer.cs

示例6: Load

		public void Load()
		{
			var files = _root.GetLocalFiles().ToList();

			var titleFile = files.First(file => file.Name == "title.txt");
			Name = File.ReadAllText(titleFile.LocalPath).Trim();

			var toolTipFile = files.FirstOrDefault(file => file.Name == "tip.txt");
			if (toolTipFile != null)
			{
				var tooltipLines = File.ReadAllLines(toolTipFile.LocalPath);
				ToolTipHeader = tooltipLines.ElementAtOrDefault(0)?.Replace("*", "");
				ToolTipBody = tooltipLines.ElementAtOrDefault(1)?.Replace("*", "");
			}

			int tempInt;
			if (Int32.TryParse(Path.GetFileName(_root.LocalPath), out tempInt))
				Order = tempInt;

			LogoFile = files.FirstOrDefault(file => file.Extension == ".png" && !file.Name.Contains("_rbn"));
			if (LogoFile != null)
			{
				Logo = new Bitmap(LogoFile.LocalPath);
				BrowseLogo = Logo.GetThumbnailImage((Logo.Width * 144) / Logo.Height, 144, null, IntPtr.Zero);

				var borderedLogo = Logo.DrawBorder();

				RibbonLogo = borderedLogo.GetThumbnailImage((borderedLogo.Width * 72) / borderedLogo.Height, 72, null, IntPtr.Zero);
				AdBarLogo = borderedLogo.GetThumbnailImage((borderedLogo.Width * 86) / borderedLogo.Height, 86, null, IntPtr.Zero);
			}
			_masterFile = files.FirstOrDefault(file => file.Extension == ".pptx");
		}
开发者ID:w01f,项目名称:VolgaTeam.Dashboard,代码行数:32,代码来源:SlideMaster.cs

示例7: Load

        public Texture2D Load()
        {
            Bitmap bitmap = new Bitmap(fileName);
            Bitmap smallBitmap = null;

            if (maxSize != 0)
            {
                // make the image smaller to need less RAM
                Size newSize;

                float aspectRatio = (float)bitmap.Width / (float)bitmap.Height;
                if (aspectRatio > 1) newSize = new Size(maxSize, (int)Math.Round(maxSize / aspectRatio));
                else newSize = new Size((int)Math.Round(maxSize * aspectRatio), maxSize);

                if(maxSize < 200) smallBitmap = new Bitmap(bitmap.GetThumbnailImage(newSize.Width, newSize.Height, null, IntPtr.Zero));
                else smallBitmap = new Bitmap(bitmap, newSize);

                bitmap.Dispose();
                bitmap = null;
            }

            if (bitmap == null)
            {
                texture = ConvertToTexture(smallBitmap);
                smallBitmap.Dispose();
            }
            else
            {
                texture = ConvertToTexture(bitmap);
                bitmap.Dispose();
            }

            GC.Collect();
            return texture;
        }
开发者ID:JacquesLucke,项目名称:Collage,代码行数:35,代码来源:ImageLoader.cs

示例8: SaveTumb

        public void SaveTumb(string reference, ImageList imageList)
        {
            this.Url = [email protected]"https://www.google.se/search?q=product+search&ie=utf-8&oe=utf-8&client=firefox-b&gfe_rd=cr&ei=pJCtV_-sHOzk8AfgsISoDw#q={reference}";
            if (this.ShowDialog() == DialogResult.OK) {
                var format = IsImage(this.Url);

                if (format!=null) {
                    WebClient client = new WebClient();
                    var data = client.DownloadData(this.Url);

                    var index = this.Url.LastIndexOf(".");
                    var extension = this.Url.Substring(index).ToLower();

                    using (System.IO.MemoryStream stream = new System.IO.MemoryStream(data)) {
                        System.Drawing.Image bmp = new Bitmap(stream);
                        var image = bmp.GetThumbnailImage(32, 32, callbackAbort, IntPtr.Zero);
                        image.Save($"{AppDomain.CurrentDomain.BaseDirectory}Images/{reference}.png", format);

                        imageList.Images.RemoveByKey(reference);
                        imageList.Images.Add(reference, image);

                    }

                }
            }
        }
开发者ID:Zerq,项目名称:InventorySystem,代码行数:26,代码来源:Browser.cs

示例9: GetThumbnail

        public static Bitmap GetThumbnail(Bitmap bmpImage, Size size)
        {
            double width = bmpImage.Width;
             double height = bmpImage.Height;

             Double xFactor = new Double();
             Double yFactor = new Double();
             xFactor = (double)size.Width / width;
             yFactor = (double)size.Height / height;

             Double scaleFactor = Math.Min(xFactor, yFactor);

             Size scaledSize = new Size();
             scaledSize.Width = Convert.ToInt32(width * scaleFactor);
             scaledSize.Height = Convert.ToInt32(height * scaleFactor);

             Bitmap scaledOriginal = (Bitmap) bmpImage.GetThumbnailImage(scaledSize.Width, scaledSize.Height, new Image.GetThumbnailImageAbort(target), IntPtr.Zero);
             Bitmap thumnailBmp = new Bitmap(size.Width, size.Height);

             for (int y = 0; y < thumnailBmp.Height; y++)
             {
            for (int x = 0; x < thumnailBmp.Width; x++)
            {
               if ((x < scaledOriginal.Width) && (y < scaledOriginal.Height))
               {
                  thumnailBmp.SetPixel(x, y, scaledOriginal.GetPixel(x, y));
               }
               else
               {
                  thumnailBmp.SetPixel(x, y, Color.Transparent);
               }
            }
             }
             return thumnailBmp;
        }
开发者ID:MarkPaxton,项目名称:MCP-shared,代码行数:35,代码来源:JpegImage.Desktop.cs

示例10: Thumbnail

 public ActionResult Thumbnail(string path)
 {
     var myCallback =
         new Image.GetThumbnailImageAbort(ThumbnailCallback);
     var paths = new List<string>(2);
     BuildPath(path, out folderPath, out resourcePath);
     var folder = session.OpenFolder(folderPath + "/");
     var resource = folder.GetResource(resourcePath + "/");
     var sourceStream = resource.GetReadStream();
     Bitmap bitmap = null;
     try
     {
         bitmap = new Bitmap(sourceStream);
     }
     catch (Exception)
     {
         var fs = new FileStream(Server.MapPath("~/Content/kendo/2014.2.716/Bootstrap/imagebrowser.png"), FileMode.Open);
         var tempBs = new byte[fs.Length];
         fs.Read(tempBs, 0, tempBs.Length);
         return new FileContentResult(tempBs, "image/jpeg");
     }
     var myThumbnail = bitmap.GetThumbnailImage(84, 70, myCallback, IntPtr.Zero);
     var ms = new MemoryStream();
     var myEncoderParameters = new EncoderParameters(1);
     var myEncoderParameter = new EncoderParameter(Encoder.Quality, 25L);
     myEncoderParameters.Param[0] = myEncoderParameter;
     myThumbnail.Save(ms, GetEncoderInfo("image/jpeg"), myEncoderParameters);
     ms.Position = 0;
     var bytes = ms.ToArray();
     return new FileContentResult(bytes, "image/jpeg");
 }
开发者ID:lxh2014,项目名称:gigade-net,代码行数:31,代码来源:ImageBrowserController.cs

示例11: ReadImage

        /// <summary>
        /// Reads the image.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="ordinalPosition">The ordinal position.</param>
        /// <param name="generateThumbnail">if set to <c>true</c> [generate thumbnail].</param>
        /// <returns>System.Byte[][].</returns>
        public static byte[] ReadImage(IDataReader reader, int ordinalPosition, bool generateThumbnail = false)
        {
            if (reader == null)
                return null;

            if (string.IsNullOrEmpty(reader.GetValue(ordinalPosition).ToString()))
                return new byte[] { };

            var blob = ((OracleDataReader)reader).GetOracleBlob(ordinalPosition);

            var byteArr = new byte[blob.Length];

            blob.Read(byteArr, 0, Convert.ToInt32(blob.Length));

            using (var stream = new MemoryStream(byteArr))
            {
                var retVal = stream.ToArray();

                if (generateThumbnail && stream.Length > 0)
                {
                    var bitmap = new Bitmap(stream);
                    var image = bitmap.GetThumbnailImage(50, 50, AdoHelper.ThumbnailCallback, IntPtr.Zero);

                    using (var ms = new MemoryStream())
                    {
                        image.Save(ms, ImageFormat.Png);
                        return ms.ToArray();
                    }
                }

                return retVal;
            }
        }
开发者ID:mparsin,项目名称:Elements,代码行数:40,代码来源:OracleImageReader.cs

示例12: GenerateThumbnail

        public void GenerateThumbnail(Stream imgFileStream, Stream thumbStream)
        {
            Image.GetThumbnailImageAbort callback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
            Bitmap bitmap = new Bitmap(imgFileStream);
            int thumbWidth = MaxThumbWidth;
            int thumbHeight = MaxThumbHeight;
            if (bitmap.Width > bitmap.Height)
            {
                thumbHeight = Decimal.ToInt32(((Decimal)bitmap.Height / bitmap.Width) * thumbWidth);
                if (thumbHeight > MaxThumbHeight)
                {
                    thumbHeight = MaxThumbHeight;
                }
            }
            else
            {
                thumbWidth = Decimal.ToInt32(((Decimal)bitmap.Width / bitmap.Height) * thumbHeight);
                if (thumbWidth > MaxThumbWidth)
                {
                    thumbWidth = MaxThumbWidth;
                }
            }

            Image thumbnail = bitmap.GetThumbnailImage(thumbWidth, thumbHeight, callback, IntPtr.Zero);

            thumbnail.Save(thumbStream,ImageFormat.Jpeg);
        }
开发者ID:TellagoDevLabs,项目名称:CloudPoint,代码行数:27,代码来源:ImageProcessor.cs

示例13: SizeScaling

 public Image SizeScaling(Bitmap image, int width, int height, bool distorted)
 {
     try
     {
         double realRatio = ((double) image.Height)/((double) image.Width);
         if (width != 0 & height != 0)
         {
             if (distorted) return image.GetThumbnailImage(width, height, ThumbnailCallback, IntPtr.Zero);
             var heightAfterRatio = (int) Math.Floor(realRatio*width);
             var widthAfterRatio = (int) Math.Floor(height/realRatio);
             using (var mem1 = new MemoryStream())
             {
                 using (var mem2 = new MemoryStream())
                 {
                     image.Save(mem1, ImageFormat.Tiff);
                     ImageBuilder.Current.Build(new ImageJob(mem1, mem2,
                         new ResizeSettings(widthAfterRatio, heightAfterRatio, FitMode.None, null)));
                     return Image.FromStream(mem2);
                 }
             }
             //return image.GetThumbnailImage(widthAfterRatio, heightAfterRatio, ThumbnailCallback, IntPtr.Zero);
         }
         if (width != 0)
         {
             var heightAfterRatio = (int) Math.Floor(realRatio*width);
             using (var mem1 = new MemoryStream())
             {
                 using (var mem2 = new MemoryStream())
                 {
                     image.Save(mem1, ImageFormat.Jpeg);
                     ImageBuilder.Current.Build(new ImageJob(mem1, mem2,
                         new ResizeSettings(width, heightAfterRatio, FitMode.None, null)));
                     return Image.FromStream(mem2);
                 }
             }
             //return image.GetThumbnailImage(width, heightAfterRatio, ThumbnailCallback, IntPtr.Zero);
         }
         if (height != 0)
         {
             var widthAfterRatio = (int) Math.Floor(height/realRatio);
             using (var mem1 = new MemoryStream())
             {
                 using (var mem2 = new MemoryStream())
                 {
                     image.Save(mem1, ImageFormat.Jpeg);
                     ImageBuilder.Current.Build(new ImageJob(mem1, mem2,
                         new ResizeSettings(widthAfterRatio, height, FitMode.None, null)));
                     return Image.FromStream(mem2);
                 }
             }
             //return image.GetThumbnailImage(widthAfterRatio, height, ThumbnailCallback, IntPtr.Zero);
         }
         return image;
     }
     catch (Exception ex)
     {
         return image;
     }
 }
开发者ID:CheViana,项目名称:ImageServer,代码行数:59,代码来源:ScalingProcessor.cs

示例14: Example_GetThumb

        public void Example_GetThumb(PaintEventArgs e)
        {
            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
            Bitmap myBitmap = new Bitmap("Climber.jpg");
            Image myThumbnail = myBitmap.GetThumbnailImage(40, 40, myCallback, IntPtr.Zero);

            e.Graphics.DrawImage(myThumbnail, 150, 75);
        }
开发者ID:engineer9090909090909090,项目名称:foxriver,代码行数:8,代码来源:Form1.cs

示例15: WebBrowser_DocumentCompleted

 private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
     WebBrowser m_WebBrowser = (WebBrowser)sender;
     m_WebBrowser.ClientSize = new Size(this.m_BrowserWidth, this.m_BrowserHeight);
     m_WebBrowser.ScrollBarsEnabled = false;
     m_Bitmap = new Bitmap(m_WebBrowser.Bounds.Width, m_WebBrowser.Bounds.Height);
     m_WebBrowser.BringToFront();
     m_WebBrowser.DrawToBitmap(m_Bitmap, m_WebBrowser.Bounds);
     m_Bitmap = (Bitmap)m_Bitmap.GetThumbnailImage(m_ThumbnailWidth, m_ThumbnailHeight, null, IntPtr.Zero);
 }
开发者ID:hexiaohe,项目名称:CommonTest,代码行数:10,代码来源:WebSiteThumbnail.cs


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