How to get a picture into a byte array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I'm trying to get a picture uploaded to the picture attribute in Active Directory. I've got most of it working, the only thing I need now, is to convert this picture to a byte array, so that I can save it in the AD

Does anyone know how to do this

Thank you VERY much in advance

Rasmus
 
Hi Rasmus,

Try this

Dim ms As New MemoryStream
Dim arrImage() As Byte
originalImage.Save(ms, ImageFormat.Jpeg)
arrImage = ms.GetBuffer

I thought ImageFormat.Bmp is better but I needed this for something extra

I hope this helps,

Cor
 
* "=?Utf-8?B?UmFzbXVzIFRlZ2xnYWFyZA==?= said:
I'm trying to get a picture uploaded to the picture attribute in
Active Directory. I've got most of it working, the only thing I need
now, is to convert this picture to a byte array, so that I can save it
in the AD.

I am not familiar with AD, but that do you want to say with "uploaded to
the picture attribute"? In what format does the picture get uploaded?
 
Hi Cor

Your my man! It worked - apparently

The reason for the "apparently" is that, I get no errors (which is usually a good thing :0)
The thing is, that I am not able see if this worked, before I can get the binary data back from the active directory and convert them back to an image and display it

So, I was wondering if you (or others) could help me with this - to get the binary data back and convert them back to the picture again

I can't express how much help you've been, thanks again

Rasmu


----- Cor wrote: ----

Hi Rasmus

Try thi

Dim ms As New MemoryStrea
Dim arrImage() As Byt
originalImage.Save(ms, ImageFormat.Jpeg
arrImage = ms.GetBuffe

I thought ImageFormat.Bmp is better but I needed this for something extr

I hope this helps

Co
 
It should be uploaded in a byte array (binary).

Rasmus

----- Herfried K. Wagner [MVP] wrote: -----

* "=?Utf-8?B?UmFzbXVzIFRlZ2xnYWFyZA==?= said:
I'm trying to get a picture uploaded to the picture attribute in
Active Directory. I've got most of it working, the only thing I need
now, is to convert this picture to a byte array, so that I can save it
in the AD.

I am not familiar with AD, but that do you want to say with "uploaded to
the picture attribute"? In what format does the picture get uploaded?
 
* "=?Utf-8?B?UmFzbXVzIFRlZ2xnYWFyZA==?= said:
It should be uploaded in a byte array (binary).

\\\
Dim fs As FileStream = New FileStream( _
"C:\WINDOWS\Angler.bmp", _
FileMode.Open _
)
Dim br As BinaryReader = New BinaryReader(fs)
Dim abyt() As Byte = br.ReadBytes(fs.Length)
br.Close()
///
 
Hi Herfried,

Thank you very much for your apply.
I've already gotten a solution from Cor though, and I've tried that, and it appears to be working. In this case, I'm using a memorystream rather than the filestream.

I've got one last question though.
I've now managed to get the picture into the active directory (I think). Now I need to get it back. So now it's the other way around.

How do I make a byte array to a memorystream, that I can then import to a picturebox in VB?

Thanks in advance,
Rasmus

----- Herfried K. Wagner [MVP] wrote: -----

* "=?Utf-8?B?UmFzbXVzIFRlZ2xnYWFyZA==?= said:
It should be uploaded in a byte array (binary).

\\ Dim fs As FileStream = New FileStream( _
"C:\WINDOWS\Angler.bmp", _
FileMode.Open _
)
Dim br As BinaryReader = New BinaryReader(fs)
Dim abyt() As Byte = br.ReadBytes(fs.Length)
br.Close()
///
 
* "=?Utf-8?B?UmFzbXVzIFRlZ2xnYWFyZA==?= said:
How do I make a byte array to a memorystream, that I can then import to a picturebox in VB?

\\\
Dim ms As New MemoryStream(abyt)
Dim img as Image = Image.FromStream(ms)
///

Keep the 'MemoryStream' alive as long as you use the image.
 
Back
Top