logo
down
shadow

What's the proper way to convert a Vector3DF into byte array?


What's the proper way to convert a Vector3DF into byte array?

By : user2956320
Date : November 22 2020, 10:54 AM
wish of those help I am implementing Kinect's FaceTrackingBasics-WPF C# code to track the position of some object. Tried to collect a Vector3DF type variable into some byte array using Buffer.BlockCopy as follows: , here is a way using interop techniques
code :
    //sample data
    Vector3DF v3df = new Vector3DF(10, 20, 30);

    //get data size
    int size = Marshal.SizeOf(v3df);

    //allocate memory
    IntPtr ptr = Marshal.AllocHGlobal(size);

    //copy data to memory
    Marshal.StructureToPtr(v3df, ptr, false);

    //copy data from memory to byte array
    byte[] bytes = new byte[size];
    Marshal.Copy(ptr, bytes, 0, bytes.Length);

    //release memory
    Marshal.FreeHGlobal(ptr);


Share : facebook icon twitter icon
RandomAccessFile: write(byte) in a loop or write(byte array), whats more effiecient?

RandomAccessFile: write(byte) in a loop or write(byte array), whats more effiecient?


By : Reesh
Date : March 29 2020, 07:55 AM
may help you . Writing a byte array is always going to be quicker than repeated calls to write one byte at a time. There's much less overhead (method calls, IO).
Whats the diffrence between an array<Byte>^ and a byte*?

Whats the diffrence between an array<Byte>^ and a byte*?


By : TonyZhang
Date : March 29 2020, 07:55 AM
I wish did fix the issue. array^ is a handle to an object in the managed heap, byte* is a pointer to an unmanaged byte. You cannot cast between them, but it is possible to fix the managed array and obtain a pointer to the elements within it.
EDIT in response to first comment:
code :
// pin_ptr_1.cpp
// compile with: /clr 
using namespace System;
#define SIZE 10

#pragma unmanaged
// native function that initializes an array
void native_function(byte* p) {
    for(byte i = 0 ; i < 10 ; i++)
        p[i] = i;
}
#pragma managed

public ref class A {
private:
    array<byte>^ arr;   // CLR integer array

public:
    A() {
        arr = gcnew array<byte>(SIZE);
    }

    void load() {
        pin_ptr<byte> p = &arr[0];   // pin pointer to first element in arr
        byte* np = p;   // pointer to the first element in arr
        native_function(np);   // pass pointer to native function
    }

    int sum() {
        int total = 0;
        for (int i = 0 ; i < SIZE ; i++)
            total += arr[i];
        return total;
    }
};

int main() {
    A^ a = gcnew A;
    a->load();   // initialize managed array using the native function
    Console::WriteLine(a->sum());
}
How to convert Cp1252 byte array to a proper string?

How to convert Cp1252 byte array to a proper string?


By : user3196490
Date : March 29 2020, 07:55 AM
Does that help I noticed your phrase - "proper string", and would like to point out that there is no such thing as a proper or improper string in your case. It's the encoding that is either proper or improper.
You're reading the byte sequence of cp1252 bytes, and appending the individual characters into a buffer. If the original file is in cp1252, there are no problems with this process. Under the hood, the InputStreamReader employs a CharsetDecoder that is capable of decoding the underlying charset of the stream, into a sequence of sixteen-bit Unicode characters (UTF-16). This is done, because you are reading characters from the byte stream.
Endianness - How to convert a c# integer into a big-endian byte (no byte array, just a single byte)?

Endianness - How to convert a c# integer into a big-endian byte (no byte array, just a single byte)?


By : Skarface
Date : March 29 2020, 07:55 AM
I wish this helpful for you Your problem has nothing to do with endian-ness. When you're doing arithmetic, it doesn't matter whether the system is big-endian or little-indian. That is, given this:
code :
int len = 260;

byte highByte = (byte)(len >> 8);
byte lowByte = (byte)(len & 255);

Console.WriteLine("highByte = {0:X2}", highByte);
Console.WriteLine("lowByte = {0:X2}", lowByte);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string tramaISOHeader = enc.GetString(tramaISOBytes);
proper way to convert byte[] to array with dots

proper way to convert byte[] to array with dots


By : John Bocharov
Date : March 29 2020, 07:55 AM
hope this fix your issue I'm capturing data from a pcap packet; in my code I have a byte[] data and I want to decode to String using new String() constructor. , One could do a String.replace, but more correct:
code :
int n = 0;
for (byte b : data) {
    if (32 <= b && b < 127) { // Within ASCII
        data[n++] = b;
    }
}
String datastr = new String(data, 0, n, StandardCharsets.US_ASCII);
Related Posts Related Posts :
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • Marshal.Copy attempted to read or write protected memory At Random Times
  • Restrict Type variable to specific class or subclass
  • Horizontal text alignment in a PdfPCell
  • C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please
  • Will the result of a LINQ query always be guaranteed to be in the correct order?
  • "Could not find default endpoint element that references contract"
  • Umbraco Request.QueryString is null if it's the first time the page is loaded
  • Error inconsistent accessibility method C#
  • How to program Intel Xeon Phi with C#?
  • remove nested element using regular expression
  • Is there a C# alternative to Java's vararg parameters?
  • Clear particular column values in DataTable
  • how to add event handler to programatically created checkboxes
  • Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
  • Check for key in pre-existing dictionary in case insensitive manner
  • How to remove year from datetime object?
  • Accessing Settings in different ways
  • "This project is empty" error in Sonarqube
  • How to create reusable icon menu in Xamarin
  • Value Cannot be null in Ado.Net connectivity
  • Adding a custom/dynamic attribute when using XSD.exe
  • How to convert object to correct type
  • Automatically sign out from Forms Authentication in ASP.NET when browser is closed
  • Can a WCF service support both Buffered and Streamed transfer modes?
  • Verify a CA Certificate with a public key in C#
  • How to invoke a Web Service that requires the "patch" verb using the C# WebClient wrapper?
  • Proper way a implementing property based on generic type
  • Closing a form that is created in another thread
  • How Can You Bind a List<String> to a StackPanel
  • WPF Application Update Best Practices - Architectural Explanation
  • System.UnauthorizedAccessException in Server.MapPath()
  • Connecting and Using SQL Compact Edition in a WPF application
  • C#: weird ref in constructor to behave like "virtual field"
  • C# XDocument Load with multiple roots
  • How to decide what goes in the Domain or Application Project in a "DDD" solution?
  • How to get/set a property of an interface that is not always implemented
  • Read-only array field in unsafe struct
  • i got "Invalid attempt to call Read when reader is closed" when using sqldatareader how to solve it in a three
  • Why should I encapsulate objects in using if there is garbage collection
  • How to load Word document from byte array
  • Caliburn.Micro and ContextMenu for DataGrid Row
  • Linq "join" with a IList<T> getting "Error Unable to create a constant value.."
  • How to draw red wavy line under words in RichTextBox c# winform
  • HttpPostedFileBase returns Null MVC3
  • Refresh Dropdownlist in webform
  • How to convert serialized byte array back to its text form
  • How to do a loop to check all the variables at the same time for C#?
  • Facebook Sentiment Analysis API
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org