InventorySlots are capturing images but are offset

This commit is contained in:
davpapp 2018-01-31 09:05:34 -05:00
parent 4ae57f7d49
commit 732c9e9aca
10 changed files with 87 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -22,6 +22,16 @@ public class Cursor {
public static final int MINIMUM_CLICK_LENGTH = 120;
public static final int MAXIMUM_CLICK_LENGTH = 240;
public static final int GAME_WINDOW_OFFSET_WIDTH = 100; // top left corner of main game screen, from top left corner of screen
public static final int GAME_WINDOW_OFFSET_HEIGHT = 81;
public static final int INVENTORY_OFFSET_WIDTH = 649; //top left corner of inventory, fromm top left corner of screen
public static final int INVENTORY_OFFSET_HEIGHT = 286;
public static final int INVENTORY_WIDTH = 820 - 649;// 820
public static final int INVENTORY_HEIGHT = 530 - 286; // 530
private Robot robot;
private Random random = new Random();

View File

@ -9,7 +9,7 @@ public class CursorTask extends Cursor {
public void dropAllItemsInInventory() {
for (int inventoryColumn = 0; inventoryColumn < 7; inventoryColumn++) {
for (int inventoryRow = 0; inventoryRow < 4; inventoryRow++) {
dropItem
//dropItem
}
}
}

View File

@ -1,19 +1,47 @@
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class Inventory {
public static final int INVENTORY_OFFSET_WIDTH = 649; //top left corner of inventory, fromm top left corner of screen
public static final int INVENTORY_OFFSET_HEIGHT = 286;
public static final int INVENTORY_WIDTH = 820 - 649;// 820
public static final int INVENTORY_HEIGHT = 530 - 286; // 530
Robot robot;
Rectangle inventoryAreaToCapture;
InventorySlot[][] inventorySlots;
public Inventory() {
public Inventory() throws AWTException {
initializeInventorySlots();
robot = new Robot();
this.inventoryAreaToCapture = new Rectangle(INVENTORY_OFFSET_WIDTH, INVENTORY_OFFSET_HEIGHT, INVENTORY_WIDTH, INVENTORY_HEIGHT);
}
private void initializeInventorySlots() {
inventorySlots = new InventorySlot[4][7];
for (int row = 0; row < 7; row++) {
for (int column = 0; column < 4; column++) {
inventorySlots[column][row] = new InventorySlot();
for (int row = 0; row < 4; row++) {
for (int column = 0; column < 7; column++) {
// might need to manually create these
inventorySlots[row][column] = new InventorySlot(row, column);
}
}
}
public void update() {
// Screenshot
public void update() throws IOException {
BufferedImage image = robot.createScreenCapture(this.inventoryAreaToCapture);
updateAllInventorySlots(image);
}
private void updateAllInventorySlots(BufferedImage image) throws IOException {
for (int row = 0; row < 4; row++) {
for (int column = 0; column < 7; column++) {
inventorySlots[row][column].writeInventorySlotToImage(image, row, column);
}
}
}
}

View File

@ -1,13 +1,45 @@
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class InventorySlot {
private static final int INVENTORY_WIDTH = 171;
private static final int INVENTORY_HEIGHT = 244;
String screenshotOutputDirectory;
Item itemInInventorySlot;
Rectangle rectangleToCapture;
public InventorySlot() {
public InventorySlot(int row, int column) {
initializeRectangleToCapture(row, column);
this.screenshotOutputDirectory = "/home/dpapp/Desktop/RunescapeAIPics/InventorySlots/";
}
private void initializeRectangleToCapture(int row, int column) {
int slotWidth = INVENTORY_WIDTH / 4;
int slotHeight = INVENTORY_HEIGHT / 7;
//System.out.println("SlotWidth: " + slotWidth + ", slotHeight: " + slotHeight);
rectangleToCapture = new Rectangle(row * slotWidth, column * slotHeight, slotWidth, slotHeight);
}
public void updateInventorySlot(BufferedImage image) {
//BufferedImage croppedInventorySlotArea = image.getSubimage(rectangleToCapture.x, rectangleToCapture.y, rectangleToCapture.width, rectangleToCapture.height);
}
public void writeInventorySlotToImage(BufferedImage image, int row, int column) throws IOException {
System.out.println("Pre-cropped image is of size:" + image.getWidth() + ", " + image.getHeight());
System.out.println(row + ", " + column);
System.out.println("Getting image from: " + rectangleToCapture.x + ", " + rectangleToCapture.y + ", " + rectangleToCapture.width + ", " + rectangleToCapture.height);
BufferedImage croppedInventorySlotArea = image.getSubimage(rectangleToCapture.x, rectangleToCapture.y, rectangleToCapture.width, rectangleToCapture.height);
ImageIO.write(croppedInventorySlotArea, "png", new File(getImageName(row, column)));
}
private String getImageName(int row, int column) {
return this.screenshotOutputDirectory + "screenshot" + row + "_" + column + ".png";
}
}

View File

@ -1,13 +1,18 @@
import java.awt.AWTException;
import java.awt.Point;
import java.io.IOException;
import java.net.URL;
public class main {
public static void main(String[] args) throws AWTException, InterruptedException {
public static void main(String[] args) throws AWTException, InterruptedException, IOException {
Cursor cursor = new Cursor();
//Cursor cursor = new Cursor();
Inventory inventory = new Inventory();
inventory.update();
System.out.println("Success!");
//cursor.moveCursorToCoordinates(new Point(620, 420));
}