public static DesktopObject[] m_GetRunningAppfromTaskBar(DesktopObject TaskBar) { Bitmap TaskBarBitmap = TaskBar.ObjBitmap; double[,] filterMatrix = JIP_Matrix.RunningAppPattern; int threshold = 20; List<DesktopObject> apps = new List<DesktopObject>(); byte[] pixelBuffer = TaskBarBitmap.JIP_ToGray1D(); byte[] resultBuffer = new byte[pixelBuffer.Length]; int Stride = TaskBarBitmap.Width * 4; int filterWidth = filterMatrix.GetLength(1); int filterHeight = filterMatrix.GetLength(0); int filterOffsetWidth = (filterWidth) / 2; int filterOffsetHeight = (filterHeight) / 2; int calcOffset = 0; int byteOffset = 0; for (int offsetY = filterOffsetHeight; offsetY < TaskBarBitmap.Height - filterOffsetHeight; offsetY++) { int prevoffsetX = 0; for (int offsetX = filterOffsetWidth; offsetX < TaskBarBitmap.Width - filterOffsetWidth; offsetX++) { byteOffset = offsetY * Stride + offsetX * 4; int percAvg = 0; for (int filterY = -filterOffsetHeight; filterY < filterOffsetHeight; filterY++) { for (int filterX = -filterOffsetWidth; filterX < filterOffsetWidth; filterX++) { calcOffset = byteOffset + (filterX * 4) + (filterY * Stride); int diff = Math.Abs(pixelBuffer[calcOffset] - ((byte)filterMatrix[filterY + filterOffsetHeight, filterX + filterOffsetWidth])); if (diff < threshold) diff = 0; int perc = ((255 - diff) * 100) / 255; percAvg += perc; } } percAvg /= filterWidth * filterHeight; if (percAvg > 65 && Math.Abs(offsetX - prevoffsetX) > (filterWidth / 2))//65 { percAvg = 100; DesktopObject dObj = new DesktopObject(TaskBar.Screen); dObj.ObjPosition = new Rectangle(new Point(TaskBar.ObjPosition.X + offsetX - (filterWidth / 2), TaskBar.ObjPosition.Y + offsetY), new Size(filterWidth, TaskBarBitmap.Height) ); apps.Add(dObj); prevoffsetX = offsetX; } } } return apps.ToArray(); }
public static DesktopObject m_GetTaskBar(Bitmap Screen) { JIP_Line[] lines = Screen.JIP_GetHorizontalLines(); JIP_Line taskbarLine = lines[0]; //lines[lines.Length - 1]; int w = Math.Abs(taskbarLine.B.X - taskbarLine.A.X); int h = Math.Abs(Screen.Height - taskbarLine.A.Y); DesktopObject dObj = new DesktopObject(Screen); dObj.ObjPosition = new Rectangle(taskbarLine.A.X, taskbarLine.A.Y, w, h); return dObj; }