Newbie Help: Java Object to create an image

Hi there.
I'm trying to create a Java class that I can call from Coldfusion that will build a GIF file based on parameters.
The idea is, the Java object opens a "background" gif file and then writes some text onto it and saves the whole thing out as a GIF.
Bearing in mind this class will be used directly by Coldfusion, and so isn't an applet or an application...can anyone tell me what is wrong with this code as I get a null pointer exception on the getGraphics() line:
// Methods available to Coldfusion
public String CreateOverlay( String imageFile, String outPath, String overlayText, int x, int y, String fontFace, int PointSize)
try{
Toolkit tk = Toolkit.getDefaultToolkit();
Image im = tk.getImage(imageFile);
Gif89Encoder enc = new Gif89Encoder();
OutputStream out = new BufferedOutputStream(
new FileOutputStream(outPath)
Image newimg = createImage(100,50);
***** Graphics g = newimg.getGraphics();
g.drawImage(im, 0, 0, 100, 50, this);
g.drawLine(0,0,50,50);
enc.addFrame( newimg );
enc.encode(out);
out.close();
catch (Exception e) {
System.out.println("Error...");
e.printStackTrace();
return "Dont care at the moment";
Any help to this troubled newbie would be appreciated.

Hi Kurt,
You must call "setVisible(true)" on your Frame before
creating the image.But, the thing is, this object doesnt have (or need) a GUI. Its just an object that sits on the server and its methods are called to generate an image on disk. Basically what happens is Coldfusion receives information from a user and it loads the java object, calls a method which then generates a new GIF file that is made up of a simple button background and some text (entered by the user)....it then returns the name of this file to Coldfusion and Coldfusion stores it in a database for later retrieval.
In simple terms:
COLDFUSION===========
1. Creates an instance of the JAVA Object
2. Call the generateGif method passing an image filename and some text eg:
newFile=c.GenerateGif( "simplebutton.gif", "Some text for button");
JAVA OBJECT========= (GenerateGif method)
1. Load the GIF simplebutton.gif
2. Create a new blank image
3. Draw the loaded GIF onto the blank one
4. Write the Text ("some text for button") onto the image
5. Take the image and encode it to GIF format
6. Write this GIF to disk
7. Return the filename of the new GIF image just created
8. Finish
As you can see, I dont want or need a GUI.....
Is this possible ?
Thanks in Advance,
Tony Johnson

Similar Messages

  • Y in java objects are created on heap only and not on stack ??

    Hi ,
    I need a answer to the question " why all the objects are created on heap only in java and not on stack " ?
    In java a object is created when we specify new i.e. for example,
    consider the following cases.
    1.
    Vector v = new Vector();
    here object is created and the reference to this object is assigned to variable v. okie.
    2.
    when i write something like
    Vector vec ;
    Here i am creating reference variable for Vector. No object is created and no seperate memory is allocated for it. Reference variablesa are stored along with other primitive variables on the java stack.
    My question is, in C++ by writing case 2 i can create an object and it is creating this object on stack. So why in java object is not created on stack while i do like this ? Why in java objects are created on heap only ?
    If my question is out of interest of this forum i apologize for it. But if somebody can throw some light on it, it would be of great help.
    Cheers !!
    Dipesh

    Hi
    I asked this question just to understand how compiler and jvm cud have been designed......i.e. to know the philosophy behind designing language.......
    now what i cud surmise is that if objects were to be stored in stack then on calling garbage colllector , it may delete some unused obj and unreferenced object(unreachable object) and this in turn may give rise to non-contagious areas in stack, thus nullifying the garbage collector's objective of freeing the the memory. Again deallocating that intersperse spaces into one free block of space will be bit troublesome task.....
    So considering above factor the designer of jvm and java compiler have opted for storing objects on heap rather than stack.....
    If u have something to say bout this.......pls go ahead.......
    Cheers !!
    Dipesh

  • Y in java objects are created on heap only n not on stack ?

    Hi ,
    I need a answer to the question " why all the objects are created on heap only in java and not on stack " ?
    In java a object is created when we specify new i.e. for example,
    consider the following cases.
    1.
    Vector v = new Vector();
    here object is created and the reference to this object is assigned to variable v. okie.
    2.
    when i write something like
    Vector vec ;
    Here i am creating reference variable for Vector. No object is created and no seperate memory is allocated for it. Here this reference is placed on the java stack along with other primitive data types.
    My question is, in C++ by writing case 2 i can create an object and it is creating this object on stack. So why in java object is not created on stack while i do like this ? Why in java objects are created on heap only ?
    If my question is out of interest of this forum i apologize for it. But if somebody can throw some light on it, it would be of great help.
    Cheers !!
    Dipesh

    Cross post!
    http://forum.java.sun.com/thread.jsp?forum=32&thread=260589

  • Newbie help with Objects

    Hi there,
    I've been trying to write a program which invokes a few different methods. I was wondering if there is a way of transferring data.. say an integer... from one method to another?
    Thanks!

    of course there is. that's basically what writing code is all about. start at the beginning and read a basic tutorial
    lots of luck!

  • JSP adding(creating) a image to the page

    Hello ..I am new to JSP and I am wondering how I could i "create" an Image and add it to the JSP ..
    I know this might be a very vague question but I hope I can get a good direction in this forum
    Essentially I want to create a rectangluar band with two colors seperated equally in the middle and depending on the current value I would a need a stripe on the band indicating the position.
    I was wondering where I should start ...(reading ..or an example )

    Creating images is not something that JSPs were designed to do. The various image formats (GIF, JPEG) are essentially binary files ands JSPs are not well suited to creating binary data. If you really want to do something like this, you should use a Java class to generate the image.
    JSPs generate html and therefore you cannot put a physical image into a JSP page. The JSP can invoke a Java class to create an image and place it into a web-accessible directory and the JSP can then include an <IMG> tag in the html it generates.
    If these images will be created on the fly for various users, you'll need to have a mechanism to delete them when they are no longer needed.
    In order to create an image, you'll have to read up on whatever format (e.g. GIF, JPEG) you are planning to you. Writing the code will probably be challenging.
    What might be helpful is to create the image you want with a "paint" program and generate various versions with different stripes. If there is a finite number of possibilities, generate them, name them appropriately and have the JSP put in the appropriate <IMG> tag. You also won't have to worry about deleting them. If the number of possibilities is too large to generate them all, you could study several of the resulting binaries to see how they differ and use that information to write your code.

  • How to create Edit Image in my form

    hi All,
    I have a form with header and detail, in my detail block i need to add Edit Image in my form. When i click on this i should be able to open one of my text column.
    can any one please help me how to create new images....

    Siva,
    There is a different Technology Stack associated with the Enterprise Business Suite (EBS). amitphynyl is correct with the description of how to create a button with the edit.ico assigned to it, but with the EBS, you will want to speak to your DBA to get a list of all the Icons that are available as you will have more icons with the EBS than are available with a standard install of Forms Builder 6i. I would also suggest you ask your DBA to give you a copy of all the Icons so you can add them to your Forms Builder installation so they will be available to you during design of your Form.
    I would also recommend that you review the Oracle Applications User Interface Standards for Forms-Based Products guide in the Oracle Applications Documentation web site to ensure your Custom Form conforms to Oracle guidelines.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • Why java objects on heap

    Hi,
    Why the java architecture is such that all the java objects are created on heap. If in certain cases they are allowed to be created on stack then i think the load on garbage collector can be reduced.
    Just for curiosity I want to know this.
    Thanking you.
    - Jaydipsinh Narolia.

    A wild stab in the dark...
    1) They just didn't think about it.
    2) A stack object would imply that there was at least an implicit destructor. But that couldn't be used in heap objects so stack objects couldn't be used.

  • Problem when adding java objects in a vector and passing thru web service

    Hi! I'm getting this error when I try to add a java object I created into a vector and passing it through a web service: java.lang.IllegalArgumentException: No Serializer found to serialize a 'testObj' using encoding style 'http://schemas.xmlsoap.org/soap/encoding/'
    This does not happen when I simply add strings or Integer objects into the vector. What am I missing?
    Thanks.

    just chek this
    http://forum.java.sun.com/thread.jspa?threadID=501189&messageID=2370914
    Edited by: garava on Jul 16, 2008 1:13 PM.
    It would be great if you could paste the wsdl part for that vector and just have a look for the complex typr cntent
    like for HashMap we have the following mapping
    <complexType name="HashMap">
      <sequence>
        <element name="item" minOccurs="0" maxOccurs="unbounded">
          <complexType>
            <sequence>
              <element name="key" type="anyType" />
              <element name="value" type="anyType" />
            </sequence>
          </complexType>
        </element>
      </sequence>
    </complexType>Since in Value it should again contain a mapping for the Object which you are trying to pass then only an appropriate serializer and deserilaizer would get generated. Hope this answers your query. For refernece
    http://www.theserverside.com/tt/articles/article.tss?l=Systinet-web-services-part-2
    [http://www.theserverside.com/tt/articles/article.tss?l=Systinet-web-services-part-2|For refernce tutorial]
    Thanks,
    Avadhoot Sawant.
    Edited by: garava on Jul 16, 2008 1:16 PM

  • Problem of create an Image object ?

    Dear all :
    the following code does not work when i use it in the application rather than in the applet :
    Image img = createImage(new MemoryImageSource(org_width,org_height,palette,0,org_width));
    where org_width , org_height is an int , while palette is an int[] that contain the pixels data in an application .
    So i then tried to create the ImageProducer object :
    ImageProducer ip = new MemoryImageSource(org_width,org_height,palette,0,org_width);
    But how can i create an Image object using the ImageProducer in an application ? Or any ways to create an Image object using the int [] pixel data in an application ?

    Hi
    I don't know if this is what your looking for, but I had the same problem, and it helped me, so why not try looking at it
    http://forum.java.sun.com/thread.jsp?forum=31&thread=167305
    Aagaard

  • How to retrieve the java object in a proxy service in osb -- Plz help

    Hi all,
    I have a singleton java class which runs whenever the weblogic server gets started and store the output in its object. I need to access this java object from a proxy service in osb.
    We tried using java call out and retrieved that object but we couldn't know how to parse that object into XML.
    We are not sure of using the java call out in osb to solve this purpose because whenever we use a java callout, that particular java code will run which is not the case of singleton class.
    So kindly help us how to retrieve the java object which holds the output without running the java code every time because its already run and holding the output in its object.
    Regards
    Prabhu

    here the doc http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/context.html#wp1106656
    but I guess you are already at the stage of getting a POJO in a first Java Callout and passing the POJO to a second Java Callout, which should then return it to OSB as a XMLObject.
    My recommendation is to write a Java function which returns a XMLObject and uses a XMLCursor to populate it with the values of the POJO.
    An XMLObject returned to the OSB is automatically transformed in a "XML" variable (which in reality is represented as a XMLObject in the Pipeline context)
    Here some code sample:
    http://www.javamonamour.org/2010/09/how-to-create-xmlobject-using-xmlcursor.html

  • How to create and instance of Java Object from an XML Document.

    Hi,
    How can we use a XML Document to create an instance of Java Object and do vice versa ie from the Java Object creating the XML Document.
    XML Document is available in the form of a String Object.
    Are there helper class available to achieve this.
    I need to do this in a Servlet.
    Regards
    Pramod.

    JAXB is part of JavaSE while Xmlbeans claims full schema support and full infoset fidelity.
    If the standard APIs do all that you need well then use them.

  • How to parse XML to Java object... please help really stuck

    Thank you for reading this email...
    If I have a **DTD** like:
    <!ELEMENT person (name, age)>
    <!ATTLIST person
         id ID #REQUIRED
    >
    <!ELEMENT name ((family, given) | (given, family))>
    <!ELEMENT age (#PCDATA)>
    <!ELEMENT family (#PCDATA)>
    <!ELEMENT given (#PCDATA)>
    the **XML** like:
    <person id="a1">
    <name>
         <family> Yoshi </family>
         <given> Samurai </given>
    </name>
    <age> 21 </age>
    </person>
    **** Could you help me to write a simple parser to parse my DTD and XML to Java object, and how can I use those objects... sorry if the problem is too basic, I am a beginner and very stuck... I am very confuse with SAXParserFactory, SAXParser, ParserAdapter and DOM has its own Factory and Parser, so confuse...
    Thank you for your help, Yo

    Hi, Yo,
    Thank you very much for your help. And I Wish you are there...I'm. And I plan to stay - It's sunny and warm here in Honolulu and the waves are up :)
    A bit more question for dear people:
    In the notes, it's mainly focus on JAXB,
    1. Is that mean JAXB is most popular parser for
    parsing XML into Java object? With me, definitely. There are essentially 3 technologies that allow you to parse XML documents:
    1) "Callbacks" (e.g. SAX in JAXP): You write a class that overrides 3 methods that will be called i) whenever the parser encounters a start tag, ii) an end tag, or iii) PCDATA. Drawback: You have to figure out where the heck in the document hierarchy you are when such a callback happens, because the same method is called on EACH start tag and similarly for the end tag and the PCDATA. You have to create the objects and put them into your own data structure - it's very tedious, but you have complete control. (Well, more or less.)
    2) "Tree" (e.g. DOM in JAXP, or it's better cousin JDOM): You call a parser that in one swoop creates an entire hierarchy that corresponds to the XML document. You don't get called on each tag as with SAX, you just get the root of the resulting tree. Drawback: All the nodes in the tree have the same type! You probably want to know which tags are in the document, don't you? Well, you'll have to traverse the tree and ask each node: What tag do you represent? And what are your attributes? (You get only strings in response even though your attributes often represent numbers.) Unless you want to display the tree - that's a nice application, you can do it as a tree model for JTree -, or otherwise don't care about the individual tags, DOM is not of much help, because you have to keep track where in the tree you are while you traverse it.
    3) Enter JAXB (or Castor, or ...): You give it a grammar of the XML documents you want to parse, or "unmarshall" as the fashion dictates to call it. (Actually the name isn't that bad, because "parsing" focuses on the input text while "unmarshalling" focuses on the objects you get, even though I'd reason that it should be marshalling that converts into objects and unmarshalling that converts objects to something else, and not vice versa but that's just my opinion.) The JAXB compiler creates a bunch of source files each with one (or now more) class(es) (and now interfaces) that correspond to the elements/tags of your grammar. (Now "compiler" is a true jevel of a misnomer, try to explain to students that after they run the "compiler", they still need to compile the sources the "compiler" generated with the real Java compiler!). Ok, you've got these sources compiled. Now you call one single method, unmarshall() and as a result you get the root node of the hierarchy that corresponds to the XML document. Sounds like DOM, but it's much better - the objects in the resulting tree don't have all the same type, but their type depends on the tag they represent. E.g if there is the tag <ball-game> then there will be an object of type myPackage.BallGame in your data structure. It gets better, if there is <score> inside <ball-game> and you have an object ballGame (of type BallGame) that you can simply call ballGame.getScore() and you get an object of type myPackage.Score. In other words, the child tags become properties of the parent object. Even better, the attributes become properties, too, so as far as your program is concerned there is no difference whether the property value was originally a tag or an attribute. On top of that, you can tell in your schema that the property has an int value - or another primitive type (that's like that in 1.0, in the early release you'll have to do it in the additional xjs file). So this is a very natural way to explore the data structure of the XML document. Of course there are drawbacks, but they are minor: daunting complexity and, as a consequence, very steep learning curve, documentation that leaves much to reader's phantasy - read trial and error - (the user's guide is too simplicistic and the examples too primitive, e.g. they don't even tell you how to make a schema where a tag has only attributes) and reference manual that has ~200 pages full of technicalities and you have to look with magnifying glas for the really usefull stuff, huge number of generated classes, some of which you may not need at all (and in 1.0 the number has doubled because each class has an accompanying interface), etc., etc. But overall, all that pales compared to the drastically improved efficiency of the programmer's efforts, i.e. your time. The time you'll spend learning the intricacies is well spent, you'll learn it once and then it will shorten your programming time all the time you use it. It's like C and Java, Java is order of magnitude more complex, but you'd probably never be sorry you gave up C.
    Of course the above essay leaves out lots and lots of detail, but I think that it touches the most important points.
    A word about JAXB 1.0 vs. Early Release (EA) version. If you have time, definitively learn 1.0, they are quite different and the main advantage is that the schema combines all the info that you had to formulate in the DTD and in the xjs file when using the EA version. I suggested EA was because you had a DTD already, but in retrospect, you better start from scratch with 1.0. The concepts in 1.0 are here to stay and once your surmounted the learning curve, you'll be glad that you don't have to switch concepts.
    When parser job is done,
    what kind of Java Object we will get? (String,
    InputStream or ...)See above, typically it's an object whose type is defined as a class (and interface in 1.0) within the sources that JABX generates. Or it can be a String or one of the primitive types - you tell the "compiler" in the schema (xjs file in EA) what you want!
    2. If we want to use JAXB, we have to contain a
    XJS-file? Something like:In EA, yes. In 1.0 no - it's all in the schema.
    I am very new to XML, is there any simpler way to get
    around them? It has already take me 4 days to find a
    simple parser which give it XML and DTD, then return
    to me Java objects ... I mean if that kind of parser
    exists....It'll take you probably magnitude longer that that to get really familiar with JAXB, but believe me it's worth it. You'll save countless days if not weeks once you'll start developing serious software with it. How long did it take you to learn Java and it's main APIs? You'll either invest the time learning how to use the software others have written, or you invest it writing it yourself. I'll take the former any time. But it's only my opinion...
    Jan

  • Create java objects from xml

    I want to create a tree structure for java object. These java objects are populated after the parsing the xml. But what could be the logic for adding child to parent when there are
    many sub nodes? I wanted to use one recursive function which iterate through all the elements of the xml file. But I have not got the idea how to add one child object to parent object.
    following are my classes. Any help on this highly appreciated.
    public class TreeObject {
              private String name;
              private TreeParent parent;
              public TreeObject(String name) {
                   this.name = name;
              public String getName() {
                   return name;
              public void setParent(TreeParent parent) {
                   this.parent = parent;
              public TreeParent getParent() {
                   return parent;
              public String toString() {
                   return getName();
    import java.util.ArrayList;
    public class TreeParent extends TreeObject {
         private TreeObject treeObject ;
              private ArrayList children;
              public TreeParent(String name) {
                   super(name);
                   children = new ArrayList();
              public void addChild(TreeObject child) {
                   children.add(child);
                   child.setParent(this);
                   treeObject = child ;
              public void removeChild(TreeObject child) {
                   children.remove(child);
                   child.setParent(null);
              public TreeObject [] getChildren() {
                   return (TreeObject [])children.toArray(new TreeObject[children.size()]);
              public boolean hasChildren() {
                   return children.size()>0;
              public TreeObject getChild(){
                   return treeObject;
    private TreeParent getChilderen(Element rootNode){
         List list = rootNode.getChildren();
         String rootNodeName = rootNode.getName();
         TreeParent root = new TreeParent(rootNodeName);
         for (int i=0; i< list.size(); i++)
    Element node = (Element) list.get(i);
    if(node.getChildren().size() > 0){
         // TreeParent treeParent = new TreeParent(node.getText());
         TreeParent treesub = new TreeParent(node.getText());
         treesub.addChild(treesub);
         //TreeParent p = treeParent.getParent();
         // rootParent.addChild(treeParent);
    }else{
         TreeObject object = new TreeObject(node.getText());
         root.addChild(object);
    getChilderen(node);
         return root ;
    public TreeParent buildTree(String filePath) {
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(filePath);
    try{
    Document document = (Document) builder.build(xmlFile);
    Element rootNode = document.getRootElement();
    // List list = rootNode.getChildren("staff");
    TreeParent rootParent = getChilderen(rootNode);
    return rootParent ;
    }catch(IOException io){
    System.out.println(io.getMessage());
    }catch(JDOMException jdomex){
    System.out.println(jdomex.getMessage());
    return null;
    Edited by: 870611 on Jul 6, 2011 6:27 AM

    Hi
    I recommend you use the API JAXB. Is much simpler.
    here a link: http://www.oracle.com/technetwork/articles/javase/index-140168.html
    here a example: http://download.oracle.com/javaee/5/tutorial/doc/bnbay.html#bnbbc

  • Newbie question on how to return java objects from java stored procedures

    Hi,
    As you may guess, i'm new to this.
    I have a stored procedure that does some calculations and creates a list of java objects as the result of the query.
    How would I return the list from the database to the client application?
    Would I have to create an Oracle type that maps to the java object?
    Please help.
    Jag

    Hi Jag,
    Your question is very vague (to me). Perhaps you could post what you have done so far? Have you tried looking through the Sample Code page of the Technet Web site, or tried searching the Ask tom Web site, or MetaLink?
    Good Luck,
    Avi.

  • Tool to create Java Object classes using the Database Tables

    Hi,
    Is their any tools or utility available to create the Java Object Classes using the Database Tables as input.
    Lets Say I am having the Employee, Employee_Salary tables in the Database.The utility has to create the Java Object classes with the relation.
    Please Help...
    Thx..

    Hm, for generating regular Java classes I wouldn't know one from memory. But I suggest you start searching in for example the Eclipse marketspace for a third party plugin that can do it. If all fail, you could always use Hibernate Tools from the Jboss Tools Eclipse plugin set to generate Hibernate/JPA entities and then strip the annotations from them to turn them into regular POJO classes.
    How many tables are we talking about anyway? It might be less effort to just create the classes with properties and then use an IDE to generate getters and setters for them.

Maybe you are looking for

  • View iCal's day and week view in reverse chronological order

    Greetings iCalers, When I think about day/week calendars, with the Y-axis being times of the day as in iCal's day/week views (e.g. "3:00 AM", and "5:00 PM" are in the leftmost column), I think about times building up to midnight from the bottom-i.e.

  • Copy and paste pictures from preview to ebay problem

    Hi. I am creating adverts on eBay with my macbook and when I copy and paste a picture from preview, into the body of the advert it works fine and displays fine. I then save the advert and go to view it on my mac and all displays ok. However my proble

  • Where can I access / download an iPhoto version to run on a G3 iMac?

    My parents run OS 9.2 on an old blue G3 iMac - great machine, but not upgradeable to X. They have a large number of old family photos which I have been scanning for them. Is there an available iPhoto version which I can access for them to run their s

  • Input Tax code

    Hello How to define Input tax code for I/P ED 5.15% & CST2% regards

  • To, CC, Reply to headers are grayed out in Mail message

    Hi All, I recently moved from SL to ML. Not everything was smooth, most probably because i'm using low level features/configurations, but that's ok. I noticed that some of my mail messages headers are light gray, while other are black as they should