bytearray

Sending UDP packets in the correct Endianness

泪湿孤枕 提交于 2019-12-11 01:05:07
问题 Hi Guys I’m having trouble understanding network byte ordering and the order in which data is sent and received over UDP. I'm using C# I have a structure holding: message.start_id = 0x7777CCCC; message.message _id = 0xBBB67000; more data the message definition has [StructLayout(LayoutKind.Sequential)] I first convert the structure to a byte array using: public byte[] StructureToByteArray(object obj) { int len = Marshal.SizeOf(obj); byte[] arr = new byte[len]; IntPtr ptr = Marshal.AllocHGlobal

How to share a big byte array between C++ and C#

独自空忆成欢 提交于 2019-12-10 22:44:01
问题 I need to share a huge (many megabytes) byte array between a C++ program residing in a DLL and a C# program. I need realtime performance, so it is very important I can share it between the two in an efficient way, so making a new copy for it in C# every time after the data is manipulated in C++ is not an option, yet the examples I have found so far seems to depend on this. Is it possible to share the array in an efficient way? And if so, how? 回答1: In current versions of .NET, any multi

Converting bitmap to byte array, to string, then all the way back

江枫思渺然 提交于 2019-12-10 22:06:55
问题 I have tried several different methods found in the java documentation, as well as several solutions from other SO questions and have successfully gotten a Bitmap to convert to a byte[] and back again. The problem is that I now need to convert this byte[] to a String , then back to a byte[] , then back to a Bitmap again. To recap what I need: Bitmap -> byte[] -> String -> byte[] -> Bitmap I know this sounds strange but what I'm trying to accomplish must be done this way. Below is what I have

How to gzip a bytearray in Python?

孤者浪人 提交于 2019-12-10 21:19:18
问题 I have binary data inside a bytearray that I would like to gzip first and then post via requests. I found out how to gzip a file but couldn't find it out for a bytearray. So, how can I gzip a bytearray via Python? 回答1: Have a look at the zlib -module of Python. Python 3: zlib-module A short example: import zlib compressed_data = zlib.compress(my_bytearray) You can decompress the data again by: decompressed_byte_data = zlib.decompress(compressed_data) Python 2: zlib-module A short example:

Interpret raw image data from Android Camera onPictureTaken(byte[] data)

99封情书 提交于 2019-12-10 20:16:51
问题 I'm using the Camera class to take a picture and want to do some processing on the image inside onPictureTaken. How can I interpret the byte array? Is it in RGB format or something else? Thanks. 回答1: references say it depends on Camera.Parameters (Camera.Parameters), and in this post (Re: FileOutPutstream code from onPictureTaken) they say that you must use the jpeg callback, so i guess it's jpeg. 回答2: One more solution mCamera.takePicture(null, null,mPictureCallbackRaw); where

Convert structure to byte array in .NET

倖福魔咒の 提交于 2019-12-10 19:43:36
问题 I wish to write a structure made up of fixed length strings to a file using My.Computer.FileSystem.WriteAllBytes or the like. I am using a VB6 project with fixed length strings that I have converted in to VB.Net. Structure Record <VBFixedString(22),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst:=22)> Public tim() As Char <VBFixedString(130),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType

Java boolean[] to byte[] and back

◇◆丶佛笑我妖孽 提交于 2019-12-10 16:58:27
问题 I am sending byte[] arrays over a socket connection in Java. I have a pretty long boolean[] array, where array.length % 8 == 0 . I'd like to convert this boolean[] array into a byte[] array with 8 times as few elements, so that I can then send the byte[] over the socket connection. The boolean[] array looks like this: 01011010 10101010 01100011 11001010 etc. The byte[] in this case should look like this: 0x5A 0xAA 0x63 0xCA . I have found some code on another question on how to convert a

Is there a function to do circular bitshift for a byte array in C#?

白昼怎懂夜的黑 提交于 2019-12-10 15:48:52
问题 I can't seem to find if there's a built-in way to do a circular bitshift of a byte array, what C's ROL and ROR used to do with a single byte? Let me explain, say, I have an array (in binary): [0] = 11001110 [1] = 01000100 [2] = 10100001 and then if I want to do ROL_Array(1 bit) or move bits 1 bit to the left, I'd get: [0] = 10011100 [1] = 10001001 [2] = 01000011 or, if I want to do ROR_Array(2 bits) or move bits 2 bits to the right, I'd get: [0] = 00110011 [1] = 01010001 [2] = 10101000 回答1:

How do I convert a JSONObject to a byte array and then convert this byte array to get back the original JSONObject? [duplicate]

半城伤御伤魂 提交于 2019-12-10 15:13:39
问题 This question already has answers here : Convert a String to a byte array and then back to the original String (5 answers) Closed 3 years ago . I am using the AWS JSONObject class. Let's say I define a JSONObject object like so: JSONObject obj = new JSONObject(); obj.put("Field1": 35); JSONObject nestedObj = new JSONObject(); nestedObj.put("Name1":"value1"); nestedObj.put("Name2":42); obj.put("Field2": nestedObj); So the JSONObject looks like: {"Field1": 35, "Field2": {"Name1": "value1",

Java validate image header

允我心安 提交于 2019-12-10 14:55:43
问题 I am having one requirement where i need to identify the type of the image not by the files extension but by validating the header. I am trying to validate a JPEG file by magic number validation. File imgFile = new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.jpg"); byte[] ba = Files.toByteArray(imgFile); //Its a google guava library int i = 0; if(ba [i] == 0xFF && ba[i+1] == 0xD8 && ba[i+2] == 0xFF && ba[i+3] == 0xE0){ System.out.println("isJPEG"); } But the condition is