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


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

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


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

示例1: ProcessRequestAsync

 public override async Task ProcessRequestAsync(HttpContext context)
 {
     System.Drawing.Bitmap myBitmap = null;
     MemoryStream objMemoryStream = null;
     try
     {
         var strImageFileName = context.Request.QueryString["ImageUrl"].ToString();
         var height = context.Request.QueryString["height"];
         var width = context.Request.QueryString["width"];
         //create callback handler
         var myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
         //creat BitMap object from image path passed in querystring
         myBitmap =
            new System.Drawing.Bitmap(
                context.Server.MapPath("~/Images/Users/" + strImageFileName));
         //create unit object for height and width. This is to convert parameter passed in differen unit like pixel, inch into generic unit.
         var widthUnit = System.Web.UI.WebControls.Unit.Parse(width);
         var heightUnit = System.Web.UI.WebControls.Unit.Parse(height);
         //Resize actual image using width and height paramters passed in querystring
         var myThumbnail = myBitmap.GetThumbnailImage(Convert.ToInt16(widthUnit.Value),
             Convert.ToInt16(heightUnit.Value), myCallback, IntPtr.Zero);
         //Create memory stream and save resized image into memory stream
         objMemoryStream = new System.IO.MemoryStream();
         myThumbnail.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Png);
         //Declare byte array of size memory stream and read memory stream data into array
         var imageData = new byte[objMemoryStream.Length];
         objMemoryStream.Position = 0;
         await objMemoryStream.ReadAsync(imageData, 0, (int)objMemoryStream.Length);
         //send contents of byte array as response to client (browser)
         context.Response.BinaryWrite(imageData);
         myBitmap.Dispose();
     }
     catch
     {
         context.Response.End();
     }
     finally
     {
         if (objMemoryStream != null)
             objMemoryStream.Dispose();
         if (myBitmap != null)
             myBitmap.Dispose();
     }
 }
开发者ID:rabbal,项目名称:AspNetWebForms-Forum,代码行数:44,代码来源:ImageHandler.ashx.cs

示例2: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.QueryString["LogoType"] != null && context.Request.QueryString["UserName"] != null)
            {
                string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlConstr"].ConnectionString;
                UserPermissions UserPermissions = UserPermission.SelectByField("UserName", context.Request.QueryString["UserName"].ToString(), ConnectionString);
                if (context.Request.QueryString["LogoType"] == "Master")
                    Image = (byte[])UserPermissions[0].MasterLogo;
                else
                    Image = (byte[])UserPermissions[0].ChildLogo;

                System.Drawing.Bitmap uploadedimage = new System.Drawing.Bitmap(convertByteArrayToStream(Image));

                int w = uploadedimage.Width;
                int h = uploadedimage.Height;

                float destHeight = float.Parse(h.ToString());
                float destWidth = float.Parse(w.ToString());
                if (w > 111 || h > 60)
                {
                    //System.Drawing.Bitmap uploadedimage = new System.Drawing.Bitmap(convertByteArrayToStream(Image));
                    System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                    System.Drawing.Image thumbNailImg = uploadedimage.GetThumbnailImage(111, 60, dummyCallBack, IntPtr.Zero);
                    MemoryStream mstream = new MemoryStream();
                    thumbNailImg.Save(mstream, ImageFormat.Jpeg);
                    byte[] image2 = mstream.ToArray();
                    HttpContext.Current.Response.ContentType = "image/jpeg";
                    HttpContext.Current.Response.BinaryWrite(image2);
                }
                else
                {
                    MemoryStream mstream = new MemoryStream(Image, true);

                    mstream.Write(Image, 0, Image.Length);

                    HttpContext.Current.Response.ContentType = "image/jpeg";
                    HttpContext.Current.Response.BinaryWrite(Image);
                }
            }
            else
                throw new ArgumentException("No parameter specified");
        }
开发者ID:shekar348,项目名称:1PointOne,代码行数:42,代码来源:ShowLogo.ashx.cs

