📄 imageutil.java
字号:
//# if(pointY4 > maxY){
//# maxY = pointY4;
//# }
//# return (int) (maxY - minY);
//# }
//#endif
//#if polish.hasFloatingPoint
//# /**
//# * Returns the new width for the given degree. The new width symbols the width for an rotated rgb data array with the same degree rotation.
//# *
//# * @param degree the degree value of the rotation.
//# * @param width the width of the rgb source.
//# * @param heigth the heigth of the rgb source
//# * @param degreeCos the cosine of the degree value: Math.cos(Math.PI*degree/180)
//# * @param degreeSin the sine of the degree value: Math.sin(Math.PI*degree/180)
//# * @return the new width of the rgb data.
//# * @author Tim Muders
//# */
//# public static final int getRotatedWidth(int degree,int width,int heigth,double degreeCos,double degreeSin)
//# {
//# if(degree == -90 || degree == 90 || degree == 270 || degree == -270){
//# return heigth;
//# }
//# else if(degree == 360 || degree == 180 || degree == 0){
//# return width;
//# }
//# long pointX1 = MathUtil.round(0 * degreeCos - 0 * degreeSin);
//# long pointX2 = MathUtil.round(width *degreeCos - 0 *degreeSin);
//# long pointX3 = MathUtil.round(0 *degreeCos - heigth *degreeSin);
//# long pointX4 = MathUtil.round(width *degreeCos - heigth *degreeSin);
//# long minX = pointX1;
//# if(pointX2 < minX){
//# minX = pointX2;
//# }
//# if(pointX3 < minX){
//# minX = pointX3;
//# }
//# if(pointX4 < minX){
//# minX = pointX4;
//# }
//# long maxX = pointX1;
//# if(pointX2 > maxX){
//# maxX = pointX2;
//# }
//# if(pointX3 > maxX){
//# maxX = pointX3;
//# }
//# if(pointX4 > maxX){
//# maxX = pointX4;
//# }
//# return (int) (maxX - minX);
//# }
//#endif
/**
* Scales an rgb data unproportional in every new size you want bigger or smaller than the given original. Returns the scaled rgb data.
*
* @author Tim Muders
* @param rgbData the original rgbdata
* @param newWidth the new width for the new rgbdata
* @param newHeight the new height for the new rgbdata
* @param oldWidth the width from the oiginal rgbdata
* @param oldHeight the height from the oiginal rgbdata
* @return the scaled rgb data.
*/
public static final int[] scale(int[]rgbData,int newWidth,int newHeight,int oldWidth, int oldHeight){
int[]newrgbData = new int[newWidth*newHeight];
scale( rgbData, newWidth,newHeight, oldWidth, oldHeight, newrgbData);
return newrgbData;
}
/**
* Stretches the rgb data vertical to the given top and bottom stretch factor and returns the new rgb data array.
*
* @author Tim Muders
* @param argbArray the rgb data to be stretched.
* @param topStrechFactor the stretch factor of the top.
* @param bottomStrechFactor the stretch factor of the bottom.
* @param width the source width of the rgb data.
* @param heigth the source heigth of the rgb data.
* @return stretched rgb data array.
*/
public static final int[] stretchVertical( int[] argbArray, int topStrechFactor, int bottomStrechFactor, int width, int heigth ){
int newWidthTop = (width * topStrechFactor)/100;
int newWidthBottom = (width * bottomStrechFactor)/100;
int procentualScalingHeight ;
int biggerWidth ;
if(newWidthTop < newWidthBottom){
procentualScalingHeight = (newWidthBottom - newWidthTop)/heigth;
biggerWidth = newWidthBottom;
}
else{
procentualScalingHeight = (newWidthTop - newWidthBottom)/heigth;
biggerWidth = newWidthTop;
}
int[] newArgbArray = new int[biggerWidth * heigth];
return stretchVertical( argbArray, newWidthTop, newWidthBottom,biggerWidth , width, heigth, procentualScalingHeight, newArgbArray );
}
/**
* Stretches the rgb data vertical to the given top and bottom width and returns the new rgb data array.
*
*
* @author Tim Muders
* @param argbArray the rgb data to be stretched.
* @param newWidthTop the new top width of the rgb data.
* @param newWidthBottom the new bottom width of the rgb data.
* @param biggerWidth the bigger width of top and bottom width.
* @param width the source width of the rgb data.
* @param heigth the source heigth of the rgb data.
* @param procentualScalingHeight the procentual scaling heigth(biggerWidth - smallerWidth)/heigthOfTheOriginalImage).
* @param newArgbArray the new rgb data where the changes getting in.
* @return return filled the newArgbArray with stretched changes.
*/
public static final int[] stretchVertical( int[] argbArray, int newWidthTop, int newWidthBottom,int biggerWidth , int width, int heigth,int procentualScalingHeight, int[] newArgbArray ){
if(procentualScalingHeight == 0)procentualScalingHeight++;
int length = newArgbArray.length;
int oldLength = argbArray.length;
int insideCurrentY = 0;
int insideCurrentX = 0, outsideCurrentX = 0;
int sum1 = (biggerWidth-newWidthTop)/2;
int sum2 = biggerWidth-((biggerWidth-newWidthTop)/2);
for(int i = 0; i < length; i++){
outsideCurrentX = (outsideCurrentX + 1) % biggerWidth;
if(outsideCurrentX == 0){
if(newWidthTop < newWidthBottom){
newWidthTop += procentualScalingHeight;
sum1 = (biggerWidth-newWidthTop)/2;
sum2 = biggerWidth-((biggerWidth-newWidthTop)/2);
}
else if(newWidthTop > newWidthBottom){
newWidthTop -= procentualScalingHeight;
sum1 = (biggerWidth-newWidthTop)/2;
sum2 = biggerWidth-((biggerWidth-newWidthTop)/2);
}
insideCurrentY++;
insideCurrentX=0;
}
if(outsideCurrentX >= sum1 && outsideCurrentX < sum2){
insideCurrentX = (insideCurrentX + 1) % newWidthTop;
newArgbArray[i] = argbArray[scaledPixel(oldLength,width,heigth,newWidthTop,heigth,insideCurrentX,insideCurrentY)];
}
else{
newArgbArray[i] = 000000;
}
}
return newArgbArray;
}
/**
* Returns the one scaled Pixel for the given new heigth and width.
*
* @author Tim Muders
* @param oldLength length of the rgb data source.
* @param oldWidth the old width of the rgb data.
* @param oldHeigth the old heigth of the rgb data.
* @param newWidth the new width of the rgb data.
* @param newHeigth the new heigth of the rgb data.
* @param currentX the x position of the pixel to be scaled.
* @param currentY the y position of the pixel to be scaled.
* @return position of the scaled pixel in the old rgb data array.
*/
public static final int scaledPixel(int oldLength,int oldWidth,int oldHeigth, int newWidth, int newHeigth, int currentX, int currentY){
int targetArrayIndex;
int verticalShrinkFactorPercent = ((newHeigth*100) / oldHeigth);
int horizontalScaleFactorPercent = ((newWidth*100) / oldWidth);
targetArrayIndex = ((currentX*100)/horizontalScaleFactorPercent)+(oldWidth * ((currentY*100)/verticalShrinkFactorPercent));
if(targetArrayIndex >= oldLength)targetArrayIndex = oldLength-1;
if(targetArrayIndex < 0)targetArrayIndex = 0;
return targetArrayIndex;
}
/**
* Stretches the rgb data horizontal to the given left and rigth stretch factor and returns the new rgb data array.
*
* @author Tim Muders
* @param argbArray the rgb data to be stretched.
* @param leftStrechFactor the stretch factor of the left.
* @param rightStrechFactor the stretch factor of the rigth.
* @param width the source width of the rgb data.
* @param heigth the source heigth of the rgb data.
* @return stretched rgb data array.
*/
public static final int[] stretchHorizontal( int[] argbArray, int leftStrechFactor, int rightStrechFactor, int width, int heigth ){
int newHeigthLeft = (heigth * leftStrechFactor)/100;
int newHeigthRight = (heigth * rightStrechFactor)/100;
int procentualScalingWidth ;
int biggerHeigth ;
if(newHeigthLeft < newHeigthRight){
procentualScalingWidth = (newHeigthRight - newHeigthLeft)/width;
biggerHeigth = newHeigthRight;
}
else{
procentualScalingWidth = (newHeigthLeft - newHeigthRight)/width;
biggerHeigth = newHeigthLeft;
}
int[] newArgbArray = new int[biggerHeigth * width];
return stretchHorizontal( argbArray, newHeigthLeft, newHeigthRight,biggerHeigth , width, heigth, procentualScalingWidth, newArgbArray );
}
/**
* Stretches the rgb data horizontal to the given left and heigth width and returns the new rgb data array.
*
*
* @author Tim Muders
* @param argbArray the rgb data to be stretched.
* @param newLeftHeigth the new left heigth of the rgb data.
* @param newRigthHeigth the new rigth heigth of the rgb data.
* @param biggerHeigth the bigger heigth of left and rigth heigth.
* @param width the source width of the rgb data.
* @param heigth the source heigth of the rgb data.
* @param procentualScalingHeight the procentual scaling heigth(biggerHeigth - smallerSmaller)/widthOfTheOriginalImage).
* @param newArgbArray the new rgb data where the changes getting in.
* @return return the filled newArgbArray with stretched changes.
*/
public static final int[] stretchHorizontal( int[] argbArray, int newLeftHeigth, int newRigthHeigth,int biggerHeigth , int width, int heigth,int procentualScalingHeight, int[] newArgbArray ){
if(procentualScalingHeight == 0)procentualScalingHeight++;
int length = newArgbArray.length;
int oldLength = argbArray.length;
// x and y position int the new array
int idX = 0, idY = 0;
// x and y position of the old array
int x = 0, y = 0;
//position in the new array
int whereIamAt = 0;
// Heighth for goal
int newHeigth = newLeftHeigth;
//start Heigth to goal
int startColumn = (biggerHeigth-newHeigth)/2;
int endColumn = biggerHeigth-((biggerHeigth-newHeigth)/2);
for(int i = 0; i < length; i++){
if(startColumn <= idY && endColumn >= idY){
newArgbArray[whereIamAt] = argbArray[scaledPixel(oldLength,width,heigth,width,newHeigth,x,y)];
y = (y + 1) % newHeigth;
}
else{
newArgbArray[whereIamAt] = 000000;
}
idY = (idY + 1)% (biggerHeigth) ;
whereIamAt = idX+(idY * width);
if(idY == 0){
idX++;
x++;
y = 0;
if(newLeftHeigth < newRigthHeigth){
newHeigth += procentualScalingHeight;
}
else if(newLeftHeigth > newRigthHeigth){
newHeigth -= procentualScalingHeight;
}
startColumn = (biggerHeigth-newHeigth)/2;
endColumn = biggerHeigth-((biggerHeigth-newHeigth)/2);
}
}
return newArgbArray;
}
/**
* Scales an rgb data unproportional in every new size you want bigger or smaller than the given original.
*
* @author Tim Muders
* @param rgbData the original rgbdata
* @param newWidth the new width for the new rgbdata
* @param newHeight the new height for the new rgbdata
* @param oldWidth the width from the oiginal rgbdata
* @param oldHeight the height from the oiginal rgbdata
* @param newrgbData the new rgbdata has to be initialised
*/
public static final void scale(int[]rgbData,int newWidth,int newHeight,int oldWidth, int oldHeight,int[] newrgbData){
int currentX = 0,currentY = 0;
int oldLenght = rgbData.length;
int newLength = newrgbData.length;
int targetArrayIndex;
int verticalShrinkFactorPercent = ((newHeight*100) / oldHeight);
int horizontalScaleFactorPercent = ((newWidth*100) / oldWidth);
for(int i = 0; i < newLength;i++){
currentX = (currentX + 1) % newWidth;
if(currentX == 0){
currentY++;
}
targetArrayIndex = ((currentX*100)/horizontalScaleFactorPercent)+(oldWidth * ((currentY*100)/verticalShrinkFactorPercent));
if(targetArrayIndex >= oldLenght)targetArrayIndex = oldLenght-1;
if(targetArrayIndex < 0)targetArrayIndex = 0;
newrgbData[i] = rgbData[targetArrayIndex];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -