이미지가 포함 된 타사 앱에서 컨트롤을 걷고 있습니다. 자동화 요소는 클래스 이름 Image, 이미지의 내용을 비트 맵 객체 또는 바이트로 가져 오는 방법에 대한 아이디어를 반환합니다.Image 클래스의 내용 가져 오기 AutomationElement에서
0
A
답변
0
이 토론은 유용 할 수 있습니다 : Capturing an image behind a rectangle.
AutomationElement의 BoundingRectangle 속성을 사용하면 스냅 샷을 만들면됩니다.
0
이 질문은 오래된 것이지만,이 문제를 해결할 때 답변을 추가하고 싶습니다.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Automation;
namespace AutomationElementExtension
{
public static class AutomationElementExtension
{
public static Bitmap ToBitmap(this AutomationElement automationElement)
{
var boundingRectangle = automationElement.Current.BoundingRectangle;
var bitmap = new Bitmap(Convert.ToInt32(boundingRectangle.Width), Convert.ToInt32(boundingRectangle.Height), PixelFormat.Format32bppArgb);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(Convert.ToInt32(boundingRectangle.X), Convert.ToInt32(boundingRectangle.Y), Point.Empty.X, Point.Empty.Y, bitmap.Size);
}
return bitmap;
}
}
}
그런 다음
var bitmap = myAutomationElement.ToBitmap();
로 호출하여 비트 맵으로 이미지를 얻을 수 있습니다