Using the Telegram Java API, images received are lower in quality. The handling within the code might be degrading resolution. Below is an alternative sample:
List<ImageData> imgs = update.getImages();
for (ImageData img : imgs) {
FileQuery query = new FileQuery(img.getUniqueId());
FileMeta meta = fetchFileMeta(query);
String fullUrl = BASE_URL + meta.getPath();
File localFile = retrieveFile(fullUrl);
byte[] imgContent = java.nio.file.Files.readAllBytes(localFile.toPath());
dbHandler.storeImage(imgContent);
}
private File retrieveFile(String urlStr) throws Exception {
URL url = new URL(urlStr);
InputStream stream = url.openStream();
File tempFile = new File(System.getProperty("user.home"), "temp_" + System.currentTimeMillis() + ".jpg");
java.nio.file.Files.copy(stream, tempFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
return tempFile;
}
byte[] imageData = dbHandler.getImage();
File outFile = new File("temp_send.jpg");
java.nio.file.Files.write(outFile.toPath(), imageData);
sendPhoto(update.getChatId(), outFile);
outFile.delete();