Show / Hide Table of Contents

Class ImageUtils

Provides helpers for centering and fitting images

Inheritance
System.Object
ImageUtils
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: NFX.Graphics
Assembly: NFX.dll
Syntax
public static class ImageUtils

Methods

ExtractMainColors(Image, Int32, Int32, Int32, Int32, Single)

Extracts three main colors and background color from source image by the following algorithm:

  1. source image color quality reduced down to 256/dwnFactor1 color per each of RGB channel (222=8 base colors used as default)
  2. four areas (three main and one background) with the biggest color frequencies are taken
  3. color frequency analisys is performed in each area which gives area main color (image color quality reduced down to 256/dwnFactor2 color per each of RGB channel)

Background area search is limited to [1-interiorPct, interiorPct] portion of image interior

Declaration
public static Color[] ExtractMainColors(Image srcImg, int resizeWidth = 64, int resizeHeight = 64, int dwnFactor1 = 128, int dwnFactor2 = 24, float interiorPct = 0.9F)
Parameters
Type Name Description
Image srcImg

Source image

System.Int32 resizeWidth

Preprocessing image width

System.Int32 resizeHeight

Preprocessing image height

System.Int32 dwnFactor1

Main downgrade factor (source image color quality reduced down to 256/dwnFactor1 color per each of RGB channel (222=8 base colors used as default))

System.Int32 dwnFactor2

Secondary downgrade factor for inner-area main color selection

System.Single interiorPct

Value within (0,1) range that indicates portion of image interior, i.e. 0.9 means that 10% part of the image will be used for boundary detection

Returns
Type Description
System.Drawing.Color[]

Three main colors and background volor

ExtractMainColors2Iter(Image, Int32, Int32, Int32, Int32, Single, Single)

Extracts three main colors and background color from source image. Does the same as ExtractMainColors(Image, Int32, Int32, Int32, Int32, Single) method but performs the second extraction attempt if the first attempt returns almost the same colors

Declaration
public static Color[] ExtractMainColors2Iter(Image srcBmp, int resizeWidth = 64, int resizeHeight = 64, int dwnFactor1 = 128, int dwnFactor2 = 24, float interiorPct = 0.9F, float imgDistEps = 0.2F)
Parameters
Type Name Description
Image srcBmp

Source image

System.Int32 resizeWidth

Preprocessing image width

System.Int32 resizeHeight

Preprocessing image height

System.Int32 dwnFactor1

color per each of RGB channel (222=8 base colors used as default))

System.Int32 dwnFactor2

Secondary downgrade factor for inner-area main color selection

System.Single interiorPct

Value within (0,1) range that indicates portion of image interior, i.e. 0.9 means that 10% part of the image will be used for boundary detection

System.Single imgDistEps

Color similarity factor. If less that specified value, then the second extraction attempt will be performed

Returns
Type Description
System.Drawing.Color[]

Three main colors and background color

FitCenteredImage(Image, Int32, Int32, Int32, Int32, Nullable<Color>)

Scales source image so it uniformly (without cropping) fits in the desired image size preserving aspect ratio. This function is usable for profile picture size/aspect normalization

Declaration
public static Image FitCenteredImage(this Image srcImage, int targetWidth = 128, int targetHeight = 128, int xDpi = 96, int yDpi = 96, Color? bColor = default (Color? ))
Parameters
Type Name Description
Image srcImage
System.Int32 targetWidth
System.Int32 targetHeight
System.Int32 xDpi
System.Int32 yDpi
System.Nullable<System.Drawing.Color> bColor
Returns
Type Description
Image

NormalizeCenteredImage(Image, Int32, Int32, Int32, Int32)

Scales source image so it fits in the desired image size preserving aspect ratio. This function is usable for profile picture size/aspect normalization

Declaration
public static Image NormalizeCenteredImage(this Image srcImage, int targetWidth = 128, int targetHeight = 128, int xDpi = 96, int yDpi = 96)
Parameters
Type Name Description
Image srcImage
System.Int32 targetWidth
System.Int32 targetHeight
System.Int32 xDpi
System.Int32 yDpi
Returns
Type Description
Image
Back to top Copyright © 2006-2018 Agnicore Inc
Generated by DocFX