Re: Getting images into byte arrays
From: MarkR (mark_at_bogus.yahoo.com)
Date: 02/16/05
- Next message: Robbe Morris [C# MVP]: "Re: Getting images into byte arrays"
- Previous message: MarkR: "Image Scaling-Up when Printing to PostScript"
- In reply to: RichardF: "Getting images into byte arrays"
- Next in thread: Robbe Morris [C# MVP]: "Re: Getting images into byte arrays"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 16 Feb 2005 23:30:41 GMT
I think you should try the Image.LockBits() function to access the image
contents, rather than reading back from a stream. This site is for C#, but
the algorithm should be apparent -- essentially, you call LockBits for a
portion of the image, then walk the BitmapData array.
http://www.codeproject.com/cs/media/csharpgraphicfilters11.asp
If you insist on reading from the stream, I suspect you need to find a way
to flush the stream. I'm not directly familiar with the function, but maybe
there's a Stream.Flush() or Stream.Close() function that will ensure your
StreamReader has the latest version...
Good luck,
/m
"RichardF" <noone@nowhere.com> wrote in message
news:ibk7119m9pgvg5g1kksas9cqdd8d1ighek@4ax.com...
> Can anyone tell me what is wrong with this code?
>
> I want to get the ocntents of the JPEG image into a byte array. After
> the theStream.read call, the theBytes array is still filled with all
> nulls. and iCount is zero.
>
> I used this article
> (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiomemorystreamclasstopic.asp)
> as a starting point.
>
> Eventually, what I want to have a function that will read an image
> from disk in any format (BMP, TIF, JPG etc), convert it to some other
> format, and then return it in a Byte array
>
>
> Thanks for any help
>
> RichardF
>
>
>
> Imports System
> Imports System.IO
> Imports System.Text
> Imports System.Drawing
>
> Module Module1
>
> Sub Main()
>
> Dim theImage As Image
> Dim theStream As New MemoryStream
> Dim theBytes As Byte()
> Dim iCount As Integer
>
> Try
> theImage = Image.FromFile("C:\Images\Test.jpg")
> theImage.Save(theStream, Imaging.ImageFormat.Jpeg)
> theBytes = New Byte(theStream.Length - 1) {}
> iCount = theStream.Read(theBytes, 0, theStream.Length - 1)
> Catch ex As Exception
> End Try
>
> End Sub
>
> End Module
- Next message: Robbe Morris [C# MVP]: "Re: Getting images into byte arrays"
- Previous message: MarkR: "Image Scaling-Up when Printing to PostScript"
- In reply to: RichardF: "Getting images into byte arrays"
- Next in thread: Robbe Morris [C# MVP]: "Re: Getting images into byte arrays"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|