add: images.load(), landscape param of requestScreenCapture()
This commit is contained in:
@@ -19,8 +19,12 @@ module.exports = function(__runtime__, scope){
|
||||
|
||||
images.read = rtImages.read.bind(rtImages);
|
||||
|
||||
images.load = rtImages.load.bind(rtImages);
|
||||
|
||||
images.saveImage = rtImages.saveImage.bind(rtImages);
|
||||
|
||||
images.save = rtImages.saveImage;
|
||||
|
||||
images.pixel = rtImages.pixel;
|
||||
|
||||
images.detectsColor = function(img, color, x, y, threshold, algorithm){
|
||||
|
||||
@@ -103,7 +103,7 @@ public class ImageWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public int getPixel(int x, int y) {
|
||||
public int pixel(int x, int y) {
|
||||
if (mBitmap != null) {
|
||||
return mBitmap.getPixel(x, y);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.stardust.autojs.runtime.api;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
@@ -15,6 +14,8 @@ import android.view.Display;
|
||||
import android.view.Surface;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.nickandjerry.dynamiclayoutinflator.lib.ImageLoader;
|
||||
import com.nickandjerry.dynamiclayoutinflator.lib.util.Drawables;
|
||||
import com.stardust.autojs.annotation.ScriptVariable;
|
||||
import com.stardust.autojs.core.image.ColorFinder;
|
||||
import com.stardust.autojs.core.image.ImageWrapper;
|
||||
@@ -23,7 +24,6 @@ import com.stardust.autojs.core.image.ScreenCapturer;
|
||||
import com.stardust.autojs.core.image.TemplateMatching;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.concurrent.VolatileBox;
|
||||
import com.stardust.concurrent.VolatileDispose;
|
||||
import com.stardust.pio.UncheckedIOException;
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
@@ -35,6 +35,9 @@ import org.opencv.core.Rect;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@@ -77,6 +80,14 @@ public class Images {
|
||||
return requestResult.blockedGetOrThrow(ScriptInterruptedException.class);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public boolean requestScreenCapture(boolean landscape) {
|
||||
if (!landscape)
|
||||
return requestScreenCapture(ScreenMetrics.getDeviceScreenWidth(), ScreenMetrics.getDeviceScreenHeight());
|
||||
else
|
||||
return requestScreenCapture(ScreenMetrics.getDeviceScreenHeight(), ScreenMetrics.getDeviceScreenWidth());
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public boolean requestScreenCapture() {
|
||||
if (mDisplay.getRotation() == Surface.ROTATION_0 || mDisplay.getRotation() == Surface.ROTATION_180)
|
||||
@@ -125,7 +136,7 @@ public class Images {
|
||||
public static int pixel(ImageWrapper image, int x, int y) {
|
||||
x = ScreenMetrics.rescaleX(x, image.getWidth());
|
||||
y = ScreenMetrics.rescaleY(y, image.getHeight());
|
||||
return image.getPixel(x, y);
|
||||
return image.pixel(x, y);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +145,20 @@ public class Images {
|
||||
return ImageWrapper.ofBitmap(bitmap);
|
||||
}
|
||||
|
||||
public ImageWrapper load(String src) {
|
||||
try {
|
||||
URL url = new URL(src);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.connect();
|
||||
InputStream input = connection.getInputStream();
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(input);
|
||||
return ImageWrapper.ofBitmap(bitmap);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveBitmap(Bitmap bitmap, String path) {
|
||||
try {
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(path));
|
||||
|
||||
Reference in New Issue
Block a user