Libraryless. Click here for Pure Java version (6670L/38K).
1 | static boolean loadBufferedImage_useImageCache = true; |
2 | |
3 | static BufferedImage loadBufferedImage(String snippetIDOrURLOrFile) ctex { |
4 | ping(); |
5 | if (snippetIDOrURLOrFile == null) ret null; |
6 | if (isURL(snippetIDOrURLOrFile)) |
7 | ret imageIO_readURL(snippetIDOrURLOrFile); |
8 | |
9 | if (isSnippetID(snippetIDOrURLOrFile)) { |
10 | S snippetID = "" + parseSnippetID(snippetIDOrURLOrFile); |
11 | |
12 | ifndef NoResourceLoader |
13 | IResourceLoader rl = vm_getResourceLoader(); |
14 | if (rl != null) |
15 | ret loadBufferedImage(rl.loadLibrary(snippetID)); |
16 | endifndef |
17 | |
18 | File dir = imageSnippetsCacheDir(); |
19 | if (loadBufferedImage_useImageCache) { |
20 | dir.mkdirs(); |
21 | File file = new File(dir, snippetID + ".png"); |
22 | if (file.exists() && file.length() != 0) |
23 | try { |
24 | return ImageIO.read(file); |
25 | } catch (Throwable e) { |
26 | e.printStackTrace(); |
27 | // fall back to loading from sourceforge |
28 | } |
29 | } |
30 | |
31 | String imageURL = snippetImageURL_http(snippetID); |
32 | print("Loading image: " + imageURL); |
33 | BufferedImage image = imageIO_readURL(imageURL); |
34 | |
35 | if (loadBufferedImage_useImageCache) { |
36 | File tempFile = new File(dir, snippetID + ".tmp." + System.currentTimeMillis()); |
37 | ImageIO.write(image, "png", tempFile); |
38 | tempFile.renameTo(new File(dir, snippetID + ".png")); |
39 | //Log.info("Cached image."); |
40 | } |
41 | |
42 | //Log.info("Loaded image."); |
43 | return image; |
44 | } else |
45 | ret loadBufferedImage(new File(snippetIDOrURLOrFile)); |
46 | } |
47 | |
48 | static BufferedImage loadBufferedImage(File file) { |
49 | ret loadBufferedImageFile(file); |
50 | } |
download show line numbers debug dex old transpilations
Travelled to 19 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, ofpaelxlmzfo, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wnsclhtenguj
No comments. add comment
Snippet ID: | #1003723 |
Snippet name: | loadBufferedImage - also takes a file path |
Eternal ID of this version: | #1003723/14 |
Text MD5: | 935506e5b3fa3ad1ef059537c4ddd00e |
Transpilation MD5: | 6007f20e13853b4da929f3c201da2634 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-08 19:32:23 |
Source code size: | 1628 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 879 / 1042 |
Version history: | 13 change(s) |
Referenced in: | [show references] |