graphics2d

Clear a transparent BufferedImage as fast as possible

帅比萌擦擦* 提交于 2019-11-29 18:24:06
问题 I have a transparent BufferedImage created with the following code(not relevant how it is created, I think): GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); Rectangle screen = transformationContext.getScreen(); // Create an image that supports transparent pixels return gc.createCompatibleImage((int) screen.getWidth(), (int) screen.getHeight(), Transparency

How to paint a group of QuadCurves using Java Graphics2D

ⅰ亾dé卋堺 提交于 2019-11-29 18:18:59
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 = new QuadCurve2D.Double(262.5, 87.5, 287.5, 25, 300, 25); g2.draw(earRight1); QuadCurve2D earRight2 = new

Create a Trailing line of blood behind a player

放肆的年华 提交于 2019-11-29 18:16:42
I am currently working on a simple top down shooter. The object is a ball that slides around the screen, and I am trying to make a sort of wet-dragging affect. I am using Java Swing and just the default Graphics2d lib inside. This is what I have: and this is my goal: I need to know how I can make a curved line that has the ability to change alpha at the trailing end. I have searched online but I can only find non-dynamic solutions. (The tail needs to update as the player moves across the screen.) A simple solution might be to simple add each point to a List of Point s which before the player

can't get my coordinates graphics2D mouseclick java

自作多情 提交于 2019-11-29 17:27:21
I got an extended JLabel class where I draw my Map using the code below : the new AffineTransform() is the identity to left my image as it is (0,0,w,h) mygraphics2D = (Graphics2D) getGraphics(); graphics2D.scale(2.0,2.0) ; graphics2D.rotate(.... graphics2D.drawImage(myImageIcon.getImage(),new AffineTransform(), this); now when I click on my JLabel using this event : public void mouseClicked(MouseEvent e) { x =e.getX() ; y = e.getY(); NewX = ???? NewY = ???? } I want to retrieve my new coordinates "the scaled,rotated ... coords" I tried Point2D ptSrc = new Point2D.Double(x, y); Point2D ptDst =

How to Undo the splash screen painting in java

末鹿安然 提交于 2019-11-29 17:10:13
I am a beginner in Java GUI, The problem is that I am using a splash screen which has a gradient as a background and I want to write the text , erase it and then write the new one. I Managed to write the text and even I can write the new one but the problem is that the new text overwrites the old text, and the old text is not erased, Since I have a gradient as background so I cannot use .clearRect() or .fillRect() of Graphics2D Class since they fill it with a solid color, here is my code which can help you to guide me. SplashScreen splash = SplashScreen.getSplashScreen(); int wpro = 0, strx =

Flipping shape (not image)

℡╲_俬逩灬. 提交于 2019-11-29 16:09:51
Solved: Thanks @MadProgrammer I replaced g2.rotate(Math.toRadians(180.0)); by g2.scale(1, -1); thanks^^ I wrote program to show Digital Clock with mirror (Vertical Flip) This is my code import java.awt.*; import java.awt.font.GlyphVector; import javax.swing.*; import java.util.*; public class DigitalClock extends JFrame implements Runnable { /** * @author HASSAN */ Thread runner; // declare global objects Font clockFont; Shape mirror; public DigitalClock() { super("Digital Clock - Hassan Sharaf 12MCMB33"); setSize(600, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true);

Incremental graphics in Swing

被刻印的时光 ゝ 提交于 2019-11-29 15:10:50
I'm trying to get the hang of doing graphics stuff (drawing lines, etc.) in Swing. So far, all the tutorials I've seen declare a class that overrides paintComponent , and all the paintComponent methods do some set, specific thing, like drawing a red square (although maybe they draw it at a different location every time). Or maybe they draw a number of lines and shapes, but the paintComponent method does everything all at once. I'm trying to figure out: suppose I want to draw one thing in a component, and later on draw something else on top of it without erasing what I drew before. My first

Java Graphics2D Translate and Scale

自闭症网瘾萝莉.ら 提交于 2019-11-29 12:53:18
I have a problem. I want to be able to zoom into my Graphics2D screen using the mouse wheel but I want to be able to translate the Graphics2D as well so that it's right on the spot that I scaled. Here's what's happening so far: " http://cdn.makeagif.com/media/6-11-2015/E0kYGY.gif " It's translating to the player's position correctly but I want it to be zoomable in and out with the scrolling of the mouse wheel. Here's the code I have so far to do it: private AffineTransform getCamTransform() { AffineTransform t = new AffineTransform(); float a = 400 - player.getX(); float b = 250 - player.getY(

Java ARGB to JPG

喜夏-厌秋 提交于 2019-11-29 11:38:05
How can I save BufferedImage with TYPE_INT_ARGB to jpg? Program generates me that image: And it's OK, but when I save it in that way: ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(byteStream); try { ImageIO.write(buffImg, "jpg", bos); // argb byteStream.flush(); byte[] newImage = byteStream.toByteArray(); OutputStream out = new BufferedOutputStream(new FileOutputStream("D:\\test.jpg")); out.write(newImage); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } The result is:

Font.createFont leaves files in temp directory

拜拜、爱过 提交于 2019-11-29 10:02:26
The code below does its work but leaves copies of the font file in the temp directory each time it is run. These files are named +~JF7154903081130224445.tmp where the number seems random for each created file. InputStream fontStream = this.getClass().getResourceAsStream("handsean.ttf"); Font baseFont = Font.createFont(Font.TRUETYPE_FONT, fontStream); fontStream.close(); I have found years-old discussions in forums at sun.com and other resources on the web where this is recognized as a bug in JDK, where upgrading from 1.5.0_06 to 1.5.0_08 would solve the problem; however, the version I am using