I am trying to create an image of one of my JPanels at a fixed resolution, or at a resolution that may be bigger than the current screen resolution. Consequently I cannot use a simple screen capture method as it causes my image resolution to be dependent on the resolution of the screen, which the user sets. Is there a way around this?
Alternatively, is there a way to do this in openGL? Create a virtual buffer, render into it, then create an image based on that virtual space?
Just create the control, you don't need to add it to any JFrame or otherwise cause it to be displayed. You can subsequently use the print method on it to cause it to be rendered to a Graphics object. You can set the size and such as you like without having to take care of the screen boundaries (as the control is never displayed on screen).
Look at JxCapture. It's a commersial product but you can get free license if you're developing open-source (or maybe even non-commercial) project.
Check out the Screen Image class.
Related
I want to draw Strings in my Libgdx game but i cant use BitMap Fonts because the scale of my game is to smal to use them.
It sounds like you mean the scale of your viewport is too small to show fonts correctly. There are two solutions. The first is better for legibility while the second is quick and dirty.
One is to use a second viewport for the UI that has an appropriate scale for text. You would first call gameViewport.apply(), draw the game, and end the batch. Then use uiViewport.apply() and then draw the UI. The downside with this method would be if you want to draw text that aligns with moving objects in the game, you would have to use the two viewports to convert coordinates. Otherwise, this is the ideal method to get a crisp looking UI. Ideally you would use a ScreenViewport and select a font size at runtime based on the screen dimensions, either by shipping your game with multiple versions of the font at different scales, or by using FreeTypeFontGenerator.
The second method is to scale down all your text. First call bitmapFont.setUseIntegerPositions(false) do it won't round off positions to integers. Then call bitmapFont.setScale() with however much you want to shrink it to fit in your game viewport.
There is a gdx-freetype project:
https://www.badlogicgames.com/wordpress/?p=2300
and it uses TrueType fonts as source to generate bitmap font on the fly.
Not sure how stable this is - didn't use it.
I would like to resize multiple imageIcons that I have attached to certain panels, but I'm not sure how to do that. After much research I've attempted to use .getScaledInstance but have had no luck, is that what I'm supposed to use? Since I define my panels outside of the main class but need to use the scaled instances of the images in multiple methods, would I add a line such as
image.getImage().getScaledInstance(30,30,whatever);
or would I need to do a different action?
getScaledInstance doesn't effect the original image, but instead returns a new instance of the image scaled to meet your parameters, make sure you are assigning the result to a variable, for example
image = image.getImage().getScaledInstance(30,30,whatever);
Then pass this to your what ever needs to use it
Beware, the quality of the operation is pretty poor, especially over a large range.
Take a look at
Quality of Image after resize very low -- Java
Java: maintaining aspect ratio of JPanel background image
The Perils of Image.getScaledInstance()
For details and ideas.
I'm beginning to write a special use graphing program and I'm leaning towards using OpenGL to generate the graphics. The ultimate goal is an architecture that accommodates both 2D and 3D graphs with the basic framework.
Exporting the generated graphs as images is a critical feature, and eventually I'm going to write the code to generate vector images of the graphs' 2D projections. However, in the mean time, I want to be able to export the graphs as high resolution images--images significantly larger than the application window.
I'm writing this application in Java and using the LWJGL OpenGL wrapper. I've figured out how to take screenshots of the display window, but I haven't been successful creating larger images. I've tried to make invisible Canvases, but I can't make it work.
The documentation says here that the Canvas's isDisplayable() method must return true, and to that end I've overridden the isDisplayable() method to always return true, so that it shouldn't care whether or not it's in a Frame, but this doesn't work. Instead, it throws the following error:
java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at org.lwjgl.opengl.GL20.glDeleteProgram(GL20.java:311)
The problem seems to be that it also needs some properties from the top-level window, but even when I make a dummy Frame class I get the same error as before, until I call setVisible(true) on the frame.
Does anyone know how to fake these graphics properties into thinking it has a visible top-level window? Does anyone know an easier way?
As an alternative, you could use a framebuffer object (FBO) to render into a texture.
Have a look at this render to texture example.
I'm making desktop app in Java Swing.
In my app I do some image processing on my image which is a 16 bit, Gray-Scale and tiff image.
In my app the user can open images from tree using drag and drop of image into a JDesktopPane.
Now when user done some process on image like Remove Noise or set Contrast, when they close the image my app should ask if they want to Save Changes in Image?
So how can i check run time that some changes in Original image?
The java.awt.image.Raster contained in a BufferedImage does not override Object#equals(). This is largely because iterating over w * h pixels can get expensive: O(wh). Any optimization depends on the nature of the change. If you're only looking for global changes, such as noise or contrast, comparing a number of samples may suffice. You'll also want to profile your intended usage.
I'm trying to create a gauge/meter/dial animation as part of an application I'm trying to build.
What I'm trying to do is to display the acceleration values that I get via the the sensors on a gauge. Now I'm able to successfully get the values from the sensors but I don't know how to display them as an animated gauge/dial.
I've looked at the frame-by-frame and tweened animations, but they don't suit my needs, because I can't seem to use them to change the animation based on input from the code.
I should be able to display an image for the gauge and an image for the needle and then change the rotation of the needle image according to the values so as to make it look animated but I don't know how to do this.
Is there a way a do what I'm trying to do?
Is there a better/alternate way?
I'm using the standard Android SDK and eclipse and trying to support devices with android v2.2 upwards.
Hi Ayos Draw the background, a solid color is best, then draw you indicator in a different color (black). When you get a new value, test to see if its different and if it is draw the indicator in the background color (erase it). Then draw the new indicator. You will need to figure out a way of scaling your raw data and making it in to degrees to draw the indicator. Its best if your difference test allows you to not change the indicator if the change does not move the indicator less that a degree or two. If you use an image or pattern for the background then you have a big job in erasing the indicator. You might have to redraw the background every time, that takes a lot of processing time and the gauge may look jumpy. Cliff