graphics2d

How to move the image inside the JApplet in vertical line?

会有一股神秘感。 提交于 2019-11-30 20:36:25
问题 I have displayed an image(ball) inside the JApplet, now I want the image to move in a vertical way (up and down). The problem is I don't know how to do it. Could someone has an idea about this matter? 回答1: You need to set the position of that image to some calculated value (means you caculate the vertical position using time, speed and maybe other restrictions). How you'd set that position depends on how you draw the image. Example, based on drawing in the applet's (or a nested component's)

How do I specify fallback fonts in Java2D/Graphics2D

£可爱£侵袭症+ 提交于 2019-11-30 19:34:09
I'm using g.drawString(str, x, y) to draw a String with a Graphics2D object g . The current font of g does not cover all the characters of str (I have e.g. Chinese chars in there). On Mac OS X, a fallback font seems to be automatically used, but not on Windows, where black square outlines appear instead of the wanted characters. Why is the behavior different depending on the platform? How do I specify a fallback font (or several fallback fonts) in case of missing characters? (For instance, one of the nice fonts there .) Update/More Info So, the original font that doesn't support all characters

How do I draw graphics to PDF using iText?

北慕城南 提交于 2019-11-30 17:30:58
问题 I am trying to complete an example that draws graphics and writes them to PDF, but I keep getting errors that the PDF has no pages. if I add something simple with document.add() after opening it works fine, I just never see the graphics. Here is my code: Document document = new Document(); PdfWriter writer = new PdfWriter(); response.setContentType("application/pdf"); response.setHeader("Content-Disposition", " attachment; filename=\"Design.pdf\""); writer = PdfWriter.getInstance(document,

How to paint a group of QuadCurves using Java Graphics2D

こ雲淡風輕ζ 提交于 2019-11-30 10:01:37
问题 I have a lot of QuadCurve2D methods in a drawing, but when I fill them they don't actually fill the whole image. Code for fill and curves: g2.setStroke(new BasicStroke(5)); QuadCurve2D earLeft1 = new QuadCurve2D.Double(145, 155, 137.5, 49, 150, 49); g2.draw(earLeft1); QuadCurve2D earLeft2 = new QuadCurve2D.Double(150, 49, 156.25, 49, 200, 100); g2.draw(earLeft2); QuadCurve2D betweenEars = new QuadCurve2D.Double(200, 100, 237.5, 88, 262.5, 87.5); g2.draw(betweenEars); QuadCurve2D earRight1 =

Save JPanel as Image HD Quality

霸气de小男生 提交于 2019-11-30 10:01:32
问题 I am trying to save a JPanel as Image (Png, Jpg, whatever) but with Graphics2D the Quality is very low. My JPanel contains mostly text and I want to print the panel 4 times on a A4 paper size, so that it fills the page. But the text is like washed-out when i print the image. I tried to create an A3 image then print it to the smaller A4 size. The quality increases very little, almost insignificantly. Here is the function i use to generate the image, based on this ScreenImage.Class i found here

Java image rotation with AffineTransform outputs black image, but works well when resized

孤街浪徒 提交于 2019-11-30 05:56:50
问题 I am just trying to rotate a JPG file by 90 degrees. However my code outputs image ( BufferedImage ) that is completely black. Here's the way to reproduce: (Download 3.jpg here ) private static BufferedImage transform(BufferedImage originalImage) { BufferedImage newImage = null; AffineTransform tx = new AffineTransform(); tx.rotate(Math.PI / 2, originalImage.getWidth() / 2, originalImage.getHeight() / 2); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BICUBIC);

Proper way of printing a BufferedImage in Java

隐身守侯 提交于 2019-11-30 05:32:47
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 this, it would be greatly appreciated. Gilbert Le Blanc Here's one from one of my Java projects. This

Flip Image with Graphics2D

心已入冬 提交于 2019-11-30 01:47:53
I've been trying to figure out how to flip an image for a while, but haven't figured out yet. I'm using Graphics2D to draw an Image with g2d.drawImage(image, x, y, null) I just need a way to flip the image on the horizontal or vertical axis. If you want you can have a look at the full source on github . From http://examples.javacodegeeks.com/desktop-java/awt/image/flipping-a-buffered-image : // Flip the image vertically AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx.translate(0, -image.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE

Save JPanel as Image HD Quality

ε祈祈猫儿з 提交于 2019-11-29 18:49:21
I am trying to save a JPanel as Image (Png, Jpg, whatever) but with Graphics2D the Quality is very low. My JPanel contains mostly text and I want to print the panel 4 times on a A4 paper size, so that it fills the page. But the text is like washed-out when i print the image. I tried to create an A3 image then print it to the smaller A4 size. The quality increases very little, almost insignificantly. Here is the function i use to generate the image, based on this ScreenImage.Class i found here : public void exportToPNG(JRootPane panel){ Dimension size = panel.getSize(); BufferedImage image =

fitting PrinterJob Object to specific print format of BufferedImage

淺唱寂寞╮ 提交于 2019-11-29 18:39:57
Im using PrinterJob object in order to print my Bufferedimage, I have a BufferedImage which I proccess and send it to Printer job with Paper Format etc, and I cant make it fittable to my card printer. when i save it to my hard-disk and print via windows printing manager it printing very good on my card printer but with PrinterJob it came out too big and not fittable for a card the size of the card is 86X54mm and the size of my buffered image is 1300x816px The Code : PrinterJob printjob = PrinterJob.getPrinterJob(); printjob.setJobName("CardPrint"); Printable printable = new Printable() {