本文整理汇总了C#中System.IO.MemoryStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.MemoryStream.Dispose方法的具体用法?C# System.IO.MemoryStream.Dispose怎么用?C# System.IO.MemoryStream.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了System.IO.MemoryStream.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnZipCompress
public static string UnZipCompress(this string value)
{
//Transform string into byte[]
byte[] byteArray = new byte[value.Length];
int indexBA = 0;
foreach (char item in value.ToCharArray())
{
byteArray[indexBA++] = (byte)item;
}
//Prepare for decompress
System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray);
System.IO.Compression.GZipStream sr = new System.IO.Compression.GZipStream(ms,
System.IO.Compression.CompressionMode.Decompress);
//Reset variable to collect uncompressed result
byteArray = new byte[byteArray.Length];
//Decompress
int rByte = sr.Read(byteArray, 0, byteArray.Length);
//Transform byte[] unzip data to string
System.Text.StringBuilder sB = new System.Text.StringBuilder(rByte);
//Read the number of bytes GZipStream red and do not a for each bytes in
//resultByteArray;
for (int i = 0; i < rByte; i++)
{
sB.Append((char)byteArray[i]);
}
sr.Close();
ms.Close();
sr.Dispose();
ms.Dispose();
return sB.ToString();
}
示例2: ZipCompress
public static string ZipCompress(this string value)
{
//Transform string into byte[]
byte[] byteArray = new byte[value.Length];
int indexBA = 0;
foreach (char item in value.ToCharArray())
{
byteArray[indexBA++] = (byte)item;
}
//Prepare for compress
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.Compression.GZipStream sw = new System.IO.Compression.GZipStream(ms,
System.IO.Compression.CompressionMode.Compress);
//Compress
sw.Write(byteArray, 0, byteArray.Length);
//Close, DO NOT FLUSH cause bytes will go missing...
sw.Close();
//Transform byte[] zip data to string
byteArray = ms.ToArray();
System.Text.StringBuilder sB = new System.Text.StringBuilder(byteArray.Length);
foreach (byte item in byteArray)
{
sB.Append((char)item);
}
ms.Close();
sw.Dispose();
ms.Dispose();
return sB.ToString();
}
示例3: GetImageMime
public static string GetImageMime(byte[] bt64)
{
string strImageMime = "image/unknown";
try
{
System.IO.MemoryStream msInputStream = new System.IO.MemoryStream(bt64);
System.Drawing.Image imgThisImage = System.Drawing.Image.FromStream(msInputStream);
foreach (System.Drawing.Imaging.ImageCodecInfo cdcInfo in System.Drawing.Imaging.ImageCodecInfo.GetImageDecoders())
{
if (cdcInfo.FormatID == imgThisImage.RawFormat.Guid)
{
strImageMime = cdcInfo.MimeType;
break;
}
}
imgThisImage.Dispose();
imgThisImage = null;
msInputStream.Dispose();
}
catch (System.Exception ex)
{
System.Console.WriteLine(ex.Message);
}
return strImageMime;
}
示例4: FromSerializedString
public static PlayerList FromSerializedString(string s)
{
PlayerList p = null;
XmlSerializer x = new XmlSerializer(typeof(PlayerList));
System.IO.MemoryStream ms = new System.IO.MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(s));
p = (PlayerList)x.Deserialize(ms);
ms.Dispose();
return p;
}
示例5: GetSerializedString
public string GetSerializedString()
{
XmlSerializer x = new XmlSerializer(this.GetType());
System.IO.MemoryStream ms = new System.IO.MemoryStream();
x.Serialize((System.IO.Stream)ms, this);
var buffer = ms.ToArray();
ms.Close();
ms.Dispose();
string s = System.Text.ASCIIEncoding.ASCII.GetString(buffer);
return s;
}
示例6: TestModifySubjectLine
public void TestModifySubjectLine()
{
System.IO.Stream inputStream = null;
System.IO.Stream outputStream = null;
try
{
string testemail = @"P:\Projects\Hygiene\src\TestDocuments\TagActionTestMail.eml";
byte[] inputBytes = System.IO.File.ReadAllBytes(testemail);
inputStream = new System.IO.MemoryStream(inputBytes);
MimeHelper mimeHelper = new MimeHelper(inputStream);
Guid guid = Guid.NewGuid();
mimeHelper.PrefixSubjectLine(guid.ToString());
outputStream = mimeHelper.MimeStream;
byte[] buffer = new byte[outputStream.Length];
outputStream.Position = 0;
int numBytesToRead = (int)outputStream.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
int n = outputStream.Read(buffer, numBytesRead, numBytesToRead);
// The end of the file is reached.
if (n == 0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
outputStream.Position = 0;
string email = System.Text.Encoding.Unicode.GetString(buffer);
string subjecttofind = "subject: " + guid.ToString() + "Test for PES";
Assert.Greater(email.IndexOf(subjecttofind), 0);
}
catch (System.Exception ex)
{
Assert.Fail(ex.Message);
}
finally
{
if (inputStream != null)
inputStream.Dispose();
if (outputStream != null)
outputStream.Dispose();
}
}
示例7: GZip
public static byte[] GZip(this byte[] bytes)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
GZipStream gs = new GZipStream(ms, CompressionMode.Compress, true);
gs.Write(bytes, 0, bytes.Length);
gs.Close();
gs.Dispose();
ms.Position = 0;
bytes = new byte[ms.Length];
ms.Read(bytes, 0, (int)ms.Length);
ms.Close();
ms.Dispose();
return bytes;
}
示例8: GetBackgroundPic
public static Bitmap GetBackgroundPic(I_DLE device, int address, byte mode, byte g_code_id, ref string desc)
{
RGS_SetBackgroundPic_frame frame=null;
System.IO.MemoryStream ms;
byte[] cmdText = new byte[] { 0x98, mode, g_code_id };
SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, address, cmdText);
device.Send(pkg);
if (pkg.result != CmdResult.ACK)
throw new Exception("cmd error:" + pkg.result);
byte frame_no = pkg.ReturnTextPackage.Text[3]; //0x98 frame_no
ms = new System.IO.MemoryStream(1024 * 1024*3);
for (int i = 1; i <= frame_no; i++)
{
cmdText = new byte[] {0x98,mode,g_code_id,(byte)i };
pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, address, cmdText);
device.Send(pkg);
frame = new RGS_SetBackgroundPic_frame(pkg.ReturnTextPackage);
ms.Write(frame.g_pattern_color, 0, frame.g_pattern_color.Length);
}
Bitmap pic = new Bitmap(frame.g_width, frame.g_height);
ms.Position = 0;
for(int y =0;y<frame.g_height;y++)
for (int x = 0; x < frame.g_width; x++)
{
// int r, g, b;
//r = ms.ReadByte();
//g = ms.ReadByte();
//b = ms.ReadByte();
pic.SetPixel(x, y, Color.FromArgb(ms.ReadByte(),ms.ReadByte(), ms.ReadByte()));
}
desc= System.Text.Encoding.Unicode.GetString(frame.g_desc);
ms.Dispose();
return pic;
}
示例9: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
VryImgGen gen = new VryImgGen();
string verifyCode = gen.CreateVerifyCode(4,0);
HttpCookie cookie = new HttpCookie("VerifyCode", verifyCode.ToUpper());
cookie.Expires = DateTime.Now.AddSeconds(3000);//过期时间为60秒
Response.Cookies.Add(cookie);
System.Drawing.Bitmap bitmap = gen.CreateImage(verifyCode);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
Response.Clear();
Response.ContentType = "image/Png";
Response.BinaryWrite(ms.GetBuffer());
bitmap.Dispose();
ms.Dispose();
ms.Close();
Response.End();
}
示例10: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var response = context.HttpContext.Response;
response.Clear();
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = ContentType;
//Check to see if this is done from bytes or physical location
// If you're really paranoid you could set a true/false flag in
// the constructor.
if (ImageBytes != null)
{
var stream = new System.IO.MemoryStream(ImageBytes);
stream.WriteTo(response.OutputStream);
stream.Dispose();
}
else
{
response.TransmitFile(SourceFilename);
}
}
示例11: Encrypt
/// <summary>
/// 加密数据
/// </summary>
/// <param name="Text"></param>
/// <param name="sKey"></param>
/// <returns></returns>
public static string Encrypt(string Text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray = Encoding.Default.GetBytes(Text);
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
cs.Close();
cs.Dispose();
ms.Close();
ms.Dispose();
return ret.ToString();
}
示例12: AddLayerClassNode
private void AddLayerClassNode(layerObj layer, TreeNode layernode)
{
if ((layer == null) || (layernode == null)) return;
int iClassCount = layer.numclasses;
for (int i = 0; i < iClassCount; i++)
{
classObj pClass = layer.getClass(i);
imageObj pSymbolImage = pClass.createLegendIcon(m_pMap, layer, 16, 16);
byte[] buffer = pSymbolImage.getBytes();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ms.Write(buffer, 0, buffer.Length);
imageListLeg.Images.Add(Image.FromStream(ms));
ms.Dispose();
pSymbolImage.Dispose();
int iIndex = imageListLeg.Images.Count - 1;
TreeNode subNode2 = new TreeNode("", iIndex, iIndex);
layernode.Nodes.Add(subNode2);
}
}
示例13: TabManagerMain_PageAdded
private void TabManagerMain_PageAdded(object sender, DevExpress.XtraTabbedMdi.MdiTabPageEventArgs e)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
e.Page.MdiChild.Icon.Save(ms);
e.Page.Image = Image.FromStream(ms);
ms.Close(); ms.Dispose();
//if (e.Page.MdiChild.GetType())
//{
//}
}
示例14: getData
public byte[] getData()
{
byte[] result = new byte[getNumSamples() * channels * (bitDepth / 8)];
System.IO.MemoryStream ms = new System.IO.MemoryStream(result);
System.IO.BinaryWriter wr = new System.IO.BinaryWriter(ms);
if (bitDepth == 16) {
for (int i = 0; i < getNumSamples(); i++) {
for (int c = 0; c < channels; c++) {
//assuming signed
wr.Write((short)(samples[c][i] * 32768));
}
}
} else if (bitDepth == 8) {
for (int i = 0; i < getNumSamples(); i++) {
for (int c = 0; c < channels; c++) {
//assuming unsigned
wr.Write((byte)(samples[c][i] * 128 + 128));
}
}
}
wr.Dispose();
ms.Dispose();
return result;
}
示例15: ToImage
public Image ToImage(System.Drawing.Imaging.ImageFormat format_)
{
Chart.DataBind();
Chart.InvalidateLayers();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
Chart.SaveTo(ms, format_);
Image ret = Image.FromStream(ms);
ms.Close();
ms.Dispose();
return ret;
}