I have a simple solar system consisting of two planets and a sun.
I can now map images to spheres, but I want to map an animated gif to a sphere.
I assumed this would be the same code, but when I load the animated gif, it simply plays the first frame and doesn't animated through the other frames.
The code that loads the image
Texture tex = null;
File img = new File("src/images/earth.jpg");
try {
tex = new TextureLoader(ImageIO.read(img)).getTexture();
} catch (IOException e) {
e.printStackTrace();
}
tex.setBoundaryModeS(Texture.WRAP);
tex.setBoundaryModeT(Texture.WRAP);
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
Appearance ap = new Appearance();
ap.setTexture(tex);
ap.setTextureAttributes(texAttr);
------
Node earth = new Sphere(earthRadius, primflags, 100, ap);
Am I missing something obvious?
Any help or pointers would be fanatics. If I have failed to give enough detail, please ask and I will be more than happy to supply more code.
Related
I'm trying to write a simple "Paint"-like JavaFX-Application.
I draw on to a JavaFX.scene.canvas, this works quite well.
Now I want to save this canvas as a ".png" image. Works, but the transparent pixels where swapped with white ones.
How do I save transparent pixels, as transparent Pixels?
Here is how I save the canvas:
private void saveFile(){
FileChooser fc = new FileChooser();
fc.setInitialDirectory(new File("res/maps"));
fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("PNG","*.png"));
fc.setTitle("Save Map");
File file = fc.showSaveDialog(primaryStage);
if(file != null){
WritableImage wi = new WritableImage((int)WIDTH,(int)HEIGHT);
try { ImageIO.write(SwingFXUtils.fromFXImage(canvas.snapshot(null,wi),null),"png",file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
The problem is that when you snapshot the canvas, the first argument to snapshot is null, which means that default SnapshotParameters are used. In particular, the entire destination image is first filled with the SnapshotParameter's fill value. Since the argument is null, the default fill value is null, which means that the fill value (see SnapshotParameters.setFill) is white.
To fix this, just create a SnapshotParameters object, set its fill to transparent, and use it in the call to snapshot:
SnapshotParameters sp = new SnapshotParameters();
sp.setFill(Color.TRANSPARENT);
...
ImageIO.write(SwingFXUtils.fromFXImage(canvas.snapshot(sp, wi), null), "png", file);
I have a gif image and I would like to be able to detect whether the gif is an animated gif or not using JAVA. This question is about detection rather than displaying the gif.
I see that MIME type of animated gif isn't different of static gif.
How I can do it?
You need an ImageReader. if size is 1 its not animated, everything above is animated.
Check this out:
public Snippet() {
File f = new File("test.gif");
ImageReader is = ImageIO.getImageReadersBySuffix("GIF").next();
ImageInputStream iis;
try {
iis = ImageIO.createImageInputStream(f);
is.setInput(iis);
int images= is.getNumImages(true);
} catch (IOException e) {
e.printStackTrace();
}
}
I'm working on a project which involves taking an image file as input on my desktop and then detecting and decoding all the barcodes present, both 1D and 2D.
I've been working with zxing and with the help of GenericMultipleBarcodeReader I was able to read multiple 1D barcodes from the image. However, it fails to detect 2D barcodes.
But if I crop the 2D barcode and input this cropped part separately it detects and decodes it without any problem.
So, if my image has 2 1D barcode and a 2D barcode my output consists of just the 2 1D barcodes decoded.
I also tried using ByQuadrantReader but that doesn't work either.
My code:
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result[] result;
HashMap<DecodeHintType,Object> hints = new HashMap<>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
try
{
result = new GenericMultipleBarcodeReader(new MultiFormatReader()).decodeMultiple(bitmap, hints);
}
catch (ReaderException re)
{
return re.toString();
}
List<String> strings = new ArrayList<String>();
for (Result r: result)
{
strings.add(r.getText());
}
return String.valueOf(Arrays.toString(strings.toArray()));
Could anyone tell me a way to do this?
QR codes can be found anywhere in the image, but Data Matrix must be in the center of the image to be found. This is why it's working when you crop the image.
I am a java programmer,I am trying to use the screen which are open and take a screen shot and compare it with an other picture and see how many of that object is on my screen. I tried to look for examples in java, but they were all in c++ and i couldn't convert them. I know my problem is in the first line, since CascadeClassifier wants a .xml file not a .png. Can someone help me with this, all I want is a program in java that do the same as this example but using the screen shot, or using screen-capture.
CascadeClassifier balDec = new CascadeClassifier("img/ball.png");
BufferedImage screenShot = r.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
try {
ImageIO.write(screenShot, "png", new File("screenShot"+i+".png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Mat screen =Highgui.imread("screenShot0.png");
MatOfRect balls = new MatOfRect();
balDec.detectMultiScale(screen, balls);
I am trying to make the image move rather than a geometric shape in jbox2d.
I dont see the image .
BodyDef bodyDef =new BodyDef();
bodyDef.position.set(100,100);
bodyDef.type=BodyType.DYNAMIC;
//texture=TextureLoader.getTexture("PNG",ResourceLoader.getResourceAsStream("resources/small.png"));
BufferedImage img = null;
try {
img = ImageIO.read(new File("resources/small.png"));
} catch (IOException e) {
}
bodyDef.userData=img;
JBox2D is based on the Box2D engine, which is a physics engine, nothing relative to something visual. You have to draw the image yourself in the main loop of the program, a method often called render().