示例3: BrowseImage_Click

        private void BrowseImage_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            // Configure save file dialog box            
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = "."; // Default file extension
            dlg.Filter = "Imagefiles (*.bmp, *.jpg, *.png, *.tif, *.tiff, *.tga, *.pgm)|*.bmp;*.jpg;*.png;*.tif;*.tiff;*.tga;*.pgm"; // Filter files by extension
            dlg.Title = "Load image";

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                System.Drawing.Bitmap emoticon = new System.Drawing.Bitmap(dlg.FileName);                

                const int thumbnailWidth = 50;
                const int thumbnailHeight = 50;

                System.Drawing.Image.GetThumbnailImageAbort tc = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                System.Drawing.Image thumbnail = emoticon.GetThumbnailImage(thumbnailWidth, thumbnailHeight, tc, IntPtr.Zero);
                
                System.IO.MemoryStream ms = new System.IO.MemoryStream();                
                thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                Console.WriteLine("Length: " + ms.ToArray().Length);

                int oid = Convert.ToInt32(button.DataContext);

                TrainingDataSet.ExpressionRow row = _DataSet.Expression.FindByExpressionOID(oid);

                if (row != null && !DBNull.Value.Equals(row))
                {
                    row.Thumbnail = ms.ToArray();
                }

            }  
        }
开发者ID:shardulchauhan007,项目名称:klucv2,代码行数:40,代码来源:ExpressionsDialog.xaml.cs

示例4: GetThumbnail

 /// <summary>
 /// 获取等比例缩放图片
 /// </summary>
 /// <param name="imgPath">待缩放图片路径</param>
 /// <param name="format">缩放图片保存的格式</param>
 /// <param name="scaling">要保持的宽度或高度</param>
 /// <param name="keepWidthOrHeight">
 /// 如果为true则保持宽度为scaling,否则保持高度为scaling</param>
 /// <returns>System.Drawing.Bitmap 类型,不受多线程UI限制</returns>
 public static System.Drawing.Bitmap GetThumbnail(
     string imgPath,
     System.Drawing.Imaging.ImageFormat format,
     int scaling,
     bool keepWidthOrHeight)
 {
     try
     {
         System.Drawing.Bitmap source;
         using (System.Drawing.Bitmap myBitmap = new System.Drawing.Bitmap(imgPath))
         {
             int width = 0;
             int height = 0;
             int tw = myBitmap.Width;//图像的实际宽度
             int th = myBitmap.Height;//图像的实际高度
             if (keepWidthOrHeight)//保持宽度
             {
                 #region 自动保持宽度
                 if (scaling >= tw)
                 {
                     width = tw;
                     height = th;
                 }
                 else
                 {
                     double ti = Convert.ToDouble(tw) / Convert.ToDouble(scaling);
                     if (ti == 0d)
                     {
                         width = tw;
                         height = th;
                     }
                     else
                     {
                         width = scaling;
                         height = Convert.ToInt32(Convert.ToDouble(th) / ti);
                     }
                 }
                 #endregion
             }
             else
             {
                 #region 自动保持高度
                 if (scaling >= th)
                 {
                     width = tw;
                     height = th;
                 }
                 else
                 {
                     double ti = Convert.ToDouble(th) / Convert.ToDouble(scaling);
                     if (ti == 0d)
                     {
                         width = tw;
                         height = th;
                     }
                     else
                     {
                         width = Convert.ToInt32(Convert.ToDouble(tw) / ti);
                         height = scaling;
                     }
                 }
                 #endregion
             }
             using (System.Drawing.Image myThumbnail = myBitmap.GetThumbnailImage(
                 width, height, () => { return false; }, IntPtr.Zero))
             {
                 MemoryStream ms = new MemoryStream();
                 myThumbnail.Save(ms, format);
                 source = new System.Drawing.Bitmap(ms);
                 ms.Close();
             }
         }
         return source;
     }
     catch
     {
         return null;
     }
 }
开发者ID:jiailiuyan,项目名称:Jisons,代码行数:88,代码来源:Global.cs

