示例#1
0
        /// <devdoc>
        ///     Copy the native GDI+ EncoderParameters data from a chunk of memory into a managed EncoderParameters object.
        ///     See ConvertToMemory for more info.
        /// </devdoc>
        internal static EncoderParameters ConvertFromMemory(IntPtr memory)
        {
            if (memory == IntPtr.Zero)
            {
                throw SafeNativeMethods.Gdip.StatusException(SafeNativeMethods.Gdip.InvalidParameter);
            }

            int count = Marshal.ReadIntPtr(memory).ToInt32();

            EncoderParameters p = new EncoderParameters(count);
            int  size           = Marshal.SizeOf(typeof(EncoderParameter));
            long arrayOffset    = (long)memory + Marshal.SizeOf(typeof(IntPtr));

            for (int i = 0; i < count; i++)
            {
                Guid guid                      = (Guid)UnsafeNativeMethods.PtrToStructure((IntPtr)(i * size + arrayOffset), typeof(Guid));
                int  numberOfValues            = Marshal.ReadInt32((IntPtr)(i * size + arrayOffset + 16));
                EncoderParameterValueType type = (EncoderParameterValueType)Marshal.ReadInt32((IntPtr)(i * size + arrayOffset + 20));
                IntPtr value                   = Marshal.ReadIntPtr((IntPtr)(i * size + arrayOffset + 24));

                p._param[i] = new EncoderParameter(new Encoder(guid), numberOfValues, type, value);
            }

            return(p);
        }
示例#2
0
        private static jthread alloc_thread(JNIEnvHandle jniEnv)
        {
            jniNativeInterface nativeInterface = (jniNativeInterface)Marshal.PtrToStructure(Marshal.ReadIntPtr(jniEnv.Handle), typeof(jniNativeInterface));

            jclass @class = nativeInterface.FindClass(jniEnv, "java/lang/Thread");

            if (@class == jclass.Null)
            {
                throw new Exception("ERROR: JNI: Cannot find %s with FindClass.");
            }

            nativeInterface.ExceptionClear(jniEnv);

            jmethodID method = nativeInterface.GetMethodID(jniEnv, @class, "<init>", "()V");

            if (method == jmethodID.Null)
            {
                throw new Exception("Cannot find Thread constructor method.");
            }

            nativeInterface.ExceptionClear(jniEnv);
            jthread result = (jthread)nativeInterface.NewObject(jniEnv, @class, method);

            if (result == jthread.Null)
            {
                throw new Exception("Cannot create new Thread object");
            }

            nativeInterface.ExceptionClear(jniEnv);
            return(result);
        }