123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.VisualBasic.PowerPacks;
- using System.Drawing.Drawing2D;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- namespace IControls_FireManager
- {
-
- public static class _Graphic
- {
-
- public static void LineShape_Start(LineShape lineshape, int x, int y)
- {
- try
- {
- lineshape.X1 = x;
- lineshape.Y1 = y;
- }
- catch
- {
- }
- }
-
- public static void LineShape_End(LineShape lineshape, int x, int y)
- {
- try
- {
- lineshape.X2 = x;
- lineshape.Y2 = y;
- }
- catch
- {
- }
- }
-
- public static void LineShape_BorderStyle(LineShape lineshape, DashStyle dashstyle, Color color, int borderwidth)
- {
- try
- {
- lineshape.BorderStyle = dashstyle;
- lineshape.BorderColor = color;
- lineshape.BorderWidth = borderwidth;
- }
- catch
- {
- }
- }
-
- public static void RectangleShape_BorderStyle(RectangleShape rectangleshape, DashStyle dashstyle, Color color, int borderwidth)
- {
- try
- {
- rectangleshape.BorderStyle = dashstyle;
- rectangleshape.BorderColor = color;
- rectangleshape.BorderWidth = borderwidth;
- }
- catch
- {
- }
- }
-
- public static void Rectangle_Create(ShapeContainer shapecontainer, string Key,
- DashStyle dashstyle, Color linecolor, Color backcolor, int BorderWidth, int x, int y, int w, int h)
- {
- try
- {
- RectangleShape rect = new RectangleShape();
- rect.Name = Key;
- if (backcolor == Color.Transparent)
- {
- rect.BackStyle = BackStyle.Transparent;
- }
- else
- {
- rect.BackStyle = BackStyle.Opaque;
- rect.BackColor = backcolor;
- }
- rect.Location = new Point(x, y);
- rect.Size = new Size(w, h);
- rect.BorderStyle = dashstyle;
- rect.BorderWidth = BorderWidth;
- rect.BorderColor = linecolor;
- shapecontainer.Shapes.Add(rect);
- }
- catch
- {
- }
- }
-
-
- public static int[] GetRectangleInfo_ByLineShape(ShapeContainer ShapeLines)
- {
- int[] result = new int[4];
-
-
-
-
- try
- {
-
- int min_x = ShapeLines.Width;
- int min_y = ShapeLines.Height;
-
- int max_x = 0;
- int max_y = 0;
- foreach (Shape shape in ShapeLines.Shapes)
- {
- if (shape.GetType().Name.ToString() == "LineShape")
- {
- LineShape line = (LineShape)shape;
-
- if (line.X1 >= max_x) max_x = line.X1;
- if (line.X2 >= max_x) max_x = line.X2;
- if (line.Y1 >= max_y) max_y = line.Y1;
- if (line.Y2 >= max_y) max_y = line.Y2;
-
- if (line.X1 <= min_x) min_x = line.X1;
- if (line.X2 <= min_x) min_x = line.X2;
- if (line.Y1 <= min_y) min_y = line.Y1;
- if (line.Y2 <= min_y) min_y = line.Y2;
- }
- }
-
- result[0] = min_x;
-
- result[1] = min_y;
-
- result[2] = max_x - min_x;
-
- result[3] = max_y - min_y;
- return result;
- }
- catch
- {
- return null;
- }
- }
-
- public static int ColorToInt(Color colorValue)
- {
- int r = colorValue.R;
- int g = colorValue.G << 8;
- int b = colorValue.B << 16;
- return r + g + b;
- }
- public static Color intToColor(int colorValue)
- {
- int r = (colorValue) & 0xFF;
- int g = (colorValue >> 8) & 0xFF;
- int b = (colorValue >> 16) & 0xFF;
- return Color.FromArgb(255, r, g, b);
- }
-
- public static void CurrentMousePoint_FillRectangle(Control control, int w, int h, Color color)
- {
- System.Drawing.Point ptMouse = Cursor.Position;
-
- Graphics g = control.CreateGraphics();
- ControlPaint.FillReversibleRectangle(new Rectangle(Cursor.Position, new Size(w, h)), color);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static bool Compare_Pixel(Image oImage, Image cImage)
- {
- Bitmap img1, img2;
- string img1_ref, img2_ref;
- int count1 = 0, count2 = 0;
- bool flag = true;
- img1 = new Bitmap(oImage);
- img2 = new Bitmap(cImage);
- if (img1.Width == img2.Width && img1.Height == img2.Height)
- {
- for (int i = 0; i < img1.Width; i++)
- {
- for (int j = 0; j < img1.Height; j++)
- {
- img1_ref = img1.GetPixel(i, j).ToString();
- img2_ref = img2.GetPixel(i, j).ToString();
- if (img1_ref != img2_ref)
- {
- count2++;
- flag = false;
- break;
- }
- count1++;
- }
- }
-
-
-
-
- return flag;
- }
- else
- return flag;
- }
-
-
-
- public static Image Capture_By_Component(Control component)
- {
- try
- {
- Bitmap memoryImage = null;
-
- Point real = component.PointToScreen(component.Location);
-
- Rectangle rc = new Rectangle(real.X - component.Location.X, real.Y - component.Location.Y, component.Width, component.Height);
-
- using (Graphics graphics = component.CreateGraphics())
- {
-
- graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
-
-
- memoryImage = new Bitmap(rc.Width, rc.Height, graphics);
-
- using (Graphics memoryGrahics = Graphics.FromImage(memoryImage))
- {
- memoryGrahics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, CopyPixelOperation.SourceCopy);
- }
- }
- return Image.FromHbitmap(memoryImage.GetHbitmap());
- }
- catch
- {
- return null;
- }
- }
-
- public static Image Get_By_byteArray(byte[] data)
- {
-
- if (data != null)
- return new Bitmap(new MemoryStream(data));
- else
- return null;
- }
-
- public static MemoryStream GetStream_For_SaveJpg(IntPtr Source, int Size, int height, int width)
- {
- MemoryStream pictureStream = new MemoryStream();
-
-
- int stride = -3 * width;
- IntPtr Scan0 = (IntPtr)(((int)Source) + (Size - (3 * width)));
-
-
-
-
-
-
-
-
-
-
-
-
- Bitmap img = new Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, Scan0);
-
- img.Save(pictureStream, System.Drawing.Imaging.ImageFormat.Jpeg);
- return pictureStream;
- }
- }
- }
|