Пример #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="columns">
 /// Array of columns
 /// Max: 10
 /// </param>
 /// <param name="imageAspectRatio">
 /// Aspect ratio of the image. Specify one of the following values:
 /// rectangle: 1.51:1
 /// square: 1:1
 /// The default value is rectangle.
 /// </param>
 /// <param name="imageSize">
 /// Size of the image. Specify one of the following values:
 /// cover: The image fills the entire image area.Parts of the image that do not fit in the area are not displayed.
 /// contain: The entire image is displayed in the image area.A background is displayed in the unused areas to the left and right of vertical images and in the areas above and below horizontal images.
 /// The default value is cover.
 /// </param>
 public CarouselTemplate(IList <CarouselColumn> columns        = null,
                         ImageAspectRatioType imageAspectRatio = ImageAspectRatioType.Rectangle, ImageSizeType imageSize = ImageSizeType.Cover)
 {
     Columns          = columns ?? new List <CarouselColumn>();
     ImageAspectRatio = imageAspectRatio;
     ImageSize        = imageSize;
 }
Пример #2
0
        private void AddImage(ImageList list, string imageNameWithoutExtension, ImageSizeType imageSizeType)
        {
            string key   = imageNameWithoutExtension;
            Image  image = GetFileTypeIcon(imageNameWithoutExtension, imageSizeType);

            list.Images.Add(key, image);
        }
Пример #3
0
        public static byte[] CreateImagePreview(byte[] sourceBytes, ImageSizeType imageSizeType)
        {
            using (var myMemStream = new MemoryStream(sourceBytes))
            {
                using (var fullsizeImage = Image.FromStream(myMemStream))
                {
                    var destinationSize = GetPreviewSizeFor(fullsizeImage.Size, imageSizeType);
                    var canvasWidth     = destinationSize.Width;
                    var canvasHeight    = destinationSize.Height;
                    using (var newImage = fullsizeImage.GetThumbnailImage(canvasWidth, canvasHeight, null, IntPtr.Zero))
                    {
                        using (var resize = new MemoryStream())
                        {
                            using (var imageEncodeParameters = CreateImageEncoderParameters())
                            {
                                var destinationImageFormat = ImageFormat.Jpeg;
                                var imageEncoder           = destinationImageFormat.GetEncoder();
                                newImage.Save(resize, imageEncoder, imageEncodeParameters);
                            }

                            return(resize.ToArray());
                        }
                    }
                }
            }
        }
Пример #4
0
 private async Task <byte[]> GetImageBytes(IBooruPost modelBase,
                                           ImageSizeType type,
                                           CancellationToken cancellationToken)
 {
     return(type == ImageSizeType.Full
         ? await _httpClient.GetByteArrayAsync(modelBase.FullImageUrl, cancellationToken).ConfigureAwait(false)
         : await _httpClient.GetByteArrayAsync(modelBase.PreviewImageUrl, cancellationToken).ConfigureAwait(false));
 }
        public async Task <bool> TryDeleteImage(string imageName, ImageSizeType imageSizeType, CancellationToken cancellationToken)
        {
            ArgumentHelper.AssertNotNullOrEmpty(nameof(imageName), imageName);

            var blockBlob = GetBlockBlob(imageName, imageSizeType);

            return(await blockBlob.DeleteIfExistsAsync(cancellationToken).ConfigureAwait(false));
        }
        public Uri GetImageUri(string imageName, ImageSizeType imageSizeType)
        {
            ArgumentHelper.AssertNotNullOrEmpty(nameof(imageName), imageName);

            var blockBlob = GetBlockBlob(imageName, imageSizeType);

            return(blockBlob.Uri);
        }
Пример #7
0
        public string GetFullCachePath(string cachePath, ImageSizeType imageType)
        {
            var dir = Path.Combine(_dynamicConfig.CacheFolder, Path.GetDirectoryName(cachePath), imageType.ToString());

            _fileSystemService.CreateDirectory(dir);

            return(Path.Combine(dir, Path.GetFileNameWithoutExtension(cachePath) + Path.GetExtension(cachePath)));
        }
Пример #8
0
        public static Image GetDefaultImage(int anidbId, ImageSizeType imageSizeType, ImageEntityType?imageEntityType = null)
        {
            var defaultImage = imageEntityType.HasValue ?
                               RepoFactory.AniDB_Anime_DefaultImage.GetByAnimeIDAndImagezSizeTypeAndImageEntityType(anidbId, imageSizeType, imageEntityType.Value) :
                               RepoFactory.AniDB_Anime_DefaultImage.GetByAnimeIDAndImagezSizeType(anidbId, imageSizeType);

            return(defaultImage != null ? new Image(defaultImage.ImageParentID, (ImageEntityType)defaultImage.ImageParentType, true) : null);
        }
        private CloudBlockBlob GetBlockBlob(string name, ImageSizeType imageSizeType)
        {
            if (imageSizeType == ImageSizeType.Original)
            {
                return(_imagesContainer.Value.GetBlockBlobReference(name));
            }

            return(_thumbnailsContainer.Value.GetBlockBlobReference(name));
        }
Пример #10
0
        /// <summary>
        /// Return full path to image in cache directory depends on imagesizetype
        /// </summary>
        private string GetImagePath(IBooruPost booruImage, ImageSizeType type)
        {
            var workDir = Path.Combine(Directory.GetCurrentDirectory(), _cachePath);

            return(type == ImageSizeType.Preview
                ? Path.Combine(
                       workDir, booruImage.Hash + "_preview")
                : Path.Combine(
                       workDir, booruImage.Hash + "_full"));
        }
Пример #11
0
 private ImageEntity CreateImageEntity(FileEntity file, ImageSizeType imageSizeType)
 {
     return(new ImageEntity
     {
         Binary = ImageResizer.CreateImagePreview(file.Binary, imageSizeType),
         ImageId = this.GuidGenerator.GenerateGuid(),
         OriginalFileId = file.FileId,
         SizeType = imageSizeType
     });
 }
Пример #12
0
 public ButtonsTemplate(string text, string thumbnailImageUrl = null, string title = null, IList <ITemplateAction> actions = null,
                        ImageAspectRatioType imageAspectRatio = ImageAspectRatioType.Rectangle, ImageSizeType imageSize = ImageSizeType.Cover, string imageBackgroundColor = "#FFFFFF")
 {
     ThumbnailImageUrl = thumbnailImageUrl;
     Title             = title.Substring(0, Math.Min(title.Length, 40));
     Text                 = (string.IsNullOrEmpty(thumbnailImageUrl) || string.IsNullOrEmpty(title)) ? text.Substring(0, Math.Min(text.Length, 160)) : text.Substring(0, Math.Min(text.Length, 60));
     Actions              = actions ?? new List <ITemplateAction>();
     ImageAspectRatio     = imageAspectRatio;
     ImageSize            = imageSize;
     ImageBackgroundColor = imageBackgroundColor;
 }
Пример #13
0
        public async Task <MemoryStream> DownloadImage(string imageName, ImageSizeType imageSizeType, CancellationToken cancellationToken)
        {
            if (_streamsDictionary.TryGetValue(imageName, out var value))
            {
                MemoryStream outMemoryStream = new MemoryStream();
                await value.CopyToAsync(outMemoryStream, cancellationToken);

                outMemoryStream.Position = 0;
                return(outMemoryStream);
            }

            return(null);
        }
Пример #14
0
        public async Task <BitmapImage> FetchImageAsync(
            IBooruPost booruPost,
            ImageSizeType imageSizeType,
            bool caching = true,
            CancellationToken cancellationToken = default)
        {
            caching = _configuration.ImageCaching;
            cancellationToken.ThrowIfCancellationRequested();
            BitmapImage resultImage;

            if (caching)
            {
                if (_imageCachingService.IsHasCache(booruPost, imageSizeType))
                {
                    resultImage = await _imageCachingService.GetImageAsync(
                        booruPost, imageSizeType, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    var imageBytes = await GetImageBytes(
                        booruPost, imageSizeType, cancellationToken).ConfigureAwait(false);

                    await _imageCachingService.CacheImageAsync(booruPost, imageSizeType, imageBytes,
                                                               imageSizeType, cancellationToken).ConfigureAwait(false);

                    resultImage =
                        await _bitmapImageCreatorService.CreateImageAsync(imageBytes).ConfigureAwait(false);
                }
            }
            else
            {
                resultImage =
                    await _bitmapImageCreatorService.CreateImageAsync(await GetImageBytes(
                                                                          booruPost, imageSizeType, cancellationToken).ConfigureAwait(false))
                    .ConfigureAwait(false);
            }


            return(resultImage);
            //    return await _bitmapImageCreatorService.CreateImageAsync(
            //        await GetImageBytes(booruImage, imageSizeType));

            //if (_imageCachingService.IsHasCache(booruImage, imageSizeType))
            //    return await _imageCachingService.GetImageAsync(booruImage, imageSizeType, token);

            //var imageBytes = await GetImageBytes(booruImage, imageSizeType);
            //await _imageCachingService.CacheImageAsync(booruImage, imageSizeType, imageBytes,
            //    imageSizeType, token);
            //return await _bitmapImageCreatorService.CreateImageAsync(imageBytes);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="text">
 /// Message text
 /// Max: 160 characters(no image or title)
 /// Max: 60 characters(message with an image or title)
 /// </param>
 /// <param name="thumbnailImageUrl">
 /// Image URL (Max: 1000 characters)
 /// HTTPS
 /// JPEG or PNG
 /// Aspect ratio: 1:1.51
 /// Max width: 1024px
 /// Max: 1 MB
 /// </param>
 /// <param name="title">
 /// Title
 /// Max: 40 characters
 /// </param>
 /// <param name="actions">
 /// Action when tapped
 /// Max: 4
 /// </param>
 /// <param name="imageAspectRatio">
 /// Aspect ratio of the image. Specify one of the following values:
 /// rectangle: 1.51:1
 /// square: 1:1
 /// The default value is rectangle.
 /// </param>
 /// <param name="imageSize">
 /// Size of the image. Specify one of the following values:
 /// cover: The image fills the entire image area.Parts of the image that do not fit in the area are not displayed.
 /// contain: The entire image is displayed in the image area.A background is displayed in the unused areas to the left and right of vertical images and in the areas above and below horizontal images.
 /// The default value is cover.
 /// </param>
 /// <param name="imageBackgroundColor">
 /// Background color of image. Specify a RGB color value. The default value is #FFFFFF (white).
 /// </param>
 /// <param name="defaultAction">
 /// Action when image is tapped; set for the entire image, title, and text area
 /// </param>
 public ButtonsTemplate(string text, string thumbnailImageUrl = null, string title = null, IList <ITemplateAction> actions = null,
                        ImageAspectRatioType imageAspectRatio = ImageAspectRatioType.Rectangle, ImageSizeType imageSize = ImageSizeType.Cover, ColorCode imageBackgroundColor = null,
                        ITemplateAction defaultAction         = null)
 {
     ThumbnailImageUrl = thumbnailImageUrl;
     Title             = title?.Substring(0, Math.Min(title.Length, 40));
     Text = (string.IsNullOrEmpty(thumbnailImageUrl) && string.IsNullOrEmpty(title))
         ? text.Substring(0, Math.Min(text.Length, 160)) : text.Substring(0, Math.Min(text.Length, 60));
     Actions              = actions ?? new List <ITemplateAction>();
     ImageAspectRatio     = imageAspectRatio;
     ImageSize            = imageSize;
     ImageBackgroundColor = imageBackgroundColor ?? ColorCode.White;
     DefaultAction        = defaultAction;
 }
Пример #16
0
        public void GetFullCachePath(ImageSizeType imageSize)
        {
            var cacheDir              = Path.Combine("home", "homePhotos", "cache");
            var cacheFilePath         = Path.Combine("c1", "983767D2-96B3-4372-89D1-74C190EE23B0.jpg");
            var expectedFullCachePath = Path.Combine(cacheDir, "c1", imageSize.ToString(), "983767D2-96B3-4372-89D1-74C190EE23B0.jpg");

            _dynamicConfig.SetupGet(o => o.CacheFolder).Returns(cacheDir);

            var actualFullCachePath = _imageService.GetFullCachePath(cacheFilePath, imageSize);

            _dynamicConfig.VerifyGet(o => o.CacheFolder, Times.Once);

            Assert.Equal(expectedFullCachePath, actualFullCachePath);
        }
Пример #17
0
        public async Task <BitmapImage> GetImageAsync(
            IBooruPost booruImage,
            ImageSizeType imageType,
            CancellationToken cancellationToken = default)
        {
            byte[] buff;
            using (var file = new FileStream(GetImagePath(booruImage, imageType),
                                             FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true))
            {
                buff = new byte[file.Length];
                await file.ReadAsync(buff, 0, (int)file.Length, cancellationToken).ConfigureAwait(false);
            }

            return(await _imageCreatorService.CreateImageAsync(buff).ConfigureAwait(false));
        }
Пример #18
0
 public UiData(UiData bd)
 {
     name     = bd.name;
     uiType   = bd.uiType;
     layer    = bd.layer;
     position = bd.position;
     color    = bd.color;
     type     = bd.type;
     sizeType = bd.sizeType;
     sprite   = bd.sprite;
     action   = bd.action;
     goTo     = bd.goTo;
     fontSize = bd.fontSize;
     text     = bd.text;
 }
Пример #19
0
        /// <summary>
        /// 按钮图标类型
        /// </summary>
        /// <param name="menuName"></param>
        /// <param name="sizeType"></param>
        /// <returns></returns>
        public Image GetMenuIcon(string menuName, ImageSizeType sizeType)
        {
            string name = menuName.Trim();

            switch (sizeType)
            {
            case ImageSizeType.Size16x16:
                return(Bitmap.FromFile(IconMenuPath16x16 + "\\" + name + ".png"));

            case ImageSizeType.Size48x48:
                return(Bitmap.FromFile(IconMenuPath48x48 + "\\" + name + ".png"));

            default:
                return(Bitmap.FromFile(IconMenuPath16x16 + "\\" + name + ".png"));
            }
        }
Пример #20
0
 public async Task CacheImageAsync(IBooruPost booruImage,
                                   ImageSizeType imageType,
                                   byte[] bytes,
                                   ImageSizeType sizeType,
                                   CancellationToken cancellationToken = default)
 {
     try
     {
         using (FileStream stream = File.Open(GetImagePath(booruImage, imageType), FileMode.OpenOrCreate))
         {
             await stream.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false);
         }
     }
     catch (IOException e)
     {
     }
 }
Пример #21
0
        /// <summary>
        /// 设置壁纸尺寸类型
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private int SetSizeType(ImageSizeType type)
        {
            switch (type)
            {
            case ImageSizeType._1200p:
                return(SIZE_1200P);

            case ImageSizeType._1080p:
                return(SIZE_1080P);

            case ImageSizeType._720p:
                return(SIZE_720P);

            default:
                return(SIZE_1080P);
            }
        }
Пример #22
0
        public static Size GetPreviewSizeFor(Size sourceSize, ImageSizeType imageSizeType)
        {
            switch (imageSizeType)
            {
            default:
            case ImageSizeType.PreviewSize:
                var previewMaxSize = new Size(600, 315);
                return(ResizeKeepAspect(sourceSize, previewMaxSize.Width, previewMaxSize.Height, true));

            case ImageSizeType.Small:
                var smallMaxSize = new Size(1200, 630);
                return(ResizeKeepAspect(sourceSize, smallMaxSize.Width, smallMaxSize.Height, true));

            case ImageSizeType.Full:
                var fullMaxSize = new Size(3000, 3000);
                return(ResizeKeepAspect(sourceSize, fullMaxSize.Width, fullMaxSize.Height, true));
            }
        }
Пример #23
0
        public async Task <MemoryStream> DownloadImage(string imageName, ImageSizeType imageSizeType,
                                                       CancellationToken cancellationToken)
        {
            ArgumentHelper.AssertNotNullOrEmpty(nameof(imageName), imageName);

            var blockBlob = GetBlockBlob(imageName, imageSizeType);

            if (blockBlob == null)
            {
                return(null);
            }

            MemoryStream memoryStream = new MemoryStream();
            await blockBlob.DownloadToStreamAsync(memoryStream, cancellationToken).ConfigureAwait(false);

            memoryStream.Position = 0;
            return(memoryStream);
        }
Пример #24
0
        /// <summary>
        /// 文件类型图标
        /// </summary>
        /// <param name="fileExtension"></param>
        /// <param name="sizeType"></param>
        /// <returns></returns>
        public Image GetFileTypeIcon(string fileExtension, ImageSizeType sizeType)
        {
            string extName = fileExtension.Replace(".", "").Trim();
            string path    = "";

            switch (sizeType)
            {
            case ImageSizeType.Size16x16:
                path = IconFileTypePath16x16;  break;

            case ImageSizeType.Size48x48:
                path = IconFileTypePath48x48; break;

            default:
                path = IconFileTypePath16x16; break;
            }
            path += "\\" + extName + ".png";
            return(Bitmap.FromFile(path));
        }
Пример #25
0
        public async Task <List <BooruImage> > GetImagesAsync(
            BooruSiteType booruSiteType,
            ImageSizeType imageType,
            ICollection <IBooruPost> collection,
            CancellationToken cancellationToken = default)
        {
            var images = new List <BooruImage>();

            foreach (var booruImage in collection)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                }

                //Todo research why hash may be empty
                if (string.IsNullOrEmpty(booruImage.Hash))
                {
                    continue;
                }

                var imageFile = await _imageFetcherService.FetchImageAsync(
                    booruImage, imageType, cancellationToken : cancellationToken);

                if (imageFile == null)
                {
                    continue;
                }
                var booruImageWrapper = new BooruImage();
                booruImageWrapper.Hash  = booruImage.Hash;
                booruImageWrapper.Image = imageFile;
                images.Add(booruImageWrapper);
            }

            return(images);
        }
Пример #26
0
        public static string GetAvatarLink(this Client user, ImageSizeType imageSizeType)
        {
            var imageId = user?.AvatarFileId;

            return(imageId.HasValue ? CrocoApp.Application.FileCopyWorker.GetVirtualResizedImageLocalPath(imageId.Value, imageSizeType) : null);
        }
Пример #27
0
        public async Task <UploadImageResult> UploadImage(string imageName, Stream imageStream, ImageSizeType imageSizeType,
                                                          string imageContentType, CancellationToken cancellationToken)
        {
            ArgumentHelper.AssertNotNullOrEmpty(nameof(imageName), imageName);
            ArgumentHelper.AssertNotNull(nameof(imageStream), imageStream);

            var blockBlob = GetBlockBlob(imageName, imageSizeType);

            blockBlob.Properties.ContentType = imageContentType;

            imageStream.Position = 0;
            await blockBlob.UploadFromStreamAsync(imageStream, cancellationToken).ConfigureAwait(false);

            return(new UploadImageResult
            {
                MD5Hash = blockBlob.Properties.ContentMD5,
                DateAdded = blockBlob.Properties.Created ?? DateTimeOffset.Now,
                Url = blockBlob.Uri
            });
        }
Пример #28
0
 public Uri GetImageUri(string imageName, ImageSizeType imageSizeType)
 {
     throw new NotImplementedException();
 }
Пример #29
0
 public Task <bool> ImageExists(string imageName, ImageSizeType imageSizeType, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
Пример #30
0
        public async Task <UploadImageResult> UploadImage(string imageName, Stream imageStream, ImageSizeType imageSizeType, string contentType,
                                                          CancellationToken cancellationToken)
        {
            var memoryStream = new MemoryStream();
            await imageStream.CopyToAsync(memoryStream, cancellationToken);

            memoryStream.Position = 0;
            _streamsDictionary.TryAdd(imageName, memoryStream);

            return(new UploadImageResult
            {
                Url = new Uri("http://test.com"),
                DateAdded = DateTimeOffset.Now,
                MD5Hash = Guid.NewGuid().ToString()
            });
        }