-
Painting images in an application
"Puneet Wadhwa" <puneet_tech@yahoo.com> wrote:
>
>...Whereas in case of application we can't
>access methods such as getDocumentBase ...
If you add a canvas component where you want the image, you can paint the
image with the canvas' paint() method. To fetch the image, try something
like the following:
import java.awt.image.*;
import java.net.*;
import java.io.*;
class MyClass{
Image image = null;
...
public void fetchImage(String imageName){
//the parameter imageName might be something like
//"file:/C:\\myDir\\...\\myPicture.gif"
URL url = null;
try{
url = new URL(imageName);
}
catch(MalformedURLException murle){
System.out.println("Cannot find image " + imageName);
return;
}
try{
image = createImage((ImageProducer)url.getContent());
}
catch(IOException ioe){
System.out.println("Unable to fetch image " + url);
return;
}
}//fetchImage
...
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks