bytearray

Hexadecimal to 8-bit unsigned array in VB.NET

冷暖自知 提交于 2019-12-24 00:25:23
问题 I have a hexadecimal value, 07A5953EE7592CE8871EE287F9C0A5FBC2BB43695589D95E76A4A9D37019C8 Which I want to convert to a byte array. Is there a built-in function in .NET 3.5 that will get the job done or will I need to write a function to loop through each pair in the string and convert it to its 8-bit integer equivalent? 回答1: There is no built-in function that will do this. You will unfortunately have to code one up :( Public Function ToHexList(ByVal str As String) As List(Of Byte) Dim list

Encode Byte array to JPEG image in Objective-C

心已入冬 提交于 2019-12-24 00:00:51
问题 I have a file of raw data , its a image data. Now i need to convert the Raw data to JPEG image in Objective-C. STEPS: 1) Read the file containing the raw data into NSString. 2) Encode the string to JPEG encoder 3) Create an JPEG image Can you please guide me how to achieve this? Is there any library available in iPhone OS to encode into JPEG. 回答1: This is how you create a UIImage from JPEG data: UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfFile:…]]; And this is how you

How deserialize Byte array to object - Windows 8 / WP 8

爱⌒轻易说出口 提交于 2019-12-23 23:33:46
问题 Hi I use code below to convert object to byte array now I need this byte array convert back to object. Does any one know how to deserialize this in windows 8 app? I find some code but use Serialize and BinaryReader classes and this classes are not in windows 8 or does not know it. Person ps = new Person(); ps.name = "Lucy"; DataContractSerializer serializer = new DataContractSerializer(typeof(List<Dictionary<String, String>>)); byte[] byteArr; using (var ms = new MemoryStream()) { serializer

Cannot properly memcpy a char array to struct

…衆ロ難τιáo~ 提交于 2019-12-23 20:31:11
问题 So I have a construct called packet struct Packet { unsigned int packet_type; wchar_t packet_length[128]; wchar_t file_name[256]; wchar_t template_name[256]; wchar_t file_name_list[1024]; wchar_t file_data[1024]; void serialize(char * dat) { memcpy(dat, this, sizeof(Packet)); } void deserialize(const char * dat) { memcpy(this, dat, sizeof(Packet)); } }; I'm trying to desieralize from this data {byte[2692]} [0] 0 unsigned int packet_type; (4 bytes) [1] 0 [2] 0 [3] 0 [4] 50 '2' wchar_t packet

Get the number of bytes of a file behind a Java InputStream

ε祈祈猫儿з 提交于 2019-12-23 19:14:13
问题 As the title says, I need to know how many bytes the file has that's "behind" an InputStream. I don't want to download all bytes and count (takes to long). I just need to know how many bytes the file has. Like this: int numberOfBytes = countBytes(inputStream); So, I need an implementation for countBytes(InputStream inputStream) 回答1: Other than by consuming the entire stream and counting the bytes, you can't (there's no API for it). There's the available() method, but it quite explicitly doesn

Is there a less painful way to GetBytes for a buffer not starting at 0?

走远了吗. 提交于 2019-12-23 12:24:23
问题 I am having to deal with raw bytes in a project and I need to basically do something like this byte[] ToBytes(){ byte[] buffer=new byte[somelength]; byte[] tmp; tmp=BitConverter.GetBytes(SomeShort); buffer[0]=tmp[0]; buffer[1]=tmp[1]; tmp=BitConverter.GetBytes(SomeOtherShort); buffer[2]=tmp[0]; buffer[3]=tmp[1]; } I feel like this is so wrong yet I can't find any better way of doing it. Is there an easier way? 回答1: BinaryWriter is very efficient: byte[] ToBytes() { var ms = new MemoryStream

Is there a faster way to loop through thousands of items?

拥有回忆 提交于 2019-12-23 12:17:18
问题 Say I have a byte array with 100,000 bytes in it. I want to convert each byte into its textual representation of itself. For example: byte[] b = new byte[55000]; for(int i = 0; i < b.Length; i++) { Console.WriteLine(ConvertToString(b[i])); } The above code takes around 35 seconds to complete, is there some way I could cut that down to around 5 seconds? 回答1: As mentioned in my comment I would suggest removing the Console.WriteLine() method. I would also suggest that it be avoided in loops.

convert byte array to UIImage in Swift

你说的曾经没有我的故事 提交于 2019-12-23 08:55:14
问题 I want to convert byte array to UIImage in my project. For that I found something here. After that I tried to convert that code in swift but failed. Here is my swift version of the code. func convierteImagen(cadenaImagen: NSMutableString) -> UIImage { var strings: [AnyObject] = cadenaImagen.componentsSeparatedByString(",") let c: UInt = UInt(strings.count) var bytes = [UInt8]() for (var i = 0; i < Int(c); i += 1) { let str: String = strings[i] as! String let byte: Int = Int(str)! bytes.append

How do you refill a byte array using SqlDataReader?

瘦欲@ 提交于 2019-12-23 06:24:14
问题 This is in reference to: byte[] and efficiently passing by reference And the SqlDataReader found in this post: Getting binary data using SqlDataReader Inside a loop, I'm calling a database and returning a large object ( varbinary[max] ). Currently, I'm running into OutOfMemory exceptions, so I'm trying to reduce the footprint in the Large Object Heap (LOH). So, I'm creating a byte array for the largest file that I'd download and adding some padding just in case. For instance: byte[]

How do you refill a byte array using SqlDataReader?

北战南征 提交于 2019-12-23 06:24:09
问题 This is in reference to: byte[] and efficiently passing by reference And the SqlDataReader found in this post: Getting binary data using SqlDataReader Inside a loop, I'm calling a database and returning a large object ( varbinary[max] ). Currently, I'm running into OutOfMemory exceptions, so I'm trying to reduce the footprint in the Large Object Heap (LOH). So, I'm creating a byte array for the largest file that I'd download and adding some padding just in case. For instance: byte[]