I'm trying the basic jMonkey but I get this exception
jun 27, 2012 9:25:08 FM com.jme3.system.JmeDesktopSystem initialize
Info: Running on jMonkeyEngine 3.0.0 Beta
jun 27, 2012 9:25:08 FM com.jme3.system.Natives extractNativeLibs
Info: Extraction Directory: C:\prv_workspace_8\DungeonWorldAdventure
jun 27, 2012 9:25:13 FM com.jme3.system.lwjgl.LwjglAbstractDisplay run
Info: Using LWJGL 2.8.3
jun 27, 2012 9:25:13 FM com.jme3.system.lwjgl.LwjglDisplay createContext
Info: Selected display mode: 640 x 480 x 0 #0Hz
jun 27, 2012 9:25:13 FM com.jme3.app.Application handleError
Allvarlig: Failed to create display
org.lwjgl.LWJGLException: Pixel format not accelerated
at org.lwjgl.opengl.WindowsPeerInfo.nChoosePixelFormat(Native Method)
at org.lwjgl.opengl.WindowsPeerInfo.choosePixelFormat(WindowsPeerInfo.java:52)
at org.lwjgl.opengl.WindowsDisplay.createWindow(WindowsDisplay.java:214)
at org.lwjgl.opengl.Display.createWindow(Display.java:306)
at org.lwjgl.opengl.Display.create(Display.java:873)
at org.lwjgl.opengl.Display.create(Display.java:782)
at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:137)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:113)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
at java.lang.Thread.run(Thread.java:722)
jun 27, 2012 9:25:13 FM com.jme3.app.Application handleError
Allvarlig: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalStateException
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:147)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)
at java.lang.Thread.run(Thread.java:722)
Exception: java.lang.NullPointerException thrown from the UncaughtExceptionHandler in thread "LWJGL Renderer Thread"
The code I'm trying to run is
package adventure;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.math.ColorRGBA;
/** Sample 1 - how to get started with the most simple JME 3 application.
* Display a blue 3D cube and view from all sides by
* moving the mouse and pressing the WASD keys. */
public class Test extends SimpleApplication {
public static void main(String[] args){
Test app = new Test();
app.start(); // start the game
}
#Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin
Geometry geom = new Geometry("Box", b); // create cube geometry from the shape
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
mat.setColor("Color", ColorRGBA.Blue); // set color of material to blue
geom.setMaterial(mat); // set the cube's material
rootNode.attachChild(geom); // make the cube appear in the scene
}
}
What am I doing wrong?
This seems like a graphics card driver problem. Make sure to update your drivers. If that doesn't work, your graphics card just may be outdated.
Related
I am trying to store the Vuforia User Image targets locally so users will not have to create the targets every time they leave the scene.
I tried to store the variables to create the new image target in a static class so i can retrieve them when i am back to the scene. and create the image targets then add them to the dataset.
//****************************************************************************************************
//Trying to load image target between scenes
//****************************************************************************************************
//Deactivate the dataset in order to add the image target
m_ObjectTracker.DeactivateDataSet(m_UDT_DataSet);
var LastImageTrackable = ImageTargetStorage.newTrackable;
if(LastImageTrackable != null)
{
//Find UDT behavior and Gameobject
ImageTargetBehaviour imageTargetCopy = Instantiate(ImageTargetTemplate);
System.Random rnd = new System.Random();
int RandomNum = rnd.Next(1, 1000);
imageTargetCopy.gameObject.name = "UserDefinedTarget-" + RandomNum;
// Add the target to the dataset
try{
m_UDT_DataSet.CreateTrackable(LastImageTrackable, imageTargetCopy.gameObject);
}
catch(Exception ex)
{
Debug.Log("An Error has occured while trying to create image target from different scene.");
}
// Activate the dataset again
m_ObjectTracker.ActivateDataSet(m_UDT_DataSet);
}
//****************************************************************************************************
Unity Crashes and never give me any useful data on the issue.
the step that causes the crash is
m_UDT_DataSet.CreateTrackable(LastImageTrackable, imageTargetCopy.gameObject);
which gets the LastImageTrackable from previous creation.
Please advise me on this error and kindly suggest a different framework if Vuforia is not suitable for this simple task.
Can someone explain what are iTextEvents in ItextSharp..
I have found a bunch of codes with its use but i dont get how they works..
Im asking you if anyone can explain me these:
OnOpenDocument
OnEndPage
OnCloseDocument
If you are looking to start using iText, then your question is obsolete. You are referring to a concept that was used in versions 5 and earlier of iText for .NET (we abandoned the name iTextSharp a long time ago). If you want to start using iText for .NET, you should start with version 7, not with iText 5 or earlier, because we stopped development on those versions. Any release we make now is nothing more than a maintenance release (maintenance releases don't contain new functionality, they have bug fixes that are meant for paying users who can't migrate to iText 7 immediately).
The name page events was misleading because those events were initially used to allow developers to execute code when a new page was created or finalized, but as the code grew organically, we also started to use the page event functionality for other things, such as: to add special behavior of a Chunk (OnGenericTag()) or to execute code before or after adding a Paragraph. That was an example of bad design.
We fixed this bad design in iText 7, where we introduced renderers and event handlers. See chapter 3 of the jump-start tutorial, entitled Using renderers and event handlers.
In iText 7, we can create an event handler such as:
protected internal class MyEventHandler : IEventHandler {
public virtual void HandleEvent(Event #event) {
PdfDocumentEvent docEvent = (PdfDocumentEvent)#event;
PdfDocument pdfDoc = docEvent.GetDocument();
PdfPage page = docEvent.GetPage();
int pageNumber = pdfDoc.GetPageNumber(page);
Rectangle pageSize = page.GetPageSize();
PdfCanvas pdfCanvas = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), pdfDoc);
//Set background
Color limeColor = new DeviceCmyk(0.208f, 0, 0.584f, 0);
Color blueColor = new DeviceCmyk(0.445f, 0.0546f, 0, 0.0667f);
pdfCanvas.SaveState()
.SetFillColor(pageNumber % 2 == 1 ? limeColor : blueColor)
.Rectangle(pageSize.GetLeft(), pageSize.GetBottom(), pageSize.GetWidth(), pageSize.GetHeight())
.Fill()
.RestoreState();
//Add header and footer
pdfCanvas.BeginText()
.SetFontAndSize(C03E03_UFO.helvetica, 9)
.MoveText(pageSize.GetWidth() / 2 - 60, pageSize.GetTop() - 20)
.ShowText("THE TRUTH IS OUT THERE")
.MoveText(60, -pageSize.GetTop() + 30)
.ShowText(pageNumber.ToString())
.EndText();
//Add watermark
iText.Layout.Canvas canvas = new iText.Layout.Canvas(pdfCanvas, pdfDoc, page.GetPageSize());
canvas.SetProperty(Property.FONT_COLOR, Color.WHITE);
canvas.SetProperty(Property.FONT_SIZE, 60);
canvas.SetProperty(Property.FONT, C03E03_UFO.helveticaBold);
canvas.ShowTextAligned(new Paragraph("CONFIDENTIAL"), 298, 421, pdfDoc.GetPageNumber(page), TextAlignment.
CENTER, VerticalAlignment.MIDDLE, 45);
pdfCanvas.Release();
}
}
The event handler is introduced in the code like this:
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
pdf.AddEventHandler(PdfDocumentEvent.END_PAGE, new C03E03_UFO.MyEventHandler(this));
// Initialize document
Document document = new Document(pdf);
Paragraph p = new Paragraph("List of reported UFO sightings in 20th century").SetTextAlignment(TextAlignment
.CENTER).SetFont(helveticaBold).SetFontSize(14);
document.Add(p);
Table table = new Table(new float[] { 3, 5, 7, 4 });
table.SetWidth(UnitValue.CreatePercentValue(100));
StreamReader sr = File.OpenText(DATA);
String line = sr.ReadLine();
Process(table, line, helveticaBold, true);
while ((line = sr.ReadLine()) != null) {
Process(table, line, helvetica, false);
}
sr.Close();
document.Add(table);
document.Close();
This code adds a background, a watermark, a header, and a footer, as is shown in this figure:
Page events in "iTextSharp" had a similar purpose, but you shouldn't use them anymore. They are outdated. You should use iText 7 instead.
If you posted your question out of historical curiosity, you should search old questions on Stack Overflow, such as:
How can I add an image to all pages of my PDF?
itextsharp: How to generate a report with dynamic header in PDF using itextsharp?
Change the color of pdf pages alternatively using iText pdf in java
How to introduce multiple PdfPageEventHelper instances?
...
I am using ImageIcon to access a photo I have cropped. I put all the cropped pictures in a pic source folder in side the project. Yet when I try to use this.getClass().getResource("image 2.png") to find the image 2.png photo, the code couldn't find it. Is there anyway to fix this, do I have to re upload all the picture into a different folder?
the "image 2.png" is inside the pic source folder, which is within the folder of the project Alle, according to the navigator panel on the right. (I am using eclipse)
Here is my code:
import java.awt.*;
import java.io.File;
import java.io.IOException;
import javax.swing.*;
public class alle extends JFrame {
JButton button1, button2;
JLabel Label1, Label2;
ImageIcon Icon1;
ImageIcon Icon2;
public alle() {
setLayout(new GridLayout(2,3)); //create a gridwolrd like thing that's like 2 row, 3 column
button1 = new JButton("set");
add(button1);
Label1 = new JLabel(" button");
add(Label1);
Icon1 = new ImageIcon(this.getClass().getResource("/alle/pic/image 2.png")) ;
JLabel p = new JLabel(Icon1);
add(p);
}
public static void main (String arg[]) {
alle adfc = new alle();
adfc.setResizable(false);
adfc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
adfc.setVisible(true);
adfc.pack();
File f = new File ("/alle/pic/image 2.png");
System.out.print(f.exists());}}
I also had this kind of problem about a year ago. You should be able to resolve it by writing a loader method for retrieving the images. You can find a detailed answer on this article which also worked for me: Images Won't Appear In A Jar
If you don't want to read through the whole post here's the code sample that should resolve things, you only need to adjust it to your needs:
public ImageIcon loadIcon(String iconName) throws IOException {
ClassLoader loader = this.getClass().getClassLoader();
BufferedImage icon = ImageIO.read(loader.getResourceAsStream(iconName));
return new ImageIcon(icon);
}
From this method you should be able to retrieve your images. I hope this helps you.
I've inserted the code below. My Jframes pop up, and close when they're supposed to, but nothing shows u inside of my JFrame. It should say "sending..." next to a gif of a loading bar. I've tried everything. I freatly appreciate any and all help. Thank You
package image_processor;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
/*
* To change this license header, choose License Headers in ProjectProperties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* #author root
*/
public class SendingGUI {
public void sending() {
JFrame frame = new JFrame("Sending Image(s)");
JFrame frame2 = new JFrame("Image(s) Sent!");
ImageIcon gifImage = new ImageIcon("/opt/med-seg-netbeans/med-seg /senderGUI/ajax-loader.gif");
JLabel label1 = new JLabel("Sending, please wait... ",gifImage, JLabel.CENTER);
JLabel label2 = new JLabel("Images Sent. Processing...",gifImage,JLabel.CENTER);
frame.add(label1);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(350, 150);
frame.setVisible(true);
try{
Thread.sleep(4000);
}catch(InterruptedException e){
}
frame.setVisible(false);
frame2.add(label2);
frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame2.setSize(350, 150);
frame2.setVisible(true);
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING,frame2));
try{
Thread.sleep(3000);
}catch(InterruptedException e){
}
frame2.setVisible(false);
}
}
The code is correct.
I suspect your image URL is incorrect, or alternatively, the Label may not support animated.
Solution:
Try using a different image. Ideally a non-animated image.
If you're using Windows, place the image in C:\ drive so the code will read:
ImageIcon gifImage = new ImageIcon("C:/image.gif");
Let me give you an overview of my project first. I have a pdf which I need to convert into images(One image for one page) using PDFBox API and write all those images onto a new pdf using PDFBox API itself. Basically, converting a pdf into a pdf, which we refer to as PDF Transcoding.
For certain pdfs, which contain JBIG2 images, PDFbox implementation of convertToImage() method is failing silently without any exceptions or errors and finally, producing a PDF, but this time, just with blank content(white). The message I am getting on the console is:
Dec 06, 2013 5:15:42 PM org.apache.pdfbox.filter.JBIG2Filter decode
SEVERE: Can't find an ImageIO plugin to decode the JBIG2 encoded datastream.
Dec 06, 2013 5:15:42 PM org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap getRGBImage
SEVERE: Something went wrong ... the pixelmap doesn't contain any data.
Dec 06, 2013 5:15:42 PM org.apache.pdfbox.util.operator.pagedrawer.Invoke process
WARNING: getRGBImage returned NULL
I need to know how to resolve this issue? We have something like:
import org.apache.pdfbox.filter.JBIG2Filter;
which I don't know how to implement.
I am searching on that, but to no avail. Could anyone please suggest?
Take a look at this ticket in PDFBox https://issues.apache.org/jira/browse/PDFBOX-1067 . I think the answer to your question is:
to make sure that you have JAI and the JAI-ImageIO plugins installed for your version of Java: decent installation instructions are available here: http://docs.geoserver.org/latest/en/user/production/java.html
to use the JBIG2-imageio plugin, (newer versions are licensed under the Apache2 license) https://github.com/levigo/jbig2-imageio/
I had the same problem and I fixed it by adding this dependency in my pom.xml :
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
<version>3.0.2</version>
</dependency>
Good luck.
I had the exact same problem.
I downloaded the jar from
jbig2-imageio
and I just included it in my project's application libraries, and it worked right out of the box. As adam said, it uses GPL3.
Installing the JAI seems not needed.
I only needed to download the levigo-jbig2-imageio-1.6.5.jar, place it in the folder of my dependency-jars and in eclipse add it to the java build path libraries.
https://github.com/levigo/jbig2-imageio/
import java.awt.image.BufferedImage
import org.apache.pdfbox.cos.COSName
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.pdmodel.PDPage
import org.apache.pdfbox.pdmodel.PDPageTree
import org.apache.pdfbox.pdmodel.PDResources
import org.apache.pdfbox.pdmodel.graphics.PDXObject
import org.apache.pdfbox.rendering.ImageType
import org.apache.pdfbox.rendering.PDFRenderer
import org.apache.pdfbox.tools.imageio.ImageIOUtil
import javax.imageio.ImageIO
import javax.imageio.spi.IIORegistry
import javax.imageio.spi.ImageReaderSpi
import javax.swing.*
import javax.swing.filechooser.FileNameExtensionFilter
public class savePDFAsImage{
String path = "c:/pdfImage/"
//allow pdf file selection for extracting
public static File selectPDF() {
File file = null
JFileChooser chooser = new JFileChooser()
FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF", "pdf")
chooser.setFileFilter(filter)
chooser.setMultiSelectionEnabled(false)
int returnVal = chooser.showOpenDialog(null)
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile()
println "Please wait..."
}
return file
}
public static void main(String[] args) {
try {
// help to view list of plugin registered. check by adding JBig2 plugin and JAI plugin
ImageIO.scanForPlugins()
IIORegistry reg = IIORegistry.getDefaultInstance()
Iterator spIt = reg.getServiceProviders(ImageReaderSpi.class, false)
spIt.each(){
println it.getProperties()
}
testPDFBoxSaveAsImage()
testPDFBoxExtractImagesX()
} catch (Exception e) {
e.printStackTrace()
}
}
public static void testPDFBoxExtractImagesX() throws Exception {
PDDocument document = PDDocument.load(selectPDF())
PDPageTree list = document.getPages()
for (PDPage page : list) {
PDResources pdResources = page.getResources()
for (COSName c : pdResources.getXObjectNames()) {
PDXObject o = pdResources.getXObject(c)
if (o instanceof org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) {
File file = new File( + System.nanoTime() + ".png")
ImageIO.write(((org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) o).getImage(), "png", file)
}
}
}
document.close()
println "Extraction complete"
}
public static void testPDFBoxSaveAsImage() throws Exception {
PDDocument document = PDDocument.load(selectPDF().getBytes())
PDFRenderer pdfRenderer = new PDFRenderer(document)
for (int page = 0; page < document.getNumberOfPages(); ++page) {
BufferedImage bim = pdfRenderer.renderImageWithDPI(page,300, ImageType.BINARY)
// suffix in filename will be used as the file format
OutputStream fileOutputStream = new FileOutputStream(+ System.nanoTime() + ".png")
boolean b = ImageIOUtil.writeImage(bim, "png",fileOutputStream,300)
}
document.close()
println "Extraction complete"
}
}