示例5: btnSave_Click

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                UserProfileInfo objinfo = new UserProfileInfo();
                string filename = "";
                string thumbTarget = Server.MapPath("~/Modules/Admin/UserManagement/UserPic");
                if (!Directory.Exists(thumbTarget))
                {
                    Directory.CreateDirectory(thumbTarget);
                }
                System.Drawing.Image.GetThumbnailImageAbort thumbnailImageAbortDelegate = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                if (fuImage.HasFile)
                {
                    double fs = fuImage.PostedFile.ContentLength / (1024 * 1024);
                    if (fs > 3)
                    {
                        ShowHideProfile();
                        ShowMessage("", GetSageMessage("UserManagement", "ImageTooLarge"), "", SageMessageType.Alert);
                        return;
                    }
                    else
                    {
                        filename = fuImage.PostedFile.FileName.Substring(fuImage.PostedFile.FileName.LastIndexOf("\\") + 1);
                        imgUser.ImageUrl = "~/Modules/Admin/UserManagement/UserPic/" + filename;
                        using (System.Drawing.Bitmap originalImage = new System.Drawing.Bitmap(fuImage.PostedFile.InputStream))
                        {
                            using (System.Drawing.Image thumbnail = originalImage.GetThumbnailImage(200, 150, thumbnailImageAbortDelegate, IntPtr.Zero))
                            {
                                thumbnail.Save(System.IO.Path.Combine(thumbTarget, fuImage.FileName));
                            }
                        }
                    }
                }
                if (filename == "")
                {
                    if (Session[SessionKeys.UserImage] != null)
                    {
                        filename = Session[SessionKeys.UserImage].ToString();
                    }
                    btnDeleteProfilePic.Visible = false;
                }
                else
                {
                    btnDeleteProfilePic.Visible = true;
                }
                objinfo.Image = filename;
                objinfo.UserName = hdnEditUsername.Value;
                objinfo.FirstName = txtFName.Text;
                objinfo.LastName = txtLName.Text;
                objinfo.FullName = txtFullName.Text;
                objinfo.Location = txtLocation.Text;
                objinfo.AboutYou = txtAboutYou.Text;
                objinfo.Email = txtEmail1.Text + (txtEmail2.Text != "" ? "," + txtEmail2.Text : "") + (txtEmail3.Text != "" ? ',' + txtEmail3.Text : "");
                objinfo.ResPhone = txtResPhone.Text;
                objinfo.MobilePhone = txtMobile.Text;
                objinfo.Others = txtOthers.Text;
                objinfo.AddedOn = DateTime.Now;
                objinfo.AddedBy = GetUsername;
                objinfo.UpdatedOn = DateTime.Now;
                objinfo.PortalID = GetPortalID;
                objinfo.UpdatedBy = GetUsername;
                objinfo.BirthDate = txtBirthDate.Text == string.Empty ? DateTime.Parse(falseDate) : DateTime.Parse(txtBirthDate.Text);
                objinfo.Gender = rdbGender.SelectedIndex;
                UserProfileController.AddUpdateProfile(objinfo);
                LoadUserDetails();
                GetSageUserInfo(hdnEditUsername.Value);
                tblEditProfile.Visible = false;
                //LoadUserDetails();
                tblViewProfile.Visible = true;
                imgProfileEdit.Visible = false;
                imgProfileView.Visible = true;
                btnDeleteProfilePic.Visible = false;
                //ShowHideProfile();
                //btnDeleteProfilePic.Visible = true;
                Session[SessionKeys.UserImage] = null;
                ShowMessage(SageMessageTitle.Information.ToString(), GetSageMessage("UserManagement", "UserProfileSavedSuccessfully"), "", SageMessageType.Success);
            }
            catch (Exception)
            {

                throw;
            }


        }
开发者ID:xiaoxiaocoder,项目名称:AspxCommerce2.7,代码行数:86,代码来源:ctl_ManageUser.ascx.cs

示例6: SaveScreenThumbnail

 /// <summary>
 /// 获取屏幕缩略图(默认保存格式,实测1920*1080【长宽都只保留50%】分辨率,缩略图文件大小为157K,文件大小中等)
 /// </summary>
 /// <param name="ScreenFilePath">截图文件保存路径</param>
 /// <returns>是否执行成功</returns>
 public static bool SaveScreenThumbnail(string ScreenFilePath)
 {
     try
     {
         System.Drawing.Rectangle bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
         System.Drawing.Bitmap image = new System.Drawing.Bitmap(bounds.Width, bounds.Height);
         using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image))
         {
             graphics.CopyFromScreen(0, 0, 0, 0, bounds.Size);
         }
         System.IntPtr callbackData = new System.IntPtr(0);
         image.GetThumbnailImage(bounds.Width / 2, bounds.Height / 2, null, callbackData).Save(ScreenFilePath);
         return true;
     }
     catch (System.Exception)
     {
         return false;
     }
 }
开发者ID:yanyuzhy,项目名称:LolAutoPlay,代码行数:24,代码来源:My.cs


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