Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 9th, 2007, 10:30 AM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 7
Create and Save Image

Hello,

I need to create and save an image from my java code. Here is some code i have:-

Code:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;

public class CreateImage
{
	public static BufferedImage createImage(String fileName) throws IOException
	{
		BufferedImage image = new BufferedImage(100, 16, BufferedImage.TYPE_INT_RGB);

		Graphics2D g2d = image.createGraphics();
		g2d.setBackground(Color.red);
		g2d.drawString("abc",0,0);
		g2d.dispose();
		CreateImage.writeImage(image, fileName);
		return image;
	}

	public static void writeImage(BufferedImage image, String fileName) throws IOException
	{
		if (fileName == null) return;

		int offset = fileName.lastIndexOf( "." );
		String type = offset == -1 ? "jpg" : fileName.substring(offset + 1);

		ImageIO.write(image, type, new File( fileName ));
	}

	public static void main(String args[]) throws Exception
	{
		System.out.println("Creating region.jpg");
		CreateImage.createImage("region.jpg");
	}
}


This code creates and saves an image but its just black, whereas its supposed to have a red background and have abc written on it (see createImage method).

Any idea where i am going wrong?

Thanks
Neville

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Create and Save Image


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT