bufferedimage

Drawing multiple lines in a BufferedImage

限于喜欢 提交于 2019-11-29 13:41:57
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 & 0,0 to width of image,0) Heres the code snippet: BufferedImage mazeImage = new BufferedImage(imgDim.width, imgDim.height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = mazeImage.createGraphics(); g2d.setBackground(Color.WHITE); g2d.fillRect(0, 0, imgDim.width, imgDim.height); g2d.setColor(Color.BLACK); BasicStroke bs = new BasicStroke(2); g2d

Load image from a filepath via BufferedImage

这一生的挚爱 提交于 2019-11-29 13:21:52
I have a problem with Java application, particular in loading a image from a location in my computer. Following this post I used a BufferedImage and a InputFileStream to load an image on my computer. First, I put the image ( pic2.jpg ) into the source code and that is working. However, if I put the image to another place (let's say C:\\ImageTest\pic2.jpg ), Java IDE show me an IllegalArgumentException return ImageIO.read(in); here is the code: public class MiddlePanel extends JPanel { private BufferedImage img; public MiddlePanel(int width) { //img = getImage("pic2.jpg"); img = getImage("C:\

Rotating BufferedImage changes its colors

拜拜、爱过 提交于 2019-11-29 12:37:21
I'm trying to code a class to seam carve images in x and y direction. The x direction is working, and to reduce the y direction I thought about simply rotating the image 90° and run the same code over the already rescaled image (in x direction only) and after that, rotate it back to its initial state. I found something with AffineTransform and tried it. It actually produced a rotated image, but messed up the colors and I don't know why. This is all the code: import java.awt.image.BufferedImage; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.io.File;

Pink/Reddish tint while resizing jpeg images using java thumbnailator or imgscalr

流过昼夜 提交于 2019-11-29 10:55:49
I am trying to convert an image (url below) using two libraries (thumbnailator and imgscalr. My code works on most of the images except a few which after conversion have a pink/reddish tint. I am trying to understand the cause and would welcome any recommendation. Note - Image type of this image is 5 i.e BufferedImage.TYPE_3BYTE_BGR and i am using Java 7 Using Thumbnailator Thumbnails.of(fromDir.listFiles()) .size(thumbnailWidth, thumbnailHeight) .toFiles(Rename.SUFFIX_HYPHEN_THUMBNAIL); Using imgscalr BufferedImage bufferedImage = ImageIO.read(file); final BufferedImage jpgImage; LOG.debug(

Can I create a BufferedImage from a JPanel without rendering in a JFrame?

假如想象 提交于 2019-11-29 09:29:58
Is it possible to create a BufferedImage from a JPanel without first rendering it in a JFrame? I've searched everywhere I can think of and cannot find an answer. Can anyone help? Here is some sample code. If I don't un-comment the JFrame code, my BufferedImage is blank. test(){ // JFrame frame = new JFrame(); JPanel panel = new JPanel(); Dimension dim = new Dimension(50,50); panel.setMinimumSize(dim); panel.setMaximumSize(dim); panel.setPreferredSize(dim); JLabel label = new JLabel("hello"); panel.add(label); // frame.add(panel); // frame.pack(); BufferedImage bi = getScreenShot(panel); //..

How to flip BufferedImage in java

北战南征 提交于 2019-11-29 06:37:31
I get RGB24 byte array and want to show it in Java. public void getByteArray(byte byteArray[]){ int count1 = 0; byte temp1 = 0; for (int i = 0; i < byteArray.length; i++) { //The order of RGB24 is red,green and blue.Change the //order to blue,green and red so that java can use TYPE_3BYTE_BGR to recognize it if (count1 == 0) { temp1 = byteArray[i]; count1++; } else if(count1 == 1) { //do nothing count1++; } else if(count1 == 2) { byteArray[i - 2] = byteArray[i]; byteArray[i] = temp1; count1=0; } } image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); image.getWritableTile(0, 0

Painting in a BufferedImage inside Swing

六眼飞鱼酱① 提交于 2019-11-29 05:22:32
Im working on a paint application written in java and running into a few (more) problems. I have a gui and a working program(kinda), my only problem is that the lines and graphics that the user draws are not saved(disappear after next one is drawn). From a past question i learned that i will need to use a BufferedImage to store the drawings then paint that inside my paint class. My questions are, Can anyone provide a basic explanation/example of how to use a bufferedimage to store and paint the drawing and if i need to, how will i pass the color and thickness of the drawn line into a stored

Save image from JPanel after draw

陌路散爱 提交于 2019-11-29 05:06:22
I'm newbie in jave, my first project is draw, and save a image from JPanel, my draw is done, but I cant save it after I draw in JPanel :(, So can you help me to fix it when I open the image after draw, It doesn't contain anything :( here my codes: package image; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.image.BufferedImage;

Proper way of printing a BufferedImage in Java

好久不见. 提交于 2019-11-29 04:18:25
问题 I would like to know if there is a proper way of printing a BufferedImage in Java. Basically I have created a photo manipulation program which works fine, I can save images etc. But my real goal is to send it to the printer software so that you can select the amount of pages you want to print and page type. So my shortened question is, how do I send a buffered image to the printer so that a printer selection screen will popup etc and then be able to print? If anyone can show me an example of

Converting an ImageIcon to a BufferedImage

♀尐吖头ヾ 提交于 2019-11-29 03:59:09
I've been trying to convert a ImageIcon to BufferedImage ... And I've had no luck. I have a pre-existing ImageIcon that needs to be converted to a Buffered Image for the vast amount of BufferedImage operations that exist. I have found a few ways, but all of them are hugely CPU intensive. What's wrong with: BufferedImage bi = new BufferedImage( icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); // paint the Icon to the BufferedImage. icon.paintIcon(null, g, 0,0); g.dispose(); See ImageIcon , Image and BufferedImage : ImageIcon yourImage;