Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I should read an image which type is png in my project. I have a folder named "Images". I put my image to this folder. I can read this image but can not convert it to byte [] .

I have an object which have a property named "Image" , and type of this property is byte[] . I should take the image which is read and set this image to my objects's Image property. I tried this after exploring this issue a long time at net. How can ı convert the image to byte[] in Silverlight ? I couldn't find a solution which can solve my problem.

Thanks for your replies in advance ..
Posted

It's quite simple create a byte array and specify the file from which to read the bytes
you need to import System.IO

byte [] photodata=File.ReadAllBytes("C:\\img.png");

Best of luck........
 
Share this answer
 
Mantu,
Thanks for your reply.
When I set an image in for path desktop, it works.
But in project I should have the project path to read the image in the project.

I tried which I find as solutions like :

string s1 = Environment.CurrentDirectory;
string s2 = Path.GetDirectoryName(Application.Current.ToString());
string s3= System.IO.Directory.GetCurrentDirectory();


But all these code blocks shows the desktop "C:\Users\MyUser".

How can I take the projet directory in silverlight ?
Thanks for the replies in advance..
 
Share this answer
 
Comments
Mantu Singh 30-Apr-12 3:46am    
Welcome;
use following

string path=Application.ExecutablePath;
no_-_namee 30-Apr-12 9:01am    
I tried your suggestion but it doesn't resolve the ExecutablePath.
Sergey Alexandrovich Kryukov 15-Jul-14 10:52am    
Not an answer.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900