Questions tagged [bufferedimage]

The Java class BufferedImage is used to read and manipulate images and assist in double-buffering in desktop GUI applications.

The java.awt.image.BufferedImage Java class is part of the Abstract Windowing Toolkit group of classes that form part of the standard JDK.

The BufferedImage class contains methods to manipulate pixel values and is also used for double-buffering in applications that have a Java Swing GUI.

2150 questions
7
votes
1 answer

What buffering strategy should I use for my 2D scrolling map?

So, I'm creating a 2d top-down game in Java. I'm following instructions from Java 2D: Hardware Accelerating - Part 2 - Buffer Strategies to take advantage of hardware acceleration. Basically, what I'm thinking is this: I'd like to be able to easily…
7
votes
2 answers

Reading an image in Netbeans

I have an image file in my project. The hierarchy looks like this: I'm trying to read Manling.png into Manling.java using this code: public BufferedImage sprite; public Manling() { try { File file = new File("resources/Manling.png"); …
Tharwen
  • 3,057
  • 2
  • 24
  • 36
7
votes
2 answers

Out of memory problem saving large BufferedImage

I have a problem saving large (f.e. 12 000 x 9 000 ) images. I'm developing a graphical editing software ( something like simple Photoshop ) and The user obviously has to have to ability to save the image. Lets say I would like to save the image as…
Icki
  • 145
  • 1
  • 7
7
votes
2 answers

Why does ImageReader return incorrect BufferedImage?

I'm trying to access a animated GIF image with 21 frames and then read the 12th (cause it starts at 0?) frame. import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import…
Rihards
  • 10,241
  • 14
  • 58
  • 78
7
votes
1 answer

Encoding a String as a picture causes compression

I'm working on a program that takes a string, turns each character of the string into a color, then draws the colors left-to-right, top-down across an image. The image can then be decoded using the same program to get the original message back. As…
Carcigenicate
  • 43,494
  • 9
  • 68
  • 117
7
votes
2 answers

PDFBox Error When Converting to BufferedImage: NoClassDefFoundError: org/apache/fontbox/FontBoxFont

I'm trying to convert a PDF doc to .png files using PDFBox. I followed this answer to get an idea of what dependencies were needed and to give me a starting point. When I try to loop through the pages and create the BufferedImage I receive a…
Shaggy
  • 1,444
  • 1
  • 23
  • 34
7
votes
3 answers

Drawing multiple lines in a BufferedImage

I am trying to draw horizontal and vertical lines on a bufferedimage. It should end up looking like a grid of cells. But when I run the code, I see only two lines: the leftmost line and the topmost line (ie. a line from 0,0 to 0,height of image &…
Adith
  • 165
  • 2
  • 2
  • 5
7
votes
1 answer

Removing transparency in PNG BufferedImage

I'm reading a PNG image with the following code: BufferedImage img = ImageIO.read(new URL(url)); Upon displaying it, there is a black background, which I know is caused from PNG transparency. I found solutions to this problem suggesting the use of…
user4020527
  • 1
  • 8
  • 20
7
votes
1 answer

How can I save a BufferedImage to be below a particular size

(Using java 8) Given a image user needs to be able to specify min/max image size in pixels and also maximum size of saved image in kbs, image is saved as jpg. So I have the first bit working, by resizing buffered image: public static BufferedImage…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
7
votes
1 answer

How can I stop BufferedImage.getGraphics() opening an X11 device?

I have the following code for creating raster images. BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); Graphics g = img.getGraphics(); g.setColor(backgroundColour); g.fillRect(0, 0, width,…
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
7
votes
3 answers

Byte array to buffered image conversion slow

I have a simple server-side code that receives a byte array representing an image in JPEG format and returns the dimensions of the image. public String processImage(byte[] data) { long startTime = System.currentTimeMillis(); …
baekacaek
  • 1,527
  • 3
  • 22
  • 45
7
votes
4 answers

Null Pointer Exception on getGraphics()

my application looks like that, i am getting a null pointer exception at the draw() method, to be exact at g.drawImage(img, 0, 0, null) package com.ochs.game; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import…
user2410644
  • 3,861
  • 6
  • 39
  • 59
7
votes
2 answers

Jcrop not cropping properly the images

My jcrop code $(function(){ // Create variables (in this scope) to hold the API and image size var jcrop_api, boundx, boundy, // Grab some information about the preview pane $preview = $('#preview-pane'), $pcnt =…
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212
7
votes
3 answers

Quality loss using ImageIO.write

I have noticied significant quality loss using ImageIO.write, how I can disable automatic compression ? val baos: ByteArrayOutputStream = new ByteArrayOutputStream val newBi = new BufferedImage(img.getWidth, img.getHeight,…
Roch
  • 21,741
  • 29
  • 77
  • 120
7
votes
5 answers

int array to BufferedImage

I'm making with the Robot class a printscreen and I convert the BufferedImage into an int array. Then I want to convert the int array back to a bufferedimage but that gives an error. This is my code: Dimension screen =…
Jochem Gruter
  • 2,813
  • 5
  • 21
  • 43