📄 imagetexture.java
字号:
package net.sf.jawp.gui.client.semi3d;
import java.awt.Image;
import java.awt.image.PixelGrabber;
/**
*
* @author from javaworld
* @version $Revision: 1.3 $
*
*/
public class ImageTexture implements Texture
{
int[] imagePixels;
int imageWidth, imageHeight;
final float shift;
public ImageTexture(final Image image, final int width, final int height, final float sh)
throws InterruptedException
{
final PixelGrabber grabber = new PixelGrabber(image, 0, 0, width, height,
true);
if (!grabber.grabPixels())
{
throw new IllegalArgumentException(
"Invalid image; pixel grab failed.");
}
imagePixels = (int[]) grabber.getPixels();
imageWidth = grabber.getWidth();
imageHeight = grabber.getHeight();
this.shift = sh;
}
public RGB getTexel(final double i, final double j)
{
final double i2 = i - Math.floor(i) + shift;
final double j2 = j - Math.floor(j);
return new RGB(imagePixels[(int) (i2 * imageWidth) + imageWidth
* (int) (j2 * imageHeight)]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -