Tag: bytearray

当我读取500MB FileStream时OutOfMemoryException

我正在使用Filestream读取大文件(> 500 MB),我得到了OutOfMemoryException。 任何解决方案。 我的代码是: using (var fs3 = new FileStream(filePath2, FileMode.Open, FileAccess.Read)) { byte[] b2 = ReadFully(fs3, 1024); } public static byte[] ReadFully(Stream stream, int initialLength) { // If we’ve been passed an unhelpful initial length, just // use 32K. if (initialLength 0) { read += chunk; // If we’ve reached the end of […]

如何使用bitConverter.ToInt32方法从c#中获取big endian的小端数据?

我在c#中进行应用程序。在该应用程序中,我有包含hex值的字节数组。 在这里,我将数据作为一个大端,但我希望它作为一个小端。 这里我使用Bitconverter.toInt32方法将该值转换为整数。 但我的问题是,在转换值之前,我必须将该4字节数据从源字节数组复制到临时数组中,然后反转该临时字节数组。 我不能反转源数组,因为它也包含其他数据。 因为我的应用程序变得缓慢。 代码这里我有一个字节的源数组作为waveData []。它包含很多数据。 byte[] tempForTimestamp=new byte[4]; tempForTimestamp[0] = waveData[290]; tempForTimestamp[1] = waveData[289]; tempForTimestamp[2] = waveData[288]; tempForTimestamp[3] = waveData[287]; int number = BitConverter.ToInt32(tempForTimestamp, 0); 该转换还有其他方法吗?

如何使用字节数组比较两个图像

我希望能够从Byte []转换为Image,反之亦然。 我从这里开始这两种方法: public byte[] imageToByteArray(System.Drawing.Image imageIn) { MemoryStream ms = new MemoryStream(); imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif); return ms.ToArray(); } public Image byteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); return returnImage; } 他们似乎工作,但如果我这样做: byte[] pic = GetImageFromDb(); bool result = pic == imageToByteArray(byteArrayToImage(pic)); 我得到result = false ! 有没有办法纠正这种方法或一些不同的function来实现我的目标? 谢谢!

WPF图像到byte

我正在尝试从System.Windows.Controls.Image转换为byte[] ,我不知道Image类中哪个方法可以帮助这个场景,顺便说一下我真的不知道该怎么做,因为我的LINQ模型该字段显示为Binary类型,如果我想将其保存为byte[]类型,我必须更改它吗? 我在这里发现了代码,但没有使用WPF: Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight); System.IO.MemoryStream stream = new System.IO.MemoryStream(); newBMP.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); PHJProjectPhoto myPhoto = new PHJProjectPhoto { ProjectPhoto = stream.ToArray(), // <<— This will convert your stream to a byte[] OrderDate = DateTime.Now, ProjectPhotoCaption = ProjectPhotoCaptionTextBox.Text, ProjectId = selectedProjectId };