이미지파일 축소 기능 추가
parent
62b49426d5
commit
a3d6a34cd6
@ -0,0 +1,20 @@
|
||||
package cokr.xit.applib;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Pstn {
|
||||
public Pstn(float left, float top){
|
||||
this.left = left;
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
private float left;
|
||||
private float top;
|
||||
|
||||
public float[] to2Float() {
|
||||
return new float[] { this.left, this.top };
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
package cokr.xit.applib;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PstnAndSize {
|
||||
public PstnAndSize(float left, float top, float width, float height){
|
||||
this.left = left;
|
||||
this.top = top;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public PstnAndSize(Pstn pstn, Size size){
|
||||
this.left = pstn.getLeft();
|
||||
this.top = pstn.getTop();
|
||||
this.width = size.getWidth();
|
||||
this.height = size.getHeight();
|
||||
}
|
||||
|
||||
public PstnAndSize(Pstn pstn, float width, float height){
|
||||
this.left = pstn.getLeft();
|
||||
this.top = pstn.getTop();
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public PstnAndSize(float left, float top, Size size){
|
||||
this.left = left;
|
||||
this.top = top;
|
||||
this.width = size.getWidth();
|
||||
this.height = size.getHeight();
|
||||
}
|
||||
|
||||
private float left;
|
||||
private float top;
|
||||
private float width;
|
||||
private float height;
|
||||
|
||||
public Pstn getPstn() {
|
||||
return new Pstn(this.left, this.top);
|
||||
}
|
||||
public Size getSize() {
|
||||
return new Size(this.width, this.height);
|
||||
}
|
||||
|
||||
public float[] to4Float() {
|
||||
return new float[] { this.left, this.top, this.width, this.height };
|
||||
}
|
||||
|
||||
public PstnAndSize x2Width() {
|
||||
this.width = this.width * 2.0f;
|
||||
return this;
|
||||
}
|
||||
public PstnAndSize x2Height() {
|
||||
this.height = this.height * 2.0f;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PstnAndSize transXY(float transX, float transY) {
|
||||
this.left = this.left * transX;
|
||||
this.top = this.top * transY;
|
||||
this.width = this.width * transX;
|
||||
this.height = this.height * transY;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PstnAndSize addPstn(Pstn pstn) {
|
||||
this.left = this.left + pstn.getLeft();
|
||||
this.top = this.top + pstn.getTop();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package cokr.xit.applib;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Size {
|
||||
public Size(float width, float height){
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
private float width;
|
||||
private float height;
|
||||
|
||||
public float[] to2Float() {
|
||||
return new float[] { this.width, this.height };
|
||||
}
|
||||
|
||||
public int[] to2Int() {
|
||||
return new int[] { (int)this.width, (int)this.height };
|
||||
}
|
||||
|
||||
/**
|
||||
* 지정한 수치가 될 때까지 정비례로 크기를 축소한다.
|
||||
* @param until 축소할 축(x 또는 y)의 길이 지정
|
||||
* @param minMax 축소할 대상 축의 선택방법 지정(가장 길이가 작은 축 또는 가장 길이가 긴 축)
|
||||
* @return Size
|
||||
*/
|
||||
public Size reduceUntil(int until, boolean minMax) {
|
||||
|
||||
float minAxisValue;
|
||||
float maxAxisValue;
|
||||
if(this.width <= this.height) {
|
||||
minAxisValue = this.width;
|
||||
maxAxisValue = this.height;
|
||||
} else {
|
||||
minAxisValue = this.height;
|
||||
maxAxisValue = this.width;
|
||||
}
|
||||
|
||||
float divisor; //피제수
|
||||
if(minMax) {
|
||||
divisor = (minAxisValue / until);
|
||||
} else {
|
||||
divisor = (maxAxisValue / until);
|
||||
}
|
||||
|
||||
this.width = this.width / divisor;
|
||||
this.height = this.height / divisor;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue