java-canvas

Blurry image after canvas rotate, only in Android 6

橙三吉。 提交于 2019-12-23 17:31:47
问题 I've got a custom view with the following code: private final Drawable outerGauge; private final Drawable innerGauge; private float rotateX; private float rotateY; private int rotation = 0; { outerGauge = getContext().getDrawable(R.drawable.gauge_outer); innerGauge = getContext().getDrawable(R.drawable.gauge_inner); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); outerGauge.draw(canvas); canvas.rotate(rotation, rotateX, rotateY); innerGauge.draw(canvas); canvas.rotate

Why would you use JNI to paint on AWT's Canvas?

為{幸葍}努か 提交于 2019-12-23 11:56:56
问题 I'm pretty new to the JNI, and I stumbled across this while looking into the JNI: Not only can native code interface with Java, it can also draw on a Java Canvas, which is possible with the Java AWT Native Interface Is there a specific reason why this functionality was made specific/is available? Does it improve processing time on Windows system? Please elaborate why and when one would use such a feature 回答1: Native performance rendering in Java... games would be the first thing to come to

java.awt.image.DataBufferByte cannot be cast to java.awt.image.DataBufferInt

谁都会走 提交于 2019-12-18 05:17:04
问题 I have some errors atm while im coding with JAVA, I have been trying to fix this for along time, also trying to find oterh ppl who have same problem and fixed it but nothing work... Well.. here is the code package ca.vanzeben.game; import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import javax.swing

Line crosses Rectangle - how to find the cross points?

邮差的信 提交于 2019-12-18 04:16:16
问题 I'm drawing a rectangle onto a canvas and a line from the center of the rectangle to some random point in the coordinate space. Now, I want to truncate the line by the length that is inside the rectangle so that the line starts at the rectangle edge. How could I do this? Example The rectangle could be defined by 2 points: Pstart(1, 3) , Pend(3, 1) The center point can be computed to : P(2, 2) Now draw the line from P(2, 2) to Q(10, 2) . As I know the width of the rectangle is 2, I could tell

Java Challenge on Creating a Canvas

Deadly 提交于 2019-12-13 06:43:29
问题 This is probably an elementary question. However, I have completed reading the 9th Chapter of Java Programming for the Absolute Beginner and have approached the Challenges section. I cannot quite understand the question. The question asks: "Create a Canvas that paints a gradient that’s dark on one side and slowly gets lighter as it moves to the other side." This might be helpful information: prior to this challenge question, the word 'gradient' has not appeared within code methods or within

How do I add a button to Canvas without letting the button resize?

笑着哭i 提交于 2019-12-12 02:48:51
问题 I'm working on a login screen for my game. I have a total of two images on it. One is a splash screenshot and the other is the background image. I'm using BufferedImages to render the images to the screen. The problem I get is that when I add a standard button to the Canvas, the button takes up the whole window, and evidently, I don't want that. I would post a picture, but alas, I do not have "enough reputation" to do that. Here's a look at my code though: import java.awt.Button; import java

Using a canvas object in a thread to do simple animations - Java

别来无恙 提交于 2019-12-11 04:06:59
问题 I have an applet that, as written now, should be drawing and bouncing a ball around the top ( drawingpanel in the code) after the "Run" button is pressed. Looking at other examples online and using code from a different program that did not use Canvas I am not able to figure out why my Ball object is not showing up. I have tested the flow of the program, and all the methods are being called as they should be, so it isn't the case where the code doesn't make it to the paint method. Any good

Java clears screen when calling paint method - how to avoid that?

放肆的年华 提交于 2019-12-10 15:58:33
问题 I'm trying to draw two lines in a Canvas in Java, calling two methods separately, but when I draw the second line, the first one disapears (Java clears the screen). How can I avoid that? I want to see the two lines. I've seen paint tutorials (how to make a program like the Paint on Windows) where the user uses the mouse to draw lines and when one line is drawn, the other do not disappear. They just call the paint method and it does not clear the screen. I'll be grateful if anyone can help me.

Mouse click coordinates are always 0

≯℡__Kan透↙ 提交于 2019-12-08 07:14:29
问题 As you can see I added the a mouse listener to the game. import java.awt.Graphics; import java.awt.image.BufferStrategy; public class Game implements Runnable { private Display display; public int width, height; public String title; private boolean running = false; private Thread thread; private BufferStrategy bs; private Graphics g; // States public static State gameState; // Input private InputManager inputManager; private MouseHandler mouseHandler; public Game(String title, int width, int

Java drag and drop custom cursor

筅森魡賤 提交于 2019-12-08 00:37:18
问题 I have defined a custom canvas style component, using JPanel, that will support the dragging of objects onto the canvas. What I can't seem to figure out is how to change the drag and drop (DnD) cursor to a custom one, using a TransferHandler. For example, instead of the default link cursor during DnD, I want substitute my own. Is there a way to do this using a TransferHandler? I suspect I will have to use the AWT DnD support to do this but I am hoping to avoid that if I can. 回答1: By digging