DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2004
    Location
    Puerto Rico
    Posts
    15

    Convert Images into a byte array.

    Hi,

    I need to know is there is a way to convert a Image into a array of bytes? I know a way using BufferedInputStream but that is loading a image from a file. I need to know a way to do it, if I already have an Image loaded in my class. Thanks in advance.

  2. #2
    Join Date
    Feb 2005
    Posts
    3
    you could probably turn the picture into an array of bytes by serializing it. Something like...

    public static byte[] serializeObj(Object obj) throws IOException
    {
    ByteArrayOutputStream baOStream = new ByteArrayOutputStream();
    ObjectOutputStream objOStream = new ObjectOutputStream(baOStream);

    objOStream.writeObject(obj); //object must be serializable
    objOStream.flush();
    objOStream.close();
    return baOStream.toByteArray(); //returns stream as byte array
    }

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia
    Posts
    1

    How to convert an image to a byte array in C#

    Image im = ...

    ImageConverter converter = new ImageConverter();
    Byte[] imageByteArray = (byte[]) converter.ConvertTo(im, typeof(byte[]));

  4. #4
    Join Date
    Feb 2009
    Posts
    1
    how to get coordinates of an image and convert into matrix or multidimensional array in array?

  5. #5
    Join Date
    Apr 2013
    Posts
    3
    following is image to byte array.
    Imports System.IO
    Imports System.Drawing.Printing
    Imports RasterEdge.Imaging
    Imports RasterEdge.Imaging.Processing
    Imports RasterEdge.Imaging.Converting.ImageToByte

    Dim Image As New RasterEdgeImaging()
    If True Then
    Dim image As New MemoryStream()
    ImageID.Save(image, System.Drawing.Imaging.ImageFormat.Jpeg)
    Return ms.ToArray()
    End If
    Image.save()

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links