25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Bumpkit (1.0.1 Documentation)
2 | =============================
3 |
4 | This is a .NET library that extends the System.Drawing GDI libraries.
5 | Useful for on-the-fly image generation in .NET-based web applications.
6 |
7 | Features:
8 | ---------
9 | * Image sizing/scaling extensions
10 | * Image rotation extensions
11 | * Lightning-fast pixel manipulation
12 | * Animated GIF generation (utilizes native gif encoding)
13 | * Font bordering and glow effects (DrawString on steroids)
14 | * Other extensions (Point, Color, etc)
15 |
16 | Scaling:
17 | --------
18 | `System.Drawing.Image.ScaleToFit(...)`
19 | * Resize images with a single extension method
20 | * Maintain image aspect ratio sizing to a height or width or confine to a boundary
21 |
22 | Rotation:
23 | ---------
24 | `System.Drawing.Image.Rotate(...)`
25 | * Rotate images with a single extension method
26 | * Maintain image centering to boundaries and scale to fit or maintain sizing ratio
27 |
28 | Fast Pixel Access:
29 | ------------------
30 | `System.Drawing.Image.CreateUnsafeContext()`
31 | * Provides access to an Image's pixels in a locked session
32 | * Allows lightning-fast custom image manipulation
33 | * Provides direct memory access wrapped in a light-weight disposable context
34 |
35 | Animated GIF Generation:
36 | ------------------------
37 | `BumpKit.GifEncoder`
38 | * Formats multiple images/frames into a single animated GIF file
39 | * Utilizes native .NET GIF encoding (simply adds missing animation file-headers)
40 | * Fast (relative to other GIF libraries)
41 |
42 | Font Effects:
43 | -------------
44 | `System.Drawing.Graphics.DrawString(text, font, brush, x, y, border, borderColors, colorOffsets)`
45 | * Utilizes native .NET font processing
46 | * Fast effect generation
47 | * Flexible API implementation
48 |
49 | Samples:
50 | --------
51 | **Scaling an image to fit a specified size maintaining scale ratio**
52 | var scaledImage = Image.FromFile("").ScaleToFit(new Size(100, 100));
53 |
54 | **Scaling an image to "overflow" or "cover" a specified size maintaining scale ratio**
55 | var scaledImage = Image.FromFile("").ScaleToFit(new Size(100, 100), ScalingMode.Overflow);
56 |
57 | **Scaling an image without disposing the original image**
58 | var img = Image.FromFile("");
59 | var scaledImage = img.ScaleToFit(new Size(100, 100), false);
60 | var scaledImage2 = img.ScaleToFit(new Size(100, 100), false, ScalingMode.Overflow);
61 |
62 | **Stretching an image to fit a specified size**
63 | var stretchedImage = Image.FromFile("").Stretch(new Size(100, 100));
64 |
65 | **Rotating an image**
66 | var rotationOverflow = Image.FromFile("").Rotate(45);
67 | var rotationFit = Image.FromFile("").Rotate(45, ScalingMode.FitContent); // scales down to fit corner content
68 |
69 | **Detecting Image Edges (finding the crop points)**
70 | var pixelBoundary = Image.FromFile("").DetectPadding(); // you can also specify the background color if it is not transparent
71 |
72 | **Direct Memory Access (reading/writing pixels quickly)**
73 | // NOTE: This locks and accesses the bitmap's unmanaged memory. This is NOT thread-safe.
74 | var image = Image.FromFile("");
75 | using (var context = image.CreateUnsafeContext())
76 | {
77 | for (var x = 0; x < context.Width; x++)
78 | for (var y = 0; y < context.Height; y++)
79 | {
80 | var pixel = context.GetRawPixel(x, y);
81 | var average = Convert.ToByte((pixel.Red + pixel.Green + pixel.Blue)/3d);
82 | context.SetPixel(x, y, pixel.Alpha, average, average, average);
83 | }
84 | }
85 |
86 | **Animated Gif Encoding**
87 | using (var image = Image.FromFile(""))
88 | using (var gif = File.OpenWrite(""))
89 | using (var encoder = new GifEncoder(gif))
90 | for (var i = 0; i < 360; i += 10)
91 | using (var frame = image.Rotate(i, false))
92 | {
93 | encoder.AddFrame(frame);
94 | }
95 |
96 | **Font Borders**
97 | var img = new Bitmap(600, 200);
98 | using (var gfx = Graphics.FromImage(img))
99 | using (var font = new Font(SystemFonts.DefaultFont.FontFamily, 50))
100 | {
101 | gfx.SmoothingMode = SmoothingMode.AntiAlias;
102 | gfx.DrawString("ABCabc123", font, Brushes.Black, 0, 0, 50,
103 | new[] {Color.Red, Color.Green, Color.Blue},
104 | new[] {0f, 0.5f, 1f});
105 | }
106 |
--------------------------------------------------------------------------------