The input that i have is a byte array containing bytes of an image
e.g.
byte[] byteData;
string fileName = @"C:\pic3.jp2";
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long numBytes = new FileInfo(fileName).Length;
byteData = br.ReadBytes((int)numBytes);
Now i have a control named j2k
and i want to use its function
j2k.OpenMemory() in order to get converted image in jp2 format
its parameters are
openmemory(ref byte src_byte,int src_length)
Now i have a byte array and the function wants me to send it a byte. How can i convert a bytearray into ref byte. I have tried using first element of byte array it got compiled but returned error in executing that line.
Loading
CrishPosted Dec 3, 2010, 4:20 AM
You can use also following code for Passing bytearray by ref in C#.you can refer this.
byte[] tmpArray = new byte[10];
for (int i = 0; i < 10; i++) { tmpArray[i] = (byte)i; }
Array ar = tmpArray;
myactivexControl.test2(ref ar);
Suthish NairPosted Dec 2, 2010, 4:48 AM
Hassan farrukhPosted Dec 2, 2010, 3:53 AM
Actually my problem is
string fileName = "rgb.jp2";
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long numBytes = new FileInfo(fileName).Length;
byteData = br.ReadBytes((int)numBytes); /// Now byteData contains image bytes info
//now if i use
codec.OpenFile("rgb.jp2"); /// Shows a file in control codec
///
//// but i want to do it by using memory as i am using all this in a live stream
/// i cant write all this in a file becuase it will consume time
//codec.OpenMemory is the function that will do it but i am unable to pass parameters in it
// It requires parametersvoid codec.OpenMemory (ref byte src_buff, int src_buff)
// While i only have a bytearray named byteData which holds bytes containing image info. I cant pass byte array as a reference i can only pass a single byte
I have also uploaded the source code.
ShankeyPosted Dec 2, 2010, 3:30 AM
I tried the following code and by default the byte array is passed by reference you can try following code.
namespace byteArray
{
class Program
{
static void Main(string[] args)
{
byte[] byteData;
string fileName = @"C:\pic3.jpeg";
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long numBytes = new FileInfo(fileName).Length;
byteData = br.ReadBytes((int)numBytes);
openMemory(byteData);
for (int i = 0; i < 10; i++)
{
Console.WriteLine("{0}:{1}", i, byteData[i]);
}
}
private static void openMemory(byte[] b)
{
for (int i = 0; i <10; i++)
{
Console.WriteLine("{0}:{1}", i, b[i]);
b[i]++;
}
}
}
}
And if i am not able to understand your problem clearly then plz provide some more details like the prototype of the openmemory function...