簡體   English   中英

MemoryStream到sbyte []

[英]MemoryStream to sbyte[]

我仍在嘗試使用Novell的c#庫將jpeg圖像添加到Open LDAP中的人:

Openldap:將jpegPhoto添加到inetOrgPerson

有一個Novell.Directory.Ldap.LdapAttribute的構造函數,帶有以下簽名:

public LdapAttribute(string attrName, sbyte[] attrBytes)

因此,我計划使用此。 但是,如何將jpeg圖像從MemoreyStream轉換為sbyte []?

MemoryStream.ToArray() 

方法返回byte [],但我不知道該怎么做。

您可以像這樣轉換數組:

Array.ConvertAll(bytes, b => (sbyte)b)

在CLR上,您可以恆定時間將byte[]轉換為sbyte[] 請參閱我以前關於這個鮮為人知的技巧的答案。

(sbyte[])(object)MemoryStream.ToArray(); //compiles and runs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM