Image from memory

D

DotNetJunkies User

i am using a dll that places an image data in memory and returns to me two wariable long P1 and long P2
i am using C#
P1 is the memory address and P2 is the number of bytes written
i want to place this image in a picturebox named pictureBox1 how can i do this

in c++ the code works like this
stream.write((void*) P1,P2);
its equavalent in C# should be
Stream str = new MemoryStream()
str.Write((void*) P1,0,P2);
pictureBox1.Image = Image.FromStream(str);

or
Stream str = new MemoryStream((void*) P1,0,P2)
pictureBox1.Image = Image.FromStream(str);

my problem P1 is pointer and str.Write function takes a byte array . how can i take the data at P1 and convert it to byte array or from an image from it.
 
S

Shakir Hussain

Try this

//include namespace
using System.Runtime.InteropServices ;
using System.Text;


string str = Marshal.PtrToStringAuto(P1);
UnicodeEncoding encod = new UnicodeEncoding();
byte [] imageBytes = encod.GetBytes(str);

Stream myStream = new MemoryStream(imageBytes);
Image myImage = Image.FromStream(stream);

pictureBox1.Image = myImage;

--
Shak
(Houston)




DotNetJunkies User said:
i am using a dll that places an image data in memory and returns to me two wariable long P1 and long P2
i am using C#
P1 is the memory address and P2 is the number of bytes written
i want to place this image in a picturebox named pictureBox1 how can i do this

in c++ the code works like this
stream.write((void*) P1,P2);
its equavalent in C# should be
Stream str = new MemoryStream()
str.Write((void*) P1,0,P2);
pictureBox1.Image = Image.FromStream(str);

or
Stream str = new MemoryStream((void*) P1,0,P2)
pictureBox1.Image = Image.FromStream(str);

my problem P1 is pointer and str.Write function takes a byte array . how
can i take the data at P1 and convert it to byte array or from an image from
it.engine supports Post Alerts, Ratings, and Searching.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top