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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:15:54+00:00 2026-06-02T08:15:54+00:00

I know the image is valid because I can convert the IplImage to an

  • 0

I know the image is valid because I can convert the IplImage to an Image and even draw it on a JPanel. But when I convert a byte array to an Image most of the time I get null reference to an Image. Look at this code below to get a picture what I am facing with and comments, questions, answers are all welcome and even tips are all welcome.

            Image i = Convert.getImage(image);
            byte[] buffer  = Convert.getBytes(image);
            Image  i2 = Convert.getImage(buffer); 
            //i2 is a null reference and i is a valid image. i can be drawn but i2 is useless.

Convert class:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Security;

import com.googlecode.javacv.cpp.opencv_core.IplImage;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.ByteArrayInputStream;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;

/**
 *
 * @author danny
 */
public final class Convert
{

        public static Image getImage(IplImage image)
        {
                return image.getBufferedImage();
        }

        public static byte[] getBytes(IplImage image)
        {
                byte[] buffer;
                BufferedImage bI = image.getBufferedImage();
                buffer = ((DataBufferByte) (bI).getRaster().getDataBuffer()).getData();
                return buffer;
        }

        public static String getString(byte[] buffer)
        {
                return new String(buffer);
        }
        public static Image getImage(byte[] buffer)
        {
                try
                {

                        Image i = ImageIO.read(new ByteArrayInputStream(buffer));
                        return i;
                }
                catch (Exception e)
                {
                        System.out.printf("Exception Message:\n%s", e.getMessage() );
                        return null;
                }

        }
}

Now some of you may ask why do I need as a byte array. Well because I need to send across a network.

Extra Things To Be Aware Of:

  1. No exception is being thrown
  2. IplImage is a valid object

Update:

I have tried using the ToolKit class to create an image from a byte array. But it fails probably because it is not a JPEG or GIF. Although it does return a valid Image object the Image object is pointing to an image that is blank. Here is the code I was trying to use but failed to do so.

public static Image getImage(byte[] buffer)
{
        try
        {
                Toolkit  toolkit = Toolkit.getDefaultToolkit();
                Image i =  toolkit.createImage(buffer);
                return i;
        }
        catch (Exception e)
        {
                System.out.printf("Exception Message:\n%s", e.getMessage() );
                return null;
        }

}
  • 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-02T08:15:56+00:00Added an answer on June 2, 2026 at 8:15 am

    DataBufferByte.getData will: “Returns the default (first) byte data array.” The first bank that is. That seems an uncertain, incomplete way to get the bytes; especially on the way back. Besides there is the implementation dependent cast from DataBuffer to DataBufferByte.

    ImageIO can write to an OutputStream, for instance to a ByteArrayOutputStream, of which you can take the bytes. And on the other side ImageIO can read it in again. That is not the pure only-pixel-data you had in mind, but fool-proof.

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

Sidebar

Related Questions

I need to know can we add image in TextArea through StyleableTextField htmlText because
I'm trying to convert a byte[] to an image in C#. I know this
Does anyone know of an Image Map-like Blackberry Control that I can use in
Perhaps, you know that google image search by local image file .. But, Google
I know how to let user select an image from UIImagePickerController, but I don't
I know the code to make an image grow in size is: imageView.transform =
Anyone know how to retrieve the current image data (alt, src) via the changepicturecallback
Does anybody know how to force resize the image that opens in lightbox either
I would like to know how the recycle image link works, it points to
I want to know how to create an image column in a SQL Server

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.