Java for ImageProcessing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fred Ho
    New Member
    • Oct 2007
    • 18

    #1

    Java for ImageProcessing

    Dear Sir/Madam,

    I try to make a function for image processing using java, I have add a menu item "Add Icon" under the menu bar. The function should read a file Icon.gif and place the icon at the top left hand corner of the image.
    The following code is what I tried to do ...

    after checking the user whether to select 'add icon',
    if (s == "Add Icon") {
    mBufferedImage = processor.AddIc on(mBufferedIma ge);

    }

    then it will run the class AddIcon as below...

    public BufferedImage AddIcon (BufferedImage inputImage) {
    BufferedImage icon = null;
    Graphics g = inputImage.getG raphics();
    g.drawImage(ico n, 0,0, null);
    return mBufferedImage;
    }

    I am just a beginner for the java programming and hope that someone can teach me:
    1.how to ask the user to input the second image to place at the corner and
    2.how to amend the class AddIcon to make it really work.
    Thanks a lot for your kindly help!
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Originally posted by Fred Ho
    Dear Sir/Madam,

    I try to make a function for image processing using java, I have add a menu item "Add Icon" under the menu bar. The function should read a file Icon.gif and place the icon at the top left hand corner of the image.
    The following code is what I tried to do ...

    after checking the user whether to select 'add icon',
    if (s == "Add Icon") {
    mBufferedImage = processor.AddIc on(mBufferedIma ge);

    }

    then it will run the class AddIcon as below...

    public BufferedImage AddIcon (BufferedImage inputImage) {
    BufferedImage icon = null;
    Graphics g = inputImage.getG raphics();
    g.drawImage(ico n, 0,0, null);
    return mBufferedImage;
    }

    I am just a beginner for the java programming and hope that someone can teach me:
    1.how to ask the user to input the second image to place at the corner and
    2.how to amend the class AddIcon to make it really work.
    Thanks a lot for your kindly help!
    If you are a beginner at programming, I wouldn't suggest jumping into Swing. Learn the basics first. For example, don't use == to compare strings, use equals:
    [CODE=Java]if (s.equals("Add Icon"))[/CODE]

    I'm also wondering why your AddIcon method both takes and returns a BufferedImage -- isn;t it going to be a reference to the same object?
    [CODE=Java]mBufferedImage = processor.AddIc on(mBufferedIma ge);[/CODE]
    As for your questions: how to ask the user to input a file: use JFileChooser:
    This Swing Java Tutorial describes developing graphical user interfaces (GUIs) for applications and applets using Swing components

    You second question "how to make it work?" is too vague to answer. Please be more specific.

    Comment

    Working...