1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System.Drawing;
- using System.Drawing.Imaging;
- namespace Microsoft.Windows.Forms
- {
- public static partial class RenderEngine
- {
-
-
-
-
-
- public static Bitmap GetGrayImage(Image originImage)
- {
- int width = originImage.Width;
- int height = originImage.Height;
- Bitmap newBitmap = new Bitmap(width, height);
-
- using (Graphics g = Graphics.FromImage(newBitmap))
- {
-
- if (m_DisabledImageAttr == null)
- {
-
- ColorMatrix colorMatrix = new ColorMatrix(new float[][]
- {
- new float[] {0.2125f, 0.2125f, 0.2125f, 000f, 000f},
- new float[] {0.2577f, 0.2577f, 0.2577f, 000f, 000f},
- new float[] {0.0361f, 0.0361f, 0.0361f, 000f, 000f},
- new float[] {000000f, 000000f, 000000f, 001f, 000f},
- new float[] {0.3800f, 0.3800f, 0.3800f, 000f, 001f}
- });
-
- m_DisabledImageAttr = new ImageAttributes();
- m_DisabledImageAttr.SetColorMatrix(colorMatrix);
- }
-
- g.DrawImage(originImage, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel, m_DisabledImageAttr);
- }
-
- return newBitmap;
- }
-
-
-
-
-
-
- public static Bitmap GetTransparentImage(Image originImage, float opacity)
- {
- int width = originImage.Width;
- int height = originImage.Height;
- Bitmap newBitmap = new Bitmap(width, height);
-
- using (Graphics graphics = Graphics.FromImage(newBitmap))
- {
-
- using (ImageAttributes imgAttr = new ImageAttributes())
- {
- ColorMatrix clrMatrix = new ColorMatrix();
- clrMatrix.Matrix33 = opacity;
- imgAttr.SetColorMatrix(clrMatrix);
-
- graphics.DrawImage(originImage, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel, imgAttr);
- }
- }
-
- return newBitmap;
- }
-
-
-
-
-
-
- public static Bitmap GetStretchImage(Image originImage, Size size)
- {
- if (originImage == null || size.Width <= 0 || size.Height <= 0)
- return null;
- Bitmap newBitmap = new Bitmap(size.Width, size.Height);
- using (Graphics g = Graphics.FromImage(newBitmap))
- {
- g.DrawImage(originImage, new Rectangle(0, 0, size.Width, size.Height));
- }
- return newBitmap;
- }
- }
- }
|