I'm developing an application using Eclipse and SWT.
If I do the following on a mac, the second file has the same contents as the first one.
There was a bug in SWT that was solved nearly a decade ago that was related with how swt.GC was disposed. But in my case it's not being disposed.
It seems there's a cache being held somewhere, but I couldn't find a way to get rid of it.
My code, simplified:
Image myImg = new Image( Display.getDefault(), 100, 100 );
GC mygc = new GC( myImg );
// draw something
// Saves the image to a file.
saveImage( myImg );
// draw something else on the same image.
// Saves the image to another file.
saveImage( myImg );
myImg.dispose();
mygc.dispose();
If I do this after saving the first file, and before the extra drawing operations, the problem is solved:
mygc.dispose();
mygc = new GC( myImg );
But I don't want to dispose and create a new GC, because of performance issues.
On Windows it works perfectly.
I've got an application window using JavaFX.
This window contains a simple WebView to display a HTML document.
Inside the HTML document, there is a script tag, executing a Java function, which returns the pixels as int[].
I'm using the following code to draw the image onto the canvas:
var context = canvas.getContext('2d');
var imageData = context.createImageData(canvas.width, canvas.height);
var buffer8 = new Uint8ClampedArray(imageData.data.buffer);
var buffer32 = new Uint32Array(imageData.data.buffer);
buffer32.set(pixels);
context.putImageData(imageData, 0, 0);
This works, however performance is about 0.07 seconds per frame, giving me a total of ~ 15 FPS, using a 640x480 canvas currently. My goal is to get at last 30fps for 1920x1080 (currently 5 FPS), and even higher values. The only solution i come up with is to create/populate the whole buffer at once on the java side, but i have no idea how to manage that. Any help would be appreciated.
I've been trying to make a surface in Java 3D reflect in a similar manner to a mirror. The API says to use TexCoordGeneration in SPHERE_MAP mode, but it doesn't seem to be making any difference at all.
Can anyone spot what I'm doing wrong?
Appearance reflectAp = new Appearance();
TexCoordGeneration tex = new TexCoordGeneration();
tex.setGenMode(TexCoordGeneration.SPHERE_MAP);
reflectAp.setMaterial(matFact.silver());
reflectAp.setTexCoordGeneration(tex);
flat = new Box(.7f, .9f, .01f, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, reflectAp);
I'm trying to make an mp3 player in java and I can`t figure out how to control the volume in it.
I've tried something like this:
// Adjust the volume on the output line.
if (dataLine.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
FloatControl volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(100.0F);
}
Everything I have written until this code worked fine but apparently the dataLine is NOT control Supported because it jumps over this IF statement.
My question is this : Do you have any idea why this is happening and how could I work this issue around so that I could control the volume of my application?
OK GUYS,
I found my mess-up. I actually forgot to call the dataLine.open(audioFormat) function which acquires the system resources.
So the code workes just fine, in case anyone has this kind of problems too
Have you tried to see what dataLine.getControls() will return ?
Obtains the set of controls associated
with this line. Some controls may only
be available when the line is open. If
there are no controls, this method
returns an array of length 0.
If you want volume wouldn't you want to test for the FloatControl.Type.VOLUME control ?
float vol=50;
final FloatControl volumeControl = (FloatControl) auline.getControl( FloatControl.Type.MASTER_GAIN );
volumeControl.setValue( 20.0f * (float) Math.log10( vol / 100.0 ) );
vol=0 means mute.
I'm working on a simple 2D game engine in Java, and having no trouble with FSEM, buffer strategies, and so on; my issue is with the mouse cursor. In windowed mode, I can hide the mouse cursor, no problem, by using setCursor() from my JFrame to set a wholly-transparent cursor. However, after a call to device.setFullScreenWindow(this) to go into FSEM, the mouse cursor comes back, and subsequent calls to setCursor() to set it back to my blank cursor have no effect. Calling device.setFullScreenWindow(null) allows me to get rid of the cursor again - it's only while I'm in FSEM that I can't get rid of it.
I'm working under JDK 6, target platform is JDK 5+.
UPDATE: I've done some more testing, and it looks like this issue occurs under MacOS X 10.5 w/Java 6u7, but not under Windows XP SP3 with Java 6u7. So, it could possibly be a bug in the Mac version of the JVM.
Try Creating a custom invisible cursor:
Toolkit toolkit = Toolkit.getDefaultToolkit();
Point hotSpot = new Point(0,0);
BufferedImage cursorImage = new BufferedImage(1, 1, BufferedImage.TRANSLUCENT);
Cursor invisibleCursor = toolkit.createCustomCursor(cursorImage, hotSpot, "InvisibleCursor");
setCursor(invisibleCursor);
One developer found a way around it by creating a one pixel cursor out of a transparent GIF.
http://sevensoft.livejournal.com/23460.html
I know you tried that, but his is specifically addressing the issue of full-screen mode, exactly as you say, so perhaps there's something he's done that you haven't.
I think I've finally found the solution:
System.setProperty("apple.awt.fullscreenhidecursor","true");
This is an Apple-proprietary system property that hides the mouse cursor when an application is in full-screen mode. It's the only way I've found to fix it.
Here's what has been working for me:
Toolkit toolkit = Toolkit.getDefaultToolkit();
// get the smallest valid cursor size
Dimension dim = toolkit.getBestCursorSize(1, 1);
// create a new image of that size with an alpha channel
BufferedImage cursorImg = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
// get a Graphics2D object to draw to the image
Graphics2D g2d = cursorImg.createGraphics();
// set the background 'color' with 0 alpha and clear the image
g2d.setBackground(new Color(0.0f, 0.0f, 0.0f, 0.0f));
g2d.clearRect(0, 0, dim.width, dim.height);
// dispose the Graphics2D object
g2d.dispose();
// now create your cursor using that transparent image
hiddenCursor = toolkit.createCustomCursor(cursorImg, new Point(0,0), "hiddenCursor");
Granted, I haven't tested it on Mac (yet), only Windows. But when I used the common methods I was getting the cursor as black box, so I use the code above the create a transparent box and set it as the cursor instead. Of course you have to use the setCursor method on an AWT object (such as your app's Frame) to set this hiddenCursor. Here is my hideMouse method ('fr' is my Frame):
public void hideMouse(boolean hide) {
if(hide) {
fr.setCursor(hiddenCursor);
} else {
fr.setCursor(Cursor.getDefaultCursor());
}
}
I don't know if this knowledge applies but in a old VB6 app I had the same problem and I got rid of it moving the cursor out of the screen giving it some very large values.
Hope it helps.
If you're running only on Windows, it looks like you'll need to call ShowCursor(FALSE) through JNI. At least, to make the cursor hide complete.
Here's some code which creates the 1x1 cursor. It works for me, though I still get a 1x1 cursor.
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension dim = toolkit.getBestCursorSize(1,1);
transCursor = toolkit.createCustomCursor(gc.createCompatibleImage(dim.width, dim.height),
new Point(0, 0), "transCursor");
((Component)mainFrame).setCursor(transCursor);
Specifically for your Mac problem, through JNI you could use the following:
Quartz Display Services Reference - CGDisplayHideCursor