use of java.awt.Graphics in project lwjgl by LWJGL.
the class TextureLoader method loadImage.
/**
* Load a given resource as a buffered image
*
* @param ref The location of the resource to load
* @return The loaded buffered image
* @throws IOException Indicates a failure to find a resource
*/
private BufferedImage loadImage(String ref) throws IOException {
URL url = TextureLoader.class.getClassLoader().getResource(ref);
if (url == null) {
throw new IOException("Cannot find: " + ref);
}
// due to an issue with ImageIO and mixed signed code
// we are now using good oldfashioned ImageIcon to load
// images and the paint it on top of a new BufferedImage
Image img = new ImageIcon(url).getImage();
BufferedImage bufferedImage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = bufferedImage.getGraphics();
g.drawImage(img, 0, 0, null);
g.dispose();
return bufferedImage;
}
use of java.awt.Graphics in project Voxel_Game by ASasseCreations.
the class AssetLoader method loadModifiedTextures.
public static final void loadModifiedTextures() throws URISyntaxException, IOException {
final List<String> list = getItems("/textures/blocks", "def");
list.addAll(getItems(Content.MOD_TEXTURE_FOLDER, "def", true));
for (final String s : list) {
final String name = getName(s, 3);
final BufferedImage original = RawAtlasTile.MODIFIED_IMAGE.get(name);
final BufferedImage image = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB);
{
final int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
for (int i = 0; i < pixels.length; i++) pixels[i] = 0x00000000;
}
final Graphics g = image.getGraphics();
try {
final String[] def = Tools.getFileAsString(s).split(Tools.getNewLine());
for (final String line : def) {
final String[] lt = line.split(Tools.getWhiteSpace());
if (lt[0].equals("fill")) {
g.setColor(new Color(Integer.parseInt(lt[1]), Integer.parseInt(lt[2]), Integer.parseInt(lt[3])));
g.fillRect(0, 0, image.getWidth(), image.getHeight());
} else if (lt[0].equals("draw"))
g.drawImage(original, 0, 0, null);
}
} catch (final IOException | NullPointerException e) {
}
g.dispose();
RawAtlasTile.MODIFIED_IMAGE.put(name, image);
}
}
use of java.awt.Graphics in project cayenne by apache.
the class WelcomeScreen method initView.
/**
* Creates all necessary components
*/
protected void initView() {
mainPanel = new JPanel(new GridBagLayout()) {
@Override
public void paintComponent(Graphics g) {
// paint gradient background
Graphics2D g2 = (Graphics2D) g.create();
Paint paint = new GradientPaint(0, 0, TOP_GRADIENT, 0, getHeight(), BOTTOM_GRADIENT);
g2.setPaint(paint);
g2.fillRect(0, 0, getWidth(), getHeight());
g2.dispose();
}
};
setBorder(BorderFactory.createEmptyBorder());
initButtonsPane();
initFileListPane();
setViewportView(mainPanel);
}
use of java.awt.Graphics in project HongsCORE by ihongs.
the class Thumb method draw.
/**
* 创建图层
* @param img 源图
* @param col 背景颜色
* @param pos 停靠位置
* @param w 目标宽
* @param h 目标高
* @param x 源图宽
* @param y 源图高
* @return 新的图层
*/
private BufferedImage draw(BufferedImage img, Color col, Position pos, int w, int h, int x, int y) {
if (pos == Positions.TOP_LEFT) {
x = 0;
y = 0;
} else if (pos == Positions.TOP_RIGHT) {
x = (w - x);
y = 0;
} else if (pos == Positions.TOP_CENTER) {
x = (w - x) / 2;
y = 0;
} else if (pos == Positions.BOTTOM_LEFT) {
x = 0;
y = (h - y);
} else if (pos == Positions.BOTTOM_RIGHT) {
x = (w - x);
y = (h - y);
} else if (pos == Positions.BOTTOM_CENTER) {
x = (w - x) / 2;
y = (h - y);
} else if (pos == Positions.CENTER_LEFT) {
x = 0;
y = (h - y) / 2;
} else if (pos == Positions.CENTER_RIGHT) {
x = (w - x);
y = (h - y) / 2;
} else /* Default is CENTER CENTER */
{
x = (w - x) / 2;
y = (h - y) / 2;
}
BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics grp = buf.createGraphics();
if (col != null) {
grp.setColor(col);
grp.fillRect(0, 0, w, h);
}
grp.drawImage(img, x, y, null);
grp.dispose();
return buf;
}
use of java.awt.Graphics in project sulky by huxi.
the class GraphicsUtilities method createCompatibleCopy.
public static BufferedImage createCompatibleCopy(BufferedImage image) {
BufferedImage result = createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
Graphics g = result.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
return result;
}
Aggregations