-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathUnitys.java
71 lines (60 loc) · 2.19 KB
/
Unitys.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package image2d;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
/**
*
* @author pratchaya
*/
public class Unitys {
private static int IMAGE_TYPE;
//----------------------------------- helper method---------------------------------
// use to copy image
public static BufferedImage copyImage(BufferedImage _image) {
ColorModel cm = _image.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
WritableRaster raster = _image.copyData(null);
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
//-------------------
public int operation_Number(String operator, int operand1, int operand2) {
int _num = 0;
try {
_num = (operator.equals("+")) ? operand1 + operand2
: (operator.equals("-")) ? operand1 - operand2 : (operator.equals("*")) ? operand1 * operand2
: (operator.equals("/") && operand2 != 0) ? operand1 / operand2 : operand1 / operand2;
} catch (ArithmeticException e) {
e.getMessage();
}
return _num;
}
//-------------- set value array2D --------------------------//
public int[][] randArray(int arr[][], int val) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
// set value
arr[i][j] = val;
} // end j
} // end i
return arr;
}
public int[] randArray(int arr[], int val) {
for (int i = 0; i < arr.length; i++) {
arr[i] = val;
}
return arr;
}
public int getRGBExtended(BufferedImage image, int row, int col) {
int width = image.getWidth();
int height = image.getHeight();
row = Math.max(0, Math.min(height - 1, row));
col = Math.max(0, Math.min(width - 1, col));
return image.getRGB(col, row);
}
}