如何在Silverlight中将图像转换为Byte []? [英] How to convert image to Byte[] in Silverlight?

查看:98
本文介绍了如何在Silverlight中将图像转换为Byte []?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我应该在我的项目中读取类型为png的图像.我有一个名为"Images"的文件夹.我将图像放到该文件夹​​中.我可以读取此图像,但不能将其转换为字节[].

我有一个对象,该对象具有一个名为"Image"的属性,并且此属性的类型为byte [].我应该读取读取的图像并将该图像设置为对象的Image属性.在网上探索了很长时间后,我尝试了此方法.如何在 Silverlight 中将图像转换为byte []?我找不到能解决我问题的解决方案.

谢谢您的提前答复..

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 ..

推荐答案

创建字节数组并指定从中读取字节的文件非常简单
您需要导入System.IO

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

祝你好运........
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........


Mantu,
感谢您的答复.
当我为路径桌面设置图像时,它可以工作.
但是在项目中,我应该具有读取项目中图像的项目路径.

我尝试了我找到的解决方案,例如:

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();



但是所有这些代码块都显示了桌面"C:\ Users \ MyUser".

如何在Silverlight中获取projet目录?
感谢您的提前答复.



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..


这篇关于如何在Silverlight中将图像转换为Byte []?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