Convert downloaded file to bitmap in asp.net

I have a field FileUploadand button. In my script, the files that will be downloaded are image files. I want to convert these image files to bitmaps and temporarily save them in a buffer.

I have a function that takes two bit files and tells us if these two files match.

One of the files will come from the control FileUploadin the event ButtonClick, and the other bitmap will be read from the database.

Can someone tell me how I can convert these files to bitmaps and pass both bitmap objects into a function.

+3
source share
1 answer

:

System.Drawing.Bitmap bmpPostedImage = new System.Drawing.Bitmap(userFileUpload.PostedFile.InputStream);

(, , , ),

byte[] byteArrayStoredImage = ImageService.GetImageData(imageID);
MemoryStream imgStream = new MemoryStream(byteArrayStoredImage);
System.Drawing.Bitmap bmpStoredImage = new Bitmap(imgStream);

(bmpPostedImage bmpStoredImage) . http://www.dreamincode.net/code/snippet2859.htm , . , , Google, .

, :

    public byte[] GetImageData(string imageID)
    {
                string connectionString = ConfigurationManager.ConnectionStrings["connectionstringname"];
        SqlConnection connection = SqlConnection(connectionString);
        connection.Open();
        SqlCommand command1 = new SqlCommand("select imgfile from myimages where imgname=@imageId", connection);
        SqlParameter myparam = command1.Parameters.Add("@imageId", SqlDbType.NVarChar, 30);
        myparam.Value = imageID;
        byte[] img = (byte[])command1.ExecuteScalar();
        connection.Close();
        return img;
    }

ImageService.GetImageData(imageID) GetImageData (imageID);

, , , , .

+6

All Articles