Skip to content

zavolokas/GdiExtensions

Repository files navigation

GDI+ Extensions

license Build Status Build Status

Contains extension methods to deal with Image classes.

PM> Install-Package Zavolokas.GdiExtensions -Version 1.0.0

Contents

  1. Scaling
  2. Opacity
  3. Channels copy

Scaling

Clones an original image to a new one with changed size.

using (var bitmap = new Bitmap(pathToImageFile))
using (var scaled = bitmap.CloneWithScaleTo(300, 80))
{
    scaled
        .SaveTo(resultPath, ImageFormat.Png)
        .ShowFile();
}
Input image Result
input1 scalingOutput1

Opacity

Clones an original image to a new one with the opacity set to the specidied.

using (var image = new Bitmap(pathToImageFile))
using (var semiTransparent = image.CloneWithOpacity(0.3f))
{
    semiTransparent
        .SaveTo(resultPath, ImageFormat.Png)
        .ShowFile();
}
Input image Result
input1 opacityOutput

Channels copy

Replaces channel values from a source RGBA image.

Note: The dest and source images should be of the same size.

using (var source = new Bitmap(pathToSrcImage))
using (var dest = new Bitmap(pathToDestImage))
{
    const int dstChannelIndex = 2;
    const int srcChannelIndex = 3;

    dest.CopyChannel(dstChannelIndex, source, srcChannelIndex)
        .SaveTo(resultPath, ImageFormat.Png)
        .ShowFile();
}
Dest Src
input1 input2
Replace Red with Alpha Replace Green with Alpha Replace Blue with Alpha
channelsOutputAR channelsOutputAG channelsOutputAB

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages