private static String ExecResizeImage(byte[] imageData, Size fotoSize, IDataStore dataStore, String photoPath)
        {
            var data = imageData;

            using (var stream = new MemoryStream(data))
                using (var img = new Bitmap(stream))
                {
                    var imgFormat = img.RawFormat;
                    if (fotoSize != img.Size)
                    {
                        using (var img2 = CommonPhotoManager.DoThumbnail(img, fotoSize, false, false, false))
                        {
                            data = CommonPhotoManager.SaveToBytes(img2, Global.GetImgFormatName(imgFormat));
                        }
                    }
                    else
                    {
                        data = Global.SaveToBytes(img);
                    }

                    using (var fileStream = new MemoryStream(data))
                    {
                        var photoUri = dataStore.Save(photoPath, fileStream).ToString();
                        photoUri = String.Format("{0}?cd={1}", photoUri, DateTime.UtcNow.Ticks);
                        return(photoUri);
                    }
                }
        }
        public static String UploadLogo(Stream inputStream, bool isTmpDir)
        {
            var imageData = Global.ToByteArray(inputStream);

            var fileExtension = String.Concat("." + Global.GetImgFormatName(ImageFormat.Jpeg));
            var photoPath     = BuildFilePath(fileExtension);

            var result = ExecResizeImage(imageData, OrganisationLogoSize, Global.GetStore(), photoPath);

            return(result);
        }
        private static void ExecResizeImage(ResizeWorkerItem resizeWorkerItem)
        {
            foreach (var fotoSize in resizeWorkerItem.RequireFotoSize)
            {
                var data = resizeWorkerItem.ImageData;
                using (var stream = new MemoryStream(data))
                    using (var img = new Bitmap(stream))
                    {
                        var imgFormat = img.RawFormat;
                        if (fotoSize != img.Size)
                        {
                            using (var img2 = CommonPhotoManager.DoThumbnail(img, fotoSize, false, false, false))
                            {
                                data = CommonPhotoManager.SaveToBytes(img2, Global.GetImgFormatName(imgFormat));
                            }
                        }
                        else
                        {
                            data = Global.SaveToBytes(img);
                        }

                        var fileExtension = String.Concat("." + Global.GetImgFormatName(imgFormat));

                        var photoPath = !resizeWorkerItem.UploadOnly
                                        ? BuildFilePath(resizeWorkerItem.ContactID, fotoSize, fileExtension)
                                        : BuildFileTmpPath(resizeWorkerItem.ContactID, fotoSize, fileExtension, resizeWorkerItem.TmpDirName);

                        using (var fileStream = new MemoryStream(data))
                        {
                            var photoUri = resizeWorkerItem.DataStore.Save(photoPath, fileStream).ToString();
                            photoUri = String.Format("{0}?cd={1}", photoUri, DateTime.UtcNow.Ticks);

                            if (!resizeWorkerItem.UploadOnly)
                            {
                                ToCache(resizeWorkerItem.ContactID, photoUri, fotoSize);
                            }
                        }
                    }
            }
        }
예제 #4
0
        public String UploadLogo(byte[] imageData, ImageFormat imageFormat)
        {
            var photoPath = BuildFilePath("." + Global.GetImgFormatName(imageFormat));

            return(ExecResizeImage(imageData, OrganisationLogoSize, _global.GetStore(), photoPath));
        }