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 6920793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:11:37+00:00 2026-05-27T10:11:37+00:00

I really confused how to send an Image data type via socket. Please help

  • 0

I really confused how to send an Image data type via socket. Please help me. I’ve searced how to convert Image data type to char[] but the result was 0.

  • 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-05-27T10:11:38+00:00Added an answer on May 27, 2026 at 10:11 am

    You can convert Image to BufferedImage with this method (source):

    public BufferedImage toBufferedImage(final Image image, final int type) {
        //Test if image does not need conversion
        if (image instanceof BufferedImage)
            return (BufferedImage) image;
        //Check if image can be converted easily
        if (image instanceof VolatileImage)
            return ((VolatileImage) image).getSnapshot();
        //loadImage method ensures that the image has loaded fully (it could be from the web or something). If you are sure that when this method is called - the image is loaded, you can remove this line and whole method.
        loadImage(image);
        //Create new BufferedImage with the same width and height and given data type (see constants in BufferedImage API)
        final BufferedImage buffImg = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
        //Get graphics out of our new BufferedImage. Graphics2D is used to draw something on the image
        final Graphics2D g2 = buffImg.createGraphics();
        //Use Graphics2D to draw our Image contents on top of BufferedImage
        g2.drawImage(image, null, null);
        //We no longer need our graphics object as we drawn everything we wanted
        g2.dispose();
        //Return BufferedImage
        return buffImg;
    }
    
    //Method that ensures that the image was loaded succesfully
    private void loadImage(final Image image) {
        //Inner class implementing the ImageObserver interface. It will be used to track the image loading progress
        class StatusObserver implements ImageObserver {
            boolean imageLoaded = false;
                //Each time an image updates - it will call this method
            public boolean imageUpdate(final Image img, final int infoflags, 
                  final int x, final int y, final int width, final int height) {
                        //When flags contains ALLBITS flag - that means that the image was fully loaded.
                if (infoflags == ALLBITS) {
                    synchronized (this) {
                                        //Therefore we set status to true
                        imageLoaded = true;
                                        //And notify anyone who was waiting for our job to be done
                        notify();
                    }
                    return true;
                }
                return false;
            }
        }
        //Then we create the observer itself
        final StatusObserver imageStatus = new StatusObserver();
        //We aquire it's monitor with this synchronized block. This will allow us to "wait" for it to complete loading (see notify() in StatusObserver)
        synchronized (imageStatus) {
                //Basically if image is loaded - it will have it's width and height set
            if (image.getWidth(imageStatus) == -1 || image.getHeight(imageStatus) == -1) {
                        //While status observer is not loaded
                while (!imageStatus.imageLoaded) {
                    try {
                                        //We wait for status observer to notify us
                        imageStatus.wait();
                    } catch (InterruptedException ex) {}
                }
            }
        }
    }
    

    Then, you can write the resulting BufferedImage with ImageIO.write() method.

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

Sidebar

Related Questions

Okay i have seen TouchXML, parseXML, NSXMLDocument, NSXMLParser but i am really confused with
I'm trying to send a HTTP request to a servers interface. But I'm really
I'm really confused about this, but when I'm trigging a thread from my SurfaceView,
I am really confused about object relationships! I have two classes Person and Address.
I'm really confused by a behaviour of LINQ I'm seeing and it's causing me
I am really confused now on how and which method to use to return
I'm really confused about the visitor pattern and its uses. I can't really seem
I'm at a point where I'm really confused about how to go about handling
I'm new to the entity framework and I'm really confused about how savechanges works.
I am bringing out a separate question from here . It really confused me.

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.