How do you align a uploaded photo without filling a space in C #?

On my site, users can upload photos. I am currently compressing and resizing photos to make sure they are not huge files. But it creates photographs of different sizes ... which makes the site a bit ugly in my opinion.

I want the thumbnails to be square images, but not with the padding. This is normal if there is some loss of the photo in miniature. I would like the fidelity of the photo to be accurate, even if it means cropping is necessary.

+3
source share
4 answers

, . , . , , :

  public Bitmap CreateThumbnail(Bitmap RawImage)
    {
        int width = RawImage.Width;
        int height = RawImage.Height;

        Size ThumbnailDimensions = new Size();
        ThumbnailDimensions.Width = 100;
        ThumbnailDimensions.Height = 100;

        Rectangle cropArea = new Rectangle();
        if (width > height)
        {               
            cropArea.Width = height;
            cropArea.Height = height;
            cropArea.X = 0;
            cropArea.Y = 0;                
        }
        else if (width < height)
        {
            cropArea.Width = width;
            cropArea.Height = width;
            cropArea.X = 0;
            cropArea.Y = 0;
        }
        if(width != height) Bitmap thumbnail = CropImage(RawImage, cropArea);

        thumbnail = ResizeImage(thumbnail, ThumbnailDimensions);
        return thumbnail;
    }

, .

+3

, ( w h), , , . . .

+2

, , div , . , .

? ? ? ?

-1

, , , ( ).

http://snippets.dzone.com/posts/show/1484

( Atalasoft - SDK SDK DotImage),

AtalaImage img = new AtalaImage("filename.jpg");
AtalaImage img2 = new CropCommand( /*point and size of crop */).Apply(img).Image;
img2.Save("filename", new JpegEncoder(quality), null);
-1

Source: https://habr.com/ru/post/1758301/


All Articles