← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #199590]: Screen resolution and regions location and size

 

Question #199590 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/199590

Cobra posted a new comment:
Brother! When working with different resolutions, I personally dislike
using Region as I found it to be a nightmare. Put the image pattern in a
loop and keep decreasing the similarity until the image is found on the
new resolution. I wrote a function to do this and If I run the tests on
new resolution, It grabs all the images by itself and then use them. The
below snippet shows the logic. Try to get as much as you can from it as
I cannot include the entire project here. And I have to agree Sikuli is
a First class tool.

public commonFunctions Find(Object object) throws Exception {

outerloop: for (int second = 0 ;; second++) {

if (second >= sikuliSetup.getWait())

Assert.fail("timedout finding " +
getElementAndMatchExtent.ImageName(object).getElement() + " after " +
second + " secs");

if(Resolution.contains("new")){ //Resolution is a property in config
file

try {
				
innerloop: for (float i= getElementAndMatchExtent.ImageName(object).getMatchExtent() ; i>=0.1 ; i-=0.1){  //Decreasing the similarity by 0.1 until image is found on the new resolution.
					    
Float f = new Float(String.format("%.2f", i));	
					    
if(com().CheckImage(object, f)==true){					    									    
					
Region region = getScreen().find(commonFunctions.Pattern(getElementAndMatchExtent.ImageName(object).getElement()).similar((Float) f));
						
ScreenImage img = getScreen().capture(region);
						
BufferedImage bf = img.getImage();
						
File file = new File(CurrentDirectory() + "\\Elements\\" + getElementAndMatchExtent.ImageName(object).getElement() + ".png");
						
ImageIO.write(bf, "png", file);						
						
break innerloop;
					    
}						
				
}			    
				
} catch (Exception e) { }
			
}						
				
try {
					
getScreen().find(com().ImagePattern(object));
					
break outerloop;
				
} catch (Exception e) {}									
			
Thread.sleep(1000);
		
}		
		
return com();

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.