Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:46:05+00:00 2026-06-17T04:46:05+00:00

Possible Duplicate: Convert a Graphics2D to an Image or BufferedImage Sorry. This is a

  • 0

Possible Duplicate:
Convert a Graphics2D to an Image or BufferedImage

Sorry. This is a very basic question. But I am very new to this platform. I am drawing a line using graphics2d draw function. I want to save this as an image into my system. I googled it out and found out that BufferedImage class is useful in doing this and then use imagedraw function.

But I could not figure out how exactly use it in my code. Can any one please help me?

Here is my code.

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class DrawAndSaveImage extends JApplet {
    public void init() {
        setBackground(Color.lightGray);
    }

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setPaint(Color.black);
    g2d.draw(new Line2D.Double(50,150,150,150 ));

}

public static void main(String s[]) {
    JFrame frame = new JFrame("sample image");
    JApplet applet = new DrawAndSaveImage();
    frame.getContentPane().add("Center", applet);
    applet.init();
    frame.setSize(200, 200);
    frame.show();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:46:06+00:00Added an answer on June 17, 2026 at 4:46 am
    1. JFrame and main are not supposed to be used in an applet, unless you try to create hybrid application.

    2. Don’t override paint() method

    3. Use SwingUtilities.invokeLater() to create GUI

    4. Applet is not allowed to write/read from external files, unless it is signed

    5. ImageIO.write() can write an image to file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Convert NSDate to NSString convert string to nsdate Currently I have this
Possible Duplicate: Convert this string to datetime I have to convert my string value
Possible Duplicate: Convert date to another timezone in javascript How to make this program
Possible Duplicate: Convert string to DateTime in c# A question I got a string
Possible Duplicate: Convert a Stream to a FileStream in C# My question is regarding
Possible Duplicate: convert object to array Let's say I have an array like this:
Possible Duplicate: Convert ascii to int ?? int a=53 This is an ASCII value
Possible Duplicate: Convert numeral date(03-11-1991) into arabic no(۱۹۹۱/۱۱/۰۳) php This is my client's requirement.
Possible Duplicate: Convert list of tuples to list? I have a list like this
Possible Duplicate: Convert array of strings to List<string> I am new to C# How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.