LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2009, 05:26 PM   #1
CoderMan
Member
 
Registered: Jan 2009
Location: Gemini Capsule 25164
Distribution: Gentoo
Posts: 375
Blog Entries: 24

Rep: Reputation: 43
Question Java Noob: How to draw my PNG?


I need to create a Java applet (1.5) and I have almost no idea what I'm doing. I found a tutorial that described how to draw lines and squares, but how do I draw a PNG image? I tried looking at the Java 5 API but I couldn't even figure out how to properly get the image into an image object...

Here's all I have so far:

Code:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;

//No need to extend JApplet, since we don't add any components;
//we just paint.
public class Simple extends Applet {

    StringBuffer buffer;

    public void init() {
    }

    public void start() {
       paint();
    }

    public void stop() {
    }

    public void destroy() {
    }

    public void paint(Graphics g) {
	Image img = ??? PNG from http://example.com/example.png ???

	g.drawImage(img, 20, 20, ???);
    }
}
 
Old 12-22-2009, 07:25 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
Image.createImage( "http://example.com/example.png" );
LOL You seem to know all languages.
 
Old 12-22-2009, 07:28 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I haven't done Java in a long time, but this may help:

Code:
import java.swing.ImageIcon;
Image img = new ImageIcon(new URL("http://example.com/example.png")).getImage();
g.drawImage(img, 20, 20, NULL);
 
Old 12-22-2009, 07:43 PM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
ImageMagick ( http://imagemagick.com/script/index.php ) has Java bindings.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with PNG image in Java on Redhat Shariq Mustaquim Linux - Software 2 06-24-2005 06:37 AM
Java: how can I draw individual pixels? johnMG Programming 2 06-05-2005 09:03 PM
Webalizer: configure: error: png library not found... please install png. mikeshn Linux - Software 5 01-10-2005 02:28 PM
how to show phtos(.jpg,.png etc) using java pranith Programming 1 01-08-2005 12:04 PM
Where is trashcan_full/empty.png and kmenu.png??? d33pdream Linux - General 2 02-25-2003 11:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration