如何在我的表单上显示图像何时附加到我的表单 [英] how to show image in my form when to get attached to my form

查看:57
本文介绍了如何在我的表单上显示图像何时附加到我的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我有一个带有上传文件控件的表单,我正在其中上传图片,每个表单仅包含一张图片
我想在表格的右侧以400X400的尺寸显示图片.
谁能帮我解决问题.

在Advance中致谢

Dear All,
i had a form with upload file control i am uploading pics in it each form contains one pic only
i want to display the pic on right side of my form with 400X400 size.
can any one help me to resolve the issue.

Thanks in Advance

推荐答案

查看这些教程-

http://www.dotnetspark.com/kb/843- show-uploaded-image-image-image-control-asp-net.aspx
.NET图片上传
如何使用ASP.NET上传图像
Check these tutorials -

http://www.dotnetspark.com/kb/843-show-uploaded-image-image-control-asp-net.aspx
.NET Image Uploading
How to upload an image using ASP.NET


希望它会帮助您

hope this will help you

protected void btnupload_Click(object sender, EventArgs e)
    {
        // Initialize variables
        string sSavePath;
        string sThumbExtension;
        int intThumbWidth;
        int intThumbHeight;

        // Set constant values
        sSavePath = "images/";
        sThumbExtension = "_thumb";
        intThumbWidth = 160;
        intThumbHeight = 120;

        // If file field isn’t empty
        if (imgupload.PostedFile != null)
        {
            // Check file size (mustn’t be 0)
            HttpPostedFile myFile = imgupload.PostedFile;
            int nFileLen = myFile.ContentLength;
            if (nFileLen == 0)
            {
                lbloutput.Text = "There wasn't any file uploaded.";
                return;
            }

            // Check file extension (must be JPG)
            if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")
            {
                lbloutput.Text = "The file must have an extension of JPG";
                return;
            }

            // Read file into a data stream
            byte[] myData = new Byte[nFileLen];
            myFile.InputStream.Read(myData, 0, nFileLen);

            // Make sure a duplicate file doesn’t exist.  If it does, keep on appending an incremental numeric until it is unique
            string sFilename = System.IO.Path.GetFileName(myFile.FileName);
            int file_append = 0;
            while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))
            {
                file_append++;
                sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + file_append.ToString() + ".jpg";
            }

            // Save the stream to disk
            System.IO.FileStream newFile = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename), System.IO.FileMode.Create);
            newFile.Write(myData, 0, myData.Length);
            newFile.Close();

            // Check whether the file is really a JPEG by opening it
            System.Drawing.Image.GetThumbnailImageAbort myCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
            Bitmap myBitmap;
            try
            {
                myBitmap = new Bitmap(Server.MapPath(sSavePath + sFilename));

                // If jpg file is a jpeg, create a thumbnail filename that is unique.
                file_append = 0;
                string sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + sThumbExtension + ".jpg";
                while (System.IO.File.Exists(Server.MapPath(sSavePath + sThumbFile)))
                {
                    file_append++;
                    sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + file_append.ToString() + sThumbExtension + ".jpg";
                }

                // Save thumbnail and output it onto the webpage
                System.Drawing.Image myThumbnail = myBitmap.GetThumbnailImage(intThumbWidth, intThumbHeight, myCallBack, IntPtr.Zero);
                myThumbnail.Save(Server.MapPath(sSavePath + sThumbFile));
                Image1.ImageUrl = sSavePath + sThumbFile;

                // Displaying success information
                lbloutput.Text = "File uploaded successfully!";

                // Destroy objects
                myThumbnail.Dispose();
                myBitmap.Dispose();
            }
            catch (ArgumentException errArgument)
            {
                // The file wasn't a valid jpg file
                lbloutput.Text = "The file wasn't a valid jpg file.";
                System.IO.File.Delete(Server.MapPath(sSavePath + sFilename));
            }
        }
    }
    public bool ThumbnailCallback()
    {
        return false;
    }


这篇关于如何在我的表单上显示图像何时附加到我的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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