简体   繁体   中英

(WPF C#) Image watermark and resize

My WPF application already can make image resizing and text watermark. My app converts a 4MB image to 600 KB image when converted image sizes are 700px x 700px and watermark text is 30 pt.

How can I reduce image size (600 KB to 250 KB or smaller)?

Should I use which library or code sample considering my application is written using WPF, C# and .NET 4?

There are two ways for reducing image size: reduce resolution or use compression parameters of the format you are using (ie. jpeg compression is based on cosine transformation which enables you to control quality (and size) of final image).

I've used BitmapSource extension method to control quality of Jpeg images I save. Maybe you will find it usefull:

    public static void SaveBitmapSourceAsJpeg(this BitmapSource image, string fileName, int quality)
    {
        using (var fileStream = new FileStream(fileName, FileMode.Create))
        {
            var encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(image));
            encoder.QualityLevel = quality;
            encoder.Save(fileStream);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM