Transpiled version (13275L) is out of date.
1 | srecord noeq CutOutRegionFromImage(IImageRegion region) { |
2 | settable double alphaNonContained = 0.5; |
3 | |
4 | // optional |
5 | settable BufferedImage fullImage; |
6 | |
7 | // grow bounds by this many pixels to include surroundings |
8 | settable int margin; |
9 | |
10 | // optional |
11 | settable Rect rect; |
12 | |
13 | BufferedImage get() { |
14 | if (region == null) null; |
15 | fullImage if null = toBufferedImage(region.image()); |
16 | if (fullImage == null) null; |
17 | rect = region.bounds(); |
18 | rect = intersectRects(growRect(rect, margin), imageRect(fullImage)); |
19 | var clipped = clipBufferedImage(fullImage, rect); |
20 | int[] pixels = pixelsOfBufferedImage(clipped); |
21 | int w = rect.w, h = rect.h, i = 0; |
22 | for y to h: |
23 | for x to w: { |
24 | if (!region.contains(rect.x+x, rect.y+y)) |
25 | pixels[i] = withAlpha(alphaNonContained, pixels[i]); |
26 | ++i; |
27 | } |
28 | ret bufferedImageWithAlpha(w, h, pixels); |
29 | } |
30 | } |
Began life as a copy of #1035974
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1035977 |
Snippet name: | CutOutRegionFromImage |
Eternal ID of this version: | #1035977/6 |
Text MD5: | df5ed334708eba6dff40658abb64a9d7 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-08-20 20:15:01 |
Source code size: | 922 bytes / 30 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 120 / 196 |
Version history: | 5 change(s) |
Referenced in: | [show references] |