I am drawing a coordinate system with weight, height =10000*10000 on a frame. It too big, my graph can't fully display. I try to draw on scroll but it's lag. I want to display my graph on a frame 10000*10000, fit with my screen computer to print screen. What should I do?
You have to scale you graph. You know, Earth is very big but it fits map that can be shown on a screen of your smart phone :)
This means that if for example you want to show rectangle of 10000*10000 on screen that has (for example) 1000 pixels you have to scale your picture 10 times.
Option 1: Set the size of the JFrame on which you are displaying the graph to the desired size.
setSize(WIDTH, HEIGHT);
where WIDTH and HEIGHT are in pixels.
OR
Option 2: Scale the drawing. That is, simply divide each dimension in the drawing by 2 to make it half the size.
Related
I'm creating a game in libGDX. I want to create some UI elements (buttons and stuff), because of my app design, I would like to draw them in the world space, as other game objects.
I'm using Freetype generator that generates a bitmap font from true type font files(.ttf). The problem is that the dimension of the font is in pixels.
Orthographic camera that I use to to render the world, has viewport size of approximately 10x10, so when I generate a font at the size of 10, it covers almost whole screen(too big) and also looks very ugly because generated bitmap for the font is too small (too few pixels).
What I want is to create sprite, draw it at same size(world space) and draw text over it, and basicly create a button.
Is there some well established way how to deal with this?
Thanks to clarifying comments, I've came up with the solution.
I took a point at which I wanted to draw the text, projected it to the screen space by my world camera. Then I flipped y axis by:
point.y = viewportHeight - point.y;
Then I unprojected it with ScreenViewport (separate viewport for drawing the text, is uses camera of the size of the screen so 1unit == 1pixel).
Now I can draw text in projection where 1unit = 1pixel, on the point that is at the same place on the screen as previously chosen point in world space.
I also wanted to be able to draw text inside rectangular boundaries. For this I chose another point. At this point text should end. Did the same procedure as with start point, and then calculated width
targetWidth = endpoint.x - startpoint.x;
Then I used GlypthLayout class to get actual width of my text at some(generated) font size.
actualWidth = glyphLayout.width;
And when I scaled font like this
font.getData().setScale(targetWidth / actualWidth);
my font get scaled so drawed text is wide as target width.
But be aware of another problem! When I generate bimap font via FreetypeGenerator with size bigger when approximately 300, some letters don't draw, and are missing. (probably bug).
I am developing vector graphics editor in Java Swing/AWT technology.
I am curious about solution for creating drawing area (workspace), which have size bigger than users screen resolution.
For example: Window of creating new file
public WorkspaceComponent() {
setPreferredSize(new Dimension(**WIDTH**,**HEIGHT**));}
User wants to create a document of size e.g 1920 x 1080[px], but his/her screen has only 1280 x 720 [px].
Does anybody have an idea or solution for scaling the drawing area to match screen and after export having original size?
Using an AffineTransform on the Graphics2D Context you can scale the drawing area. Using this, you could even implement something like a zoom in/out feature.
double scaledSize = ... // do calculations of the scale here
AffineTransform t = new AffineTransform();
t.scale(scaledSize, scaledSize);
g2d.setTransform(t);
// do your drawing after setting the transform
If your scale is 1, it wont change the scale. A value less than one will make it smaller and a value greater than 1 will make it bigger.
I want my canvas to have a fixed width and high so when say item 200px, by 100px that is relative to the canvas but may get display bigger or smaller depending on the user screen size. So what it want to know is can make canvas 640x360 or what ever size i want but display it the bigger i can on the users screen as zoom so all distastes are the same.
I have a buffered image of a 4x4 checker Board (resolution 400x400) rendered on half a JPanel. Is it possible to find the coordinates of each square corner without doing it manually? I'm using absolute positioning on the JPanel and it is the only container besides the Frame
If you have a 4 x 4 checkerboard that's 400 x 400, then each square is 100 x 100 pixels.
When you construct a BufferedImage like this, you save a Rectangle for each square as you're doing the construction.
That way, when you do a mouse click later, you can use the contains method of Rectangle to determine which square was clicked.
You shouldn't use absolute positioning. If your checker board takes up half the JPanel, FlowLayout or BoxLayout works well.
I am capturing the screen using robot.screenCapture() and frame bufferedImage1. Again I am capturing desktop screen and frame bufferedImage2.
Could please tell me how to compare these 2 images (bufferedImage1 and bufferedImage2) pixel by pixel. If there is any difference, then how to frame the part that is different?
Here's one way to do it:
Compare the entire images, get the percentage of pixels that differ more than a threshold.
Divide into quarters recursively, down to a certain size, and get the same percentage for each quadrant.
Draw the frame around the quadrants that are a certain amount above the average difference. If you need square sections, use a single quadrant based on size and percent difference. Otherwise, you can combine more than one quadrant with large differences.