如何上传和显示图片? [英] how to upload and display an image?

查看:72
本文介绍了如何上传和显示图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我一个简单的代码,以在应用程序上上传和显示图像....
和代码应用于同时管理缩略图和原始尺寸的图像..
并应限制重复的图像.
嗯,这是针对Web应用程序的,我想要C#中的代码.
谢谢:)

please tell me a simple code to upload and display images on the application....
and code should be for managing thumbnail and original size images at the same time..
and duplicate images should be restricted.
hmm it is for web application and i want the code in c#.
thanks :)

推荐答案

要上传图像并将其存储在数据库中,请在此处找到链接

http://aspalliance.com/articleViewer.aspx?aId=150 [ http://aspalliance.com/articleViewer.aspx?aId=138&pId= [ ^ ]

要从数据库读取图像,请在此处找到链接

http://authors.aspalliance.com/das/readimage.aspx [
To upload image and store in database find the links here

http://aspalliance.com/articleViewer.aspx?aId=150[^]

http://aspalliance.com/articleViewer.aspx?aId=138&pId=[^]

To Read image from database find the link here

http://authors.aspalliance.com/das/readimage.aspx[^]


To make thumbnail find the code here
public void ProcessImage(Picture objPicture)
        {

            string lastPart = "image/jpg";
            byte[] PictureBytes = null;
            PictureBytes = objPicture.PictureBinary;
            string[] parts = objPicture.Extension.Split(''/'');
            lastPart = parts[parts.Length - 1];
            ImageFormat imgFormat = new ImageFormat(System.Guid.NewGuid());
            switch (lastPart)
            {
                case "pjpeg":
                    lastPart = "image/jpg";
                    imgFormat = ImageFormat.Jpeg;
                    break;
                case "x-png":
                    lastPart = "image/png";
                    imgFormat = ImageFormat.Png;
                    break;
                case "x-icon":
                    lastPart = "image/ico";
                    imgFormat = ImageFormat.Icon;
                    break;
                default:
                    imgFormat = ImageFormat.Jpeg;
                    lastPart = "image/jpg";
                    break;
            }
            Response.ContentType = lastPart;
            Response.BinaryWrite(ThumbnailImage(PictureBytes , imgFormat,30,30));
            Response.End();
            
        }

        private byte[] ThumbnailImage(byte[] bImage, ImageFormat imgFormat, short height, short width)
        {
            byte[] bThumbnailImage;
            MemoryStream strm = new MemoryStream(bImage);
            Image img = Image.FromStream(strm);
            Image imgThumbnail = img.GetThumbnailImage(width, height, new Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
            MemoryStream imageStream = new MemoryStream(Convert.ToInt32(strm.Length));
            imgThumbnail.Save(imageStream, imgFormat);
            bThumbnailImage = new byte[imageStream.Length];
            imageStream.Position = 0;
            imageStream.Read(bThumbnailImage, 0, (int)(imageStream.Length));
            return bThumbnailImage;
        }

        private bool ThumbnailCallback()
        {
            return false;
        } 


答案取决于是Windows还是Web.

对于Web,请使用上载控件,将其放置在某个位置,然后将img和img添加到指向该控件的控件集合中.
The answer will be dependent on whether it is for windows or web.

For web, use an upload control, place the in some location and add and img to the control collection that points to it.


我猜您是在向Web应用程序索要东西,请至少在标签列表中完全询问您的问题.

尝试
i guess you are asking the thing for web application, please ask your question completely at-least mention list of Tags.

try this


这篇关于如何上传和显示图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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