Beispiel #1
0
        public ImageReference SaveImage(byte[] imageBytes)
        {
            ImageReference imageReference = new ImageReference();

            string root     = HttpContext.Current.Server.MapPath("~/Content/Files/");
            string imageUrl = VirtualPathUtility.ToAbsolute("~/Content/Files/");

            var filename           = Guid.NewGuid() + ".jpg";
            var thumpImageFilename = Guid.NewGuid() + ".jpg";

            imageReference.ImageOriginal  = imageUrl + filename;
            imageReference.ThumbnailImage = imageUrl + thumpImageFilename;

            try
            {
                SaveImageOriginalAndthumpImage(imageBytes, root, filename, thumpImageFilename);
            }
            catch (Exception)
            {
                throw new Exception("Not Save Image");
            }

            imageReference.ImageOriginal  = imageReference.ImageOriginal.ToAbsolutPath();
            imageReference.ThumbnailImage = imageReference.ThumbnailImage.ToAbsolutPath();

            return(imageReference);
        }
Beispiel #2
0
        public List <ImageReference> SaveImages(MultipartMemoryStreamProvider provider, string root, ref Dictionary <string, string> errors)
        {
            List <ImageReference> imageFilesVeterans = new List <ImageReference>();

            foreach (HttpContent file in provider.Contents)
            {
                var filename = file.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);

                if (!ValidateImageType(filename))
                {
                    errors?.Add(filename, "Cannot supported type file");
                    continue;
                }

                var filesVeteran = new ImageReference();

                filename = Guid.NewGuid() + ".jpg";
                var thumpImageFilename = Guid.NewGuid() + ".jpg";


                filesVeteran.ImageOriginal  = filename;
                filesVeteran.ThumbnailImage = thumpImageFilename;

                imageFilesVeterans.Add(filesVeteran);

                byte[] fileArray = file.ReadAsByteArrayAsync().Result;

                using (FileStream fs = new FileStream(root + filename, FileMode.Create))
                {
                    fs.Write(fileArray, 0, fileArray.Length);
                }

                using (
                    FileStream fs = new FileStream(root + thumpImageFilename,
                                                   FileMode.Create))
                {
                    MemoryStream ms    = new MemoryStream(fileArray);
                    Image        image = Image.FromStream(ms);

                    Bitmap resizeImage = (Bitmap)ResizeImage(image, new Size(200, 200));

                    var imageToByte = ImageToByte(resizeImage);

                    fs.Write(imageToByte, 0, imageToByte.Length);
                }
            }

            return(imageFilesVeterans);
        }
Beispiel #3
0
        public List<ImageReference> SaveImages(MultipartMemoryStreamProvider provider, string root, ref Dictionary<string, string> errors)
        {
            List<ImageReference> imageFilesVeterans = new List<ImageReference>();

            foreach (HttpContent file in provider.Contents)
            {
                var filename = file.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);

                if (!ValidateImageType(filename))
                {
                    errors?.Add(filename, "Cannot supported type file");
                    continue;
                }

                var filesVeteran = new ImageReference();

                filename = Guid.NewGuid() + ".jpg";
                var thumpImageFilename = Guid.NewGuid() + ".jpg";

                filesVeteran.ImageOriginal = filename;
                filesVeteran.ThumbnailImage = thumpImageFilename;

                imageFilesVeterans.Add(filesVeteran);

                byte[] fileArray = file.ReadAsByteArrayAsync().Result;

                using (FileStream fs = new FileStream(root + filename, FileMode.Create))
                {
                    fs.Write(fileArray, 0, fileArray.Length);
                }

                using (
                    FileStream fs = new FileStream(root + thumpImageFilename,
                        FileMode.Create))
                {
                    MemoryStream ms = new MemoryStream(fileArray);
                    Image image = Image.FromStream(ms);

                    Bitmap resizeImage = (Bitmap)ResizeImage(image, new Size(200, 200));

                    var imageToByte = ImageToByte(resizeImage);

                    fs.Write(imageToByte, 0, imageToByte.Length);
                }

            }

            return imageFilesVeterans;
        }
Beispiel #4
0
        public ImageReference SaveImage(byte[] imageBytes)
        {
            ImageReference imageReference = new ImageReference();

            string root = HttpContext.Current.Server.MapPath("~/Content/Files/");
            string imageUrl = VirtualPathUtility.ToAbsolute("~/Content/Files/");

            var filename = Guid.NewGuid() + ".jpg";
            var thumpImageFilename = Guid.NewGuid() + ".jpg";

            imageReference.ImageOriginal = imageUrl + filename;
            imageReference.ThumbnailImage = imageUrl + thumpImageFilename;

            try
            {
                SaveImageOriginalAndthumpImage(imageBytes, root, filename, thumpImageFilename);
            }
            catch (Exception)
            {

                throw new Exception("Not Save Image");
            }

            imageReference.ImageOriginal = imageReference.ImageOriginal.ToAbsolutPath();
            imageReference.ThumbnailImage = imageReference.ThumbnailImage.ToAbsolutPath();

            return imageReference;
        }