Class GraphicUtils
Windows GDI+ graphics utilities for the report engine: DPI scaling, grid drawing, text measurement,
font-style conversions, metafile/bitmap rendering and image codec, scaling and format helpers.
Assembly: Reportman.Drawing.Windows.dll
Syntax
public class GraphicUtils
Constructors
View Source
GraphicUtils()
Declaration
Fields
View Source
DefaultDPI
Declaration
public static int DefaultDPI
Field Value
Properties
View Source
DPIScale
Declaration
public static float DPIScale { get; }
Property Value
View Source
DPIScaleX
Declaration
public static float DPIScaleX { get; }
Property Value
View Source
DPIScaleY
Declaration
public static float DPIScaleY { get; }
Property Value
Methods
View Source
ConvertToBitonal(Bitmap, int)
Declaration
public static Bitmap ConvertToBitonal(Bitmap original, int threshold)
Parameters
| Type |
Name |
Description |
| Bitmap |
original |
|
| int |
threshold |
|
Returns
View Source
Declaration
public static Metafile CreateWindowsMetafile(int Width, int Height)
Parameters
| Type |
Name |
Description |
| int |
Width |
|
| int |
Height |
|
Returns
View Source
DrawGrid(Graphics, int, int, int, int, Color, bool, int, int, double)
Draw a grid given a distance in twips
Declaration
public static void DrawGrid(Graphics gr, int XWidth, int XHeight, int PixelsWidth, int PixelsHeight, Color GridColor, bool Lines, int XOffset, int YOffset, double Scale)
Parameters
| Type |
Name |
Description |
| Graphics |
gr |
Destination
|
| int |
XWidth |
Width in twips (1440 twips=1 inch)
|
| int |
XHeight |
Height in twips
|
| int |
PixelsWidth |
Width in pixels
|
| int |
PixelsHeight |
Height in pixels
|
| Color |
GridColor |
Color of the points or lines drawn
|
| bool |
Lines |
Set to true to draw lines instead of points
|
| int |
XOffset |
Horizontal offset
|
| int |
YOffset |
Vertical offset
|
| double |
Scale |
Scale the grid, set to 1.0 to draw in real size
|
View Source
ExifRotate(Image)
Declaration
public static bool ExifRotate(Image img)
Parameters
| Type |
Name |
Description |
| Image |
img |
|
Returns
View Source
FontStyleFromInteger(int)
Create a FontStyle from integer
Declaration
public static FontStyle FontStyleFromInteger(int intfontstyle)
Parameters
| Type |
Name |
Description |
| int |
intfontstyle |
|
Returns
View Source
GetAvgFontSizeTwips(string, float, FontStyle)
Declaration
public static Size GetAvgFontSizeTwips(string FontFamily, float FontSize, FontStyle FStyle)
Parameters
Returns
View Source
GetBitmapGrid(int, int, int, int, Color, Color, bool, double)
Obtain a bitmap to perform fast drawing of a grid,
so consecutive calls with similar parameters will execute faster.
The implementation uses a shared bitmap.
Declaration
public static Bitmap GetBitmapGrid(int Width, int Height, int GWidth, int GHeight, Color GColor, Color BackColor, bool Lines, double Scale)
Parameters
Returns
View Source
GetEncoderInfo(string)
Declaration
public static ImageCodecInfo GetEncoderInfo(string mimeType)
Parameters
| Type |
Name |
Description |
| string |
mimeType |
|
Returns
View Source
GetImageCodec(string)
Retuns a codec with the mime type or null if not found
Declaration
public static ImageCodecInfo GetImageCodec(string mimeType)
Parameters
| Type |
Name |
Description |
| string |
mimeType |
Codec string, example "image/jpeg"
|
Returns
View Source
GetImageCodecFromExtension(string)
Retuns a codec with the mime type or null if not found
Declaration
public static ImageCodecInfo GetImageCodecFromExtension(string extension)
Parameters
| Type |
Name |
Description |
| string |
extension |
|
Returns
View Source
GetImageCodecs()
Obtain a list of available image codecs
Declaration
public static Strings GetImageCodecs()
Returns
| Type |
Description |
| Strings |
A list, string collection of image codecs
|
View Source
GetImageGrid(int, int, int, int, Color, Color, bool, double)
Obtain a Image (Metafile or Bitmap) to perform fast drawing of a grid,
so consecutive calls with similar parameters will execute faster.
The implementation uses a shared bitmap or metafile.
Declaration
public static Image GetImageGrid(int Width, int Height, int GWidth, int GHeight, Color GColor, Color BackColor, bool Lines, double Scale)
Parameters
Returns
View Source
GetInvertedBlackWhite(Color)
Declaration
public static Color GetInvertedBlackWhite(Color c)
Parameters
| Type |
Name |
Description |
| Color |
c |
|
Returns
View Source
Obtain a metafile to perform fast drawing of a grid,
so consecutive calls with similar parameters will execute faster.
The implementation uses a shared metafile.
Declaration
public static Metafile GetMetafileGrid(int Width, int Height, int GWidth, int GHeight, Color GColor, Color BackColor, bool Lines, double Scale)
Parameters
Returns
View Source
GetMimeType(Image)
Declaration
public static string GetMimeType(Image i)
Parameters
| Type |
Name |
Description |
| Image |
i |
|
Returns
View Source
GetRotateFlipTypeByExifOrientationData(int)
Declaration
public static RotateFlipType GetRotateFlipTypeByExifOrientationData(int orientation)
Parameters
| Type |
Name |
Description |
| int |
orientation |
|
Returns
View Source
GetRoundedLine(PointF[], float)
Declaration
public static GraphicsPath GetRoundedLine(PointF[] points, float cornerRadius)
Parameters
| Type |
Name |
Description |
| PointF[] |
points |
|
| float |
cornerRadius |
|
Returns
View Source
ImageFromStream(Stream)
Returns a Image from stream. Do rotation for jpeg camera images
Declaration
public static Image ImageFromStream(Stream mstream)
Parameters
| Type |
Name |
Description |
| Stream |
mstream |
Memory stream to read Image from
|
Returns
| Type |
Description |
| Image |
Image object
|
View Source
ImageToByteArray(Image)
Declaration
public static byte[] ImageToByteArray(Image nimage)
Parameters
| Type |
Name |
Description |
| Image |
nimage |
|
Returns
View Source
ImageToStream(Image)
Declaration
public static MemoryStream ImageToStream(Image nimage)
Parameters
| Type |
Name |
Description |
| Image |
nimage |
|
Returns
View Source
IntegerFromFontStyle(FontStyle)
Declaration
public static int IntegerFromFontStyle(FontStyle astyle)
Parameters
Returns
View Source
IntegerFromStringFontStyle(string)
Declaration
public static int IntegerFromStringFontStyle(string sfontstyle)
Parameters
| Type |
Name |
Description |
| string |
sfontstyle |
|
Returns
View Source
LengthenLine(PointF, ref PointF, float)
Declaration
public static void LengthenLine(PointF startPoint, ref PointF endPoint, float pixelCount)
Parameters
View Source
MeasureDisplayStringWidth(Graphics, string, Font)
Calculates the with in current graphics units of a text
Declaration
public static double MeasureDisplayStringWidth(Graphics graphics, string text, Font font)
Parameters
| Type |
Name |
Description |
| Graphics |
graphics |
Graphics object where the measurement will be done
|
| string |
text |
Text to be measured
|
| Font |
font |
Font used for the measurement
|
Returns
| Type |
Description |
| double |
Width in graphic units of the measured text
|
View Source
RemapImageTransparentColor(Image, Color)
Declaration
public static Image RemapImageTransparentColor(Image img, Color OldColor)
Parameters
Returns
View Source
ScaleBitmapDPI(Image)
Declaration
public static Image ScaleBitmapDPI(Image image)
Parameters
| Type |
Name |
Description |
| Image |
image |
|
Returns
View Source
ScaleToDPI(int)
Declaration
public static int ScaleToDPI(int pixels)
Parameters
| Type |
Name |
Description |
| int |
pixels |
|
Returns
View Source
ScaledBitmapRatio(Image, int, int, bool)
Scale bitmap to a maximum of width and height
Declaration
public static Image ScaledBitmapRatio(Image image, int width, int height, bool highquality)
Parameters
Returns
View Source
ScaledBitmapRatio(Image, int, int, bool, bool)
Declaration
public static Image ScaledBitmapRatio(Image image, int width, int height, bool highquality, bool allowexpand)
Parameters
Returns
View Source
ScreenDPI()
Declaration
public static int ScreenDPI()
Returns
View Source
ScreenDPIX()
Declaration
public static int ScreenDPIX()
Returns
View Source
ScreenDPIY()
Declaration
public static int ScreenDPIY()
Returns
View Source
SimpleThresholdBW(byte[], int, int, int, int, int)
Declaration
public static byte[] SimpleThresholdBW(byte[] sourceBuffer, int width, int height, int srcStride, int dstStride, int threshold)
Parameters
| Type |
Name |
Description |
| byte[] |
sourceBuffer |
|
| int |
width |
|
| int |
height |
|
| int |
srcStride |
|
| int |
dstStride |
|
| int |
threshold |
|
Returns
View Source
StringFontStyleFromInteger(int)
Declaration
public static string StringFontStyleFromInteger(int intstyle)
Parameters
| Type |
Name |
Description |
| int |
intstyle |
|
Returns
View Source
StringFromFontStyle(FontStyle)
Declaration
public static string StringFromFontStyle(FontStyle astyle)
Parameters
Returns
View Source
TextToBitmap(int, string, string, float)
Converts a text to his representation in bitmap form
Declaration
public static Bitmap TextToBitmap(int width, string text, string fontfamily, float fontsize)
Parameters
| Type |
Name |
Description |
| int |
width |
Witdh of the resulting bitmap
|
| string |
text |
Text to be printed into the bitmap
|
| string |
fontfamily |
Font family
|
| float |
fontsize |
Font size
|
Returns
| Type |
Description |
| Bitmap |
Returns a bitmap with the text drawn on it
|
View Source
Write a Windows Metafile into a stream
Declaration
public static void WriteWindowsMetaFile(Metafile metaf, Stream destination, float Scale)
Parameters
| Type |
Name |
Description |
| Metafile |
metaf |
Metafile to write
|
| Stream |
destination |
Stream destination
|
| float |
Scale |
Scale of the Windows Metafile
|
View Source
Convert a windows metafile to a image format saved into a stream
Declaration
public static void WriteWindowsMetaFileCodec(Metafile metaf, Stream destination, float Scale, string codecstring, out string mimetype)
Parameters
| Type |
Name |
Description |
| Metafile |
metaf |
Windows Metafile to be converted
|
| Stream |
destination |
Destination stream
|
| float |
Scale |
Scale of the metafile
|
| string |
codecstring |
Codec to be used you can obtain a list by using GetImageCodecs
|
| string |
mimetype |
Mimetype of the selected codec
|