bufferedimage

Part 2 - How do I get consistent rendering when scaling a JTextPane?

耗尽温柔 提交于 2019-11-28 02:06:53
I submitted another version of this question and a sample program before: How do I get consistent rendering when scaling a JTextPane? Recapitulating the problem: I would like to allow users to zoom into or out of a non-editable JTextPane. Running the example program submitted in the earlier question, which simply scaled the Graphics object, resulted in inconsistent spacing between runs of bold text and non-bold text. The sample program below attempts to solve the problem by drawing the text pane to a BufferedImage at 100% and then scaling the image. This solves the problem of inconsistent

Printable prints BufferedImage with incorrect size

Deadly 提交于 2019-11-28 01:36:29
So yeah what I am trying here is printing a BufferedImage, all works just fine until you see the outcome. The outcome is to big, the print is to large and doesn't it scales up everything when printing for some reason. I used ((MM * DPI)/25,4) to calculate the correct pixel length according to paper size from Millimeters but when I print it its to big. This is the code I wrote for it: package frik.main; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.awt.print.Printable; import java

How to convert Icon from JLabel into BufferedImage?

大兔子大兔子 提交于 2019-11-28 01:11:18
Simple, very straight forward but seems uncle google and me getting confused. I have single JLabel that already has its own Icon . How do I convert the Icon obtained from JLabel into a BufferedImage ? Is there any way around: I tried to multiple casting like this .. final BufferedImage bf1 = (BufferedImage)((Image)jll_img.getIcon()); ..but it failed. trashgod To amplify on @Andrew Thompson's answer , note that an object that implements the Icon interface knows how to paint something, but it may not have been asked to do so yet. In contrast, a BufferedImage has "an accessible buffer of image

Null Pointer Exception on getGraphics()

时间秒杀一切 提交于 2019-11-28 00:26:56
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 java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JPanel; public class Game extends JPanel implements Runnable{ private static final long serialVersionUID = 8229934361462702491L; public static final int WIDTH = 320; public static final int HEIGHT = 240; public static final int SCALE = 2; public boolean isRunning; private

How to flip BufferedImage in java

孤街醉人 提交于 2019-11-28 00:04:05
问题 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;

Java - Image Rotation

跟風遠走 提交于 2019-11-27 23:03:32
I am trying to rotate image. I am using this Java code: BufferedImage oldImage = ImageIO.read(new FileInputStream("C:\\workspace\\test\\src\\10.JPG")); BufferedImage newImage = new BufferedImage(oldImage.getHeight(), oldImage.getWidth(), oldImage.getType()); Graphics2D graphics = (Graphics2D) newImage.getGraphics(); graphics.rotate(Math.toRadians(90), newImage.getWidth() / 2, newImage.getHeight() / 2); graphics.drawImage(oldImage, 0, 0, oldImage.getWidth(), oldImage.getHeight(), null); ImageIO.write(newImage, "JPG", new FileOutputStream("C:\\workspace\\test\\src\\10_.JPG")); But I see strange

Reading an image in Netbeans

痴心易碎 提交于 2019-11-27 22:28:33
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"); sprite = ImageIO.read(file); } catch (IOException e) {} System.out.println(sprite.toString()); //This line is to test if it works } I always get a NullPointerException on the println statement, so I assume the path is wrong. I've tried moving the image to different places in the project and I've tried changing the file path (e.g. 'mine/resources/Manling.png' and '

How to convert buffered image to image and vice-versa?

好久不见. 提交于 2019-11-27 21:14:01
Actually i am working on a image editing software and now i want to convert the buffered-image i.e : BufferedImage buffer = ImageIO.read(new File(file)); to Image i.e in the format something like : Image image = ImageIO.read(new File(file)); Is it possible to so?? If yes, then how?? BufferedImage is a(n) Image, so the implicit cast that you're doing in the second line is able to be compiled directly. If you knew an Image was really a BufferedImage, you would have to cast it explicitly like so: Image image = ImageIO.read(new File(file)); BufferedImage buffered = (BufferedImage) image; Because

Add BufferedImage to PDFBox document

蹲街弑〆低调 提交于 2019-11-27 21:01:51
问题 In my current project, I try to add a BufferedImage to a PDFBox document. More specificly, I use an image from a JFreeChart . My code looks like this: public void exportToPDF(JFreeChart chart, String filePath){ PDDocument doc = null; PDPage page = null; PDXObjectImage ximage = null; try { doc = new PDDocument(); page = new PDPage(); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); BufferedImage image = chart.createBufferedImage(300, 300); ximage = new

How to resize the buffered image n graphics 2d in java?

眉间皱痕 提交于 2019-11-27 20:49:31
int width = 175; Graphics2D gb = (Graphics2D) g; bufferedimage = (BufferedImage) createImage(width, width); Graphics2D graphics = bufferedimage.createGraphics(); graphics.setColor(/*this.getBackground()*/Color.red); graphics.fillRect(0, 0, width, width); hi i have the the buffered with big size...i have to resize the bufferd image...plz can u anyone help me? public BufferedImage scaleImage(BufferedImage img, int width, int height, Color background) { int imgWidth = img.getWidth(); int imgHeight = img.getHeight(); if (imgWidth*height < imgHeight*width) { width = imgWidth*height/imgHeight; }