C#中的缩略图 [英] Thumbnail image in c#

查看:106
本文介绍了C#中的缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发一个在WPF中上传图像的应用程序.

上传后,我需要将原始图像保留为缩略图,然后可以使用放大和缩小来缩放该图像.

请给我建议任何链接或方式.

我正在使用WPF2010.

谢谢
Sophia



I am developing an application to upload an image in WPF .

I need to keep the original image as a thumbnail image after i upload and then later that image can be zoomed using zoom in and zoom out.

Please suggest me any links or way for this .

I am using WPF 2010 .

Thanks
Sophia

推荐答案

HI Sophia,

我想给出一些基本的想法,以将需求实现为代码,

我在Silverlight中尝试过,但没有在WPF中尝试过.因此,在这里我将为您介绍在Silverlight上所做的事情.

尝试一下:

文件上传后,

步骤1:读取实际的宽度和高度,并将其存储在变量中.
第2步:现在减小图像尺寸(例如:128x128)并将其放置在缩略图框中.
第3步:在表单中放置两个按钮,以方便或水平移动滑块(如果您知道的话)
第4步:在Button_Click()中将宽度和高度增加10px/Click,或者如果其Slider尝试使用Slider_Change()

希望这对您有帮助,如果您希望我为您放置Silverlight代码.
HI Sophia,

I would like to give some basic idea to implement the requirement into code,

I tried in silverlight, but not in WPF. So i''ll give what i did on Silverlight for you here.

Just try this:

Once file is uploaded,

Step 1: Read the actual width and height and store it in variable.
Step 2: Now reduce the image size(eg: 128x128) and place it in thumbnail picture box.
Step 3: Place two button in the form for your convenient or horizontal slider(if you aware of it)
Step 4: In Button_Click() increase the width and height by 10px/Click or if its Slider try Slider_Change()

Hope this could be helpful, if u want i''ll place the silverlight code for you.


这不是Silverlight代码.....

试试这个C#代码,

第一名List控件(显示图像列表),Textbox控件,3个按钮(一个用于浏览,一个用于Zoomin,一个用于ZoomOut)

请注意更改控件名称.

现在尝试以下代码:

This is not Silverlight code.....

Try this C# code,

First place List control(Display list of images),Textbox control, 3 buttons(One for Browse,One for Zoomin, one for ZoomOut)

Note change the name of the control resp.

Now try this code:

private void btnBrowse_Click(object sender, EventArgs e)
       {

           lstImagename.Items.Clear();

           if(dlgFolder.ShowDialog() == DialogResult.OK)
           {
               var filePaths = Directory.GetFiles(strFldrpath, "*.*", SearchOption.AllDirectories)
           .Where(s => s.EndsWith(".gif") || s.EndsWith(".jpg") || s.EndsWith(".bmp"));

               //string[] filePaths = Directory.GetFiles(strFldrpath, strExt);
               int length = filePaths.Count();
               int i = 0;
               while (length > i)
               {

                   lstImagename.Items.Add(new FileInfo(filePaths.ElementAt(i).ToString()).Name);
                   i++;
               }
               if (lstImagename.Items.Count == 0)
               {
                   MessageBox.Show("Image(s) not available", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
                   DialogResult resYesNo;
                  resYesNo = MessageBox.Show("Do you want to continue ", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                  if (resYesNo == DialogResult.Yes)
                  {
                      btnBrowse_Click(sender, e);
                  }
                  else
                  {
                  //Nothing in here
                      txtFldrpath.Text = "";

                  }
               }
               txtFldrpath.Text = strFldrpath;
               }
            }

      private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
       {
           strImgName = txtFldrpath.Text + "\\" + lstImagename.SelectedItem;
           pbxImg.Image = Image.FromFile(strImgName);
       }

      private void buttin_Click(object sender, EventArgs e)
      {
          if ((pbxImg.Width <= 322) & (pbxImg.Height <= 290))
          {
              pbxImg.Width = pbxImg.Width + 10;
              pbxImg.Height = pbxImg.Height + 10;
          }
      }

      private void buttout_Click(object sender, EventArgs e)
      {
          if ((pbxImg.Width >= 1) & (pbxImg.Height >= 1))
          {
              pbxImg.Width = pbxImg.Width - 10;
              pbxImg.Height = pbxImg.Height - 10;
          }
      }
       }


这篇关于C#中的缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