Asp.Net画像をバイナリに変換

1018 ワード

private byte[] PhotoToBinary()
        {
            int FileLength = 0;
            //    
            HttpPostedFile UpFile = this.txtPhoto.PostedFile;
            //      
            FileLength = UpFile.ContentLength;
            Byte[] FileByteArray = new Byte[FileLength];   //        Byte  
            try
            {
                //       
                if (FileLength == 0)
                {
                    FileByteArray = null;
                    return FileByteArray;
                }
                else
                {
                    System.IO.Stream StreamObject = UpFile.InputStream;      //       
                    //        ,FileByteArray      ,0       、FileLnegth     
                    StreamObject.Read(FileByteArray, 0, FileLength);
                }
            }
            catch (Exception ex)
            {
                FileByteArray = null;
                throw ex;
            }
            return FileByteArray;
        }