|
Vivek Vijayan wrote: value does not fall within expected range
There can be two reasons, either that btye array is not a valid bitmap or your device cannot decode the image.
|
|
|
|
|
how can can i load an image from a file in to a picture box in mobile application (not using filedialog)
This code was posted by me...
|
|
|
|
|
What kind of byte array is it? Raw pixels or a complete image with header and all?
|
|
|
|
|
sry i din undrstd ur question
i m giving the code code and i m getting just "Exception".i cant understand wht exception is it.sometimes i m getting outofmemory exception.the line that throws exception is
pictureBox1.Image = new Bitmap(File.Open("\\Program Files\\syswifi\\pic\\screen.Bmp",FileMode.Open,FileAccess.Read));
this line raises another exception too "the process cannot access the files \Program Files\\syswifi\\pic\\screen.jpg because it is used been used by another process"
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
try
{
FileStream fs = new FileStream("\\Program Files\\syswifi\\pic\\screen.Bmp", FileMode.Create);
ms.WriteTo(fs);
fs.Close();
ms.Flush();
ms.Close();
pictureBox1.Image = new Bitmap(File.Open("\\Program Files\\syswifi\\pic\\screen.Bmp",FileMode.Open,FileAccess.Read)) ;
}
catch(Exception ex)
{
MessageBox.Show("Failed to display" + ex.Message);
}
how can can i load an image in to a picture box
in mobile application
This code was posted by me...
|
|
|
|
|
My question is actually very important, if your data is "just pixels" then saving it in a BMP file will just give an invalid BMP file - when the Bitmap importer then tries to read it, it will read the width and height but they would be colors instead of the width and height and they will probably be very big, then it will try to allocate too much memory because it thinks the picture is that big (when of course it really isn't).
So what is your data? Is it pixels? Or do you have a proper image header in there? If so, of what type?
|
|
|
|
|
my application is like this:
windows appliaction send the image as bytes and the mobile device receives the bytes and then i send it to a memory stream and convert it back to picture.. i want to get image from that received byte array or memory stream.i m new to this mobile application development. so i still cant differentiate raw pixel or complete image.
This code was posted by me...
|
|
|
|
|
How does it send the image as bytes?
|
|
|
|
|
i convert the image to bytes and send using socket.send()
This code was posted by me...
|
|
|
|
|
Vivek Vijayan wrote: convert the image to bytes
Well that is the most important part - How do you convert it?
|
|
|
|
|
here is the code
Bitmap bmp = new Bitmap("D:\\screen.Bmp");
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] size = ms.ToArray();
sockt.Send(size);
This code was posted by me...
|
|
|
|
|
and the receiving part code is
byte[] data = new byte[1024];
data=receivefile();
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
try
{
FileStream fs = new FileStream("\\Program Files\\syswifi\\pic\\screen.Bmp", FileMode.Create);
ms.WriteTo(fs);
ms.Flush();
fs.Close();
ms.Close();
i m getting "exception in this code"
pictureBox1.Image = new Bitmap("\\Program Files\\pic\\screen.Bmp");
}
catch(Exception ex)
{
MessageBox.Show("Failed to display" + ex.Message.ToString());
}
i getting "Exception" in the last line
it is not telling what is the exception its displaying just "Exception"
This code was posted by me...
|
|
|
|
|
when i run applicn when it reaches this line "picturebox1.image=new Bitmap("\\Program Files\\pic\\screen.Bmp")" is null
This code was posted by me...
|
|
|
|
|
Maybe it's bigger than 1024 bytes?
Also, why do you use the memorystream .. for nothing? You could write the array directly to the stream (or if File.WriteAllBytes is available, that's even easier)
|
|
|
|
|
how do i get byte array from the an image with out using memory stream
This code was posted by me...
|
|
|
|
|
Scanning the pixels, but I was referring to the receiving code, which doesn't use the memory stream for anything other than the WriteTo method
|
|
|
|
|
what is the other way...but i m not able to open the image using the code
pictureBox1.Image =new Bitmap("\\Program Files\\pic\\screen.Bmp");
and
pictureBox1.Image =File.Open("\\Program Files\\pic\\screen.Bmp", FileMode.Open, FileAccess.Read));its raising exception "Exception"
This code was posted by me...
|
|
|
|
|
Well if you have that filestream you can just fs.Write(buffer, 0, 1024)
Assigning a stream to the Image property should not even compile though
|
|
|
|
|
i m getting exception when i load to picture box
This code was posted by me...
|
|
|
|
|
Are you sure? Maybe you are getting it when you load the bitmap? You'd have to put it on 2 lines to know that.
|
|
|
|
|
exception "Exception" is caught on loading the image. why it is happening??
and wht type of exception is this
This code was posted by me...
|
|
|
|
|
sorry the exception is not cought on loading its in ht eline
picturebox1.image=new Bitmap(fs)
where fs is file stream
This code was posted by me...
|
|
|
|
|
NullReferenceException is caught in the line
fs=File.Open("\\Program Files\\pic\\screen.Bmp", FileMode.Open, FileAccess.Read);
pictureBox1.Image =new Bitmap(fs);
This code was posted by me...
|
|
|
|
|
So.. fs is null? AFAIK that can never happen, it would have to give an other exception as detailed here: File.Open on MSDN[^]
I don't know what else?
|
|
|
|
|
i don knwo wht is happening,The file is created. that i can see when when i browse the folder. but null reference exception is shown when i run applcn.
This code was posted by me...
|
|
|
|
|
Is the file ok? does it open in, say, paint without error?
|
|
|
|