コード例 #1
0
        public static Photo Upload(BaseController controller, UploadPOSTParameters param)
        {
            var photo = new Photo();

            controller.DatabaseSession.Save(photo);
            controller.DatabaseSession.Flush(); // to get the ID

            var unique_id = photo.PhotoId.ToString();

            var original_buffer = new byte[param.Photo.ContentLength];

            param.Photo.InputStream.Read(original_buffer, 0, param.Photo.ContentLength);

            using (var originalBitmap = ImageUtilities.LoadBitmap(original_buffer))
            {
                AzureBlogStorageUtil.PutBlob(photo.GetOriginalFileURL()
                                             , azureStorageAccountName, azureStorageAccountKey
                                             , ImageUtilities.GetBytes(originalBitmap, ImageFormat.Jpeg), "image/jpeg");

                if (originalBitmap.Width > 600 || originalBitmap.Height > 800)
                {
                    // original image is too large for general display
                    photo.LargeFileIsSameAsOriginal = false;
                    using (var largeBitmap = ImageUtilities.Resize(originalBitmap, 600, 800))
                    {
                        AzureBlogStorageUtil.PutBlob(photo.GetLargeFileURL()
                                                     , azureStorageAccountName, azureStorageAccountKey
                                                     , ImageUtilities.GetBytes(largeBitmap, ImageFormat.Jpeg), "image/jpeg");
                    }
                }

                using (var thumbnailBitmap = ImageUtilities.Resize(originalBitmap, 240, 240))
                {
                    AzureBlogStorageUtil.PutBlob(photo.GetThumbnailFileURL()
                                                 , azureStorageAccountName, azureStorageAccountKey
                                                 , ImageUtilities.GetBytes(thumbnailBitmap, ImageFormat.Jpeg), "image/jpeg");
                }
                using (var tinyBitmap = ImageUtilities.Resize(originalBitmap, 50, 50))
                {
                    AzureBlogStorageUtil.PutBlob(photo.GetTinyFileURL()
                                                 , azureStorageAccountName, azureStorageAccountKey
                                                 , ImageUtilities.GetBytes(tinyBitmap, ImageFormat.Jpeg), "image/jpeg");
                }
            }

            return(photo);
        }
コード例 #2
0
        public static Photo Upload(BaseController controller, UploadPOSTParameters param)
        {
            var photo = new Photo();
            controller.DatabaseSession.Save(photo);
            controller.DatabaseSession.Flush(); // to get the ID

            var unique_id = photo.PhotoId.ToString();

            var original_buffer = new byte[param.Photo.ContentLength];
            param.Photo.InputStream.Read(original_buffer, 0, param.Photo.ContentLength);

            using (var originalBitmap = ImageUtilities.LoadBitmap(original_buffer))
            {
                AzureBlogStorageUtil.PutBlob(photo.GetOriginalFileURL()
                , azureStorageAccountName, azureStorageAccountKey
                , ImageUtilities.GetBytes(originalBitmap, ImageFormat.Jpeg), "image/jpeg");

                if (originalBitmap.Width > 600 || originalBitmap.Height > 800)
                {
                    // original image is too large for general display
                    photo.LargeFileIsSameAsOriginal = false;
                    using (var largeBitmap = ImageUtilities.Resize(originalBitmap, 600, 800))
                    {
                        AzureBlogStorageUtil.PutBlob(photo.GetLargeFileURL()
                            , azureStorageAccountName, azureStorageAccountKey
                            , ImageUtilities.GetBytes(largeBitmap, ImageFormat.Jpeg), "image/jpeg");
                    }
                }

                using (var thumbnailBitmap = ImageUtilities.Resize(originalBitmap, 240, 240))
                {
                    AzureBlogStorageUtil.PutBlob(photo.GetThumbnailFileURL()
                        , azureStorageAccountName, azureStorageAccountKey
                        , ImageUtilities.GetBytes(thumbnailBitmap, ImageFormat.Jpeg), "image/jpeg");
                }
                using (var tinyBitmap = ImageUtilities.Resize(originalBitmap, 50, 50))
                {
                    AzureBlogStorageUtil.PutBlob(photo.GetTinyFileURL()
                        , azureStorageAccountName, azureStorageAccountKey
                        , ImageUtilities.GetBytes(tinyBitmap, ImageFormat.Jpeg), "image/jpeg");
                }
            }

            return photo;
        }