Skip to content

Commit

Permalink
新增设置截图横竖屏方法
Browse files Browse the repository at this point in the history
  • Loading branch information
qiushui95 committed Dec 15, 2023
1 parent bbb2589 commit fd7f4d9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autojs/src/main/assets/modules/__images__.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = function (runtime, scope) {
function images() {
}
if (android.os.Build.VERSION.SDK_INT >= 21) {
util.__assignFunctions__(runtime.images, images, ['captureScreen', 'read', 'copy', 'load', 'clip', 'pixel'])
util.__assignFunctions__(runtime.images, images, ['captureScreen','setPortrait','setLandscape', 'read', 'copy', 'load', 'clip', 'pixel'])
}
images.opencvImporter = JavaImporter(
org.opencv.core.Point,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ public void setOrientation(int orientation) {
mOrientation = orientation;
mDetectedOrientation = mContext.getResources().getConfiguration().orientation;
refreshVirtualDisplay(mOrientation == ORIENTATION_AUTO ? mDetectedOrientation : mOrientation);

Image oldImage = mCachedImage.getAndSet(mImageReader.acquireNextImage());

if (oldImage != null) {
oldImage.close();
}
}


Expand Down
25 changes: 24 additions & 1 deletion autojs/src/main/java/com/stardust/autojs/runtime/api/Images.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public ScriptPromiseAdapter requestScreenCapture(int orientation) {

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public synchronized ImageWrapper captureScreen() {
try {
throw new RuntimeException();
} catch (Exception ex) {
ex.printStackTrace();
}

ScriptRuntime.requiresApi(21);
if (mScreenCapturer == null) {
throw new SecurityException("No screen capture permission");
Expand Down Expand Up @@ -126,6 +132,23 @@ public boolean captureScreen(String path) {
return false;
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void setPortrait() {

if (mScreenCapturer == null) return;

mScreenCapturer.setOrientation(ScreenCapturer.ORIENTATION_PORTRAIT);
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void setLandscape() {

if (mScreenCapturer == null) return;

mScreenCapturer.setOrientation(ScreenCapturer.ORIENTATION_LANDSCAPE);

}

public ImageWrapper copy(ImageWrapper image) {
return image.clone();
}
Expand All @@ -140,7 +163,7 @@ public boolean save(ImageWrapper image, String path, String format, int quality)
boolean compress = bitmap.compress(compressFormat, quality, outputStream);
outputStream.flush();
return compress;
}finally {
} finally {
outputStream.close();
}
}
Expand Down

0 comments on commit fd7f4d9

Please # to comment.