Esempio n. 1
0
        public async Task <IActionResult> UserAvatar(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest());
            }
            var user = await userManager.FindByIdAsync(userId);

            return(user?.Avatar == null || user.Avatar.Length == 0
                ? File(ImageScaler.ScaleImage(Resource.DefaultAvatar, 128, 128), "image/png")
                : File(ImageScaler.ScaleImage(user.Avatar, 128, 128), "image/png"));
        }
        private static void checkResizeImage(string imageFilePath, int width, int height)
        {
            // 2013-05-20, Uwe Keim:
            // Das Bild so in der Größe anpassen, wie es im HTML auch tatsächlich angegeben wurde.

            if (width > 0 && height > 0 && !String.IsNullOrEmpty(imageFilePath) && File.Exists(imageFilePath))
            {
                using (var img = ImageHelper.LoadImage(imageFilePath))
                {
                    if (img.Width != width || img.Height != height)
                    {
                        using (var img2 = ImageScaler.ScaleImage(img, width, height))
                        {
                            ImageHelper.SaveImage(img2, imageFilePath);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        Image addImage(int width, int height)
        {
            if (Image == null)
            {
                return(null);
            }
            Image img;

            try
            {
                img = ImageScaler.ScaleImage(width, height, Image);
            }
            catch (OutOfMemoryException)
            {
                return(null);
            }
            if (img == null)
            {
                return(null);
            }

            if (img == Image)
            {
                return(null);
            }

            ImageDesc desc = new ImageDesc();

            desc.Width  = width;
            desc.Height = height;
            desc.Image  = img;
            mImages.Add(desc);
            mImage.Dispose();
            mImage = null;
            return(img);
        }