-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also remove file prefix option as it might not be necessary.
- Loading branch information
Showing
2 changed files
with
28 additions
and
10 deletions.
There are no files selected for viewing
22 changes: 18 additions & 4 deletions
22
celebrity/src/main/java/com/github/rtyley/android/screenshot/celebrity/Screenshots.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 10 additions & 6 deletions
16
...o/src/main/java/com/github/rtyley/android/screenshot/paparazzo/processors/ImageSaver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
package com.github.rtyley.android.screenshot.paparazzo.processors; | ||
|
||
import static java.lang.String.format; | ||
import static java.lang.System.currentTimeMillis; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.text.NumberFormat; | ||
import java.util.Map; | ||
|
||
public class ImageSaver implements ScreenshotProcessor { | ||
|
||
private final File screenshotDirectory; | ||
private final String fileNamePrefix; | ||
private int screenshotCount = 0; | ||
|
||
public ImageSaver(File screenshotDirectory, String fileNamePrefix) { | ||
public ImageSaver(File screenshotDirectory) { | ||
this.screenshotDirectory = screenshotDirectory; | ||
this.fileNamePrefix = fileNamePrefix; | ||
} | ||
|
||
@Override | ||
public void process(BufferedImage image, Map<String, String> requestData) { | ||
File screenshotFile = new File(screenshotDirectory, fileNamePrefix + "-" + currentTimeMillis() + ".png"); | ||
public void process(BufferedImage image, Map<String, String> request) { | ||
String name=request.containsKey("name")?request.get("name"):format("%04d", screenshotCount++); | ||
|
||
File screenshotFile = new File(screenshotDirectory, name + ".png"); | ||
try { | ||
// log.info("Writing " + screenshotFile.getAbsolutePath()); | ||
ImageIO.write(image, "png", screenshotFile); | ||
} catch (IOException e) { | ||
// log error? | ||
} | ||
} | ||
|
||
@Override | ||
public void finish() { | ||
// No resources to dispose of | ||
} | ||
|
||
} |