示例#1
0
   public IntPtr ToByteArray(int x, int y, int width, int height, string mapping)
   {
       using (INativeInstance mappingNative = UTF8Marshaler.CreateInstance(mapping))
       {
           IntPtr exception = IntPtr.Zero;
           IntPtr result;
 #if ANYCPU
           if (NativeLibrary.Is64Bit)
 #endif
 #if WIN64 || ANYCPU
           result = NativeMethods.X64.PixelCollection_ToByteArray(Instance, (UIntPtr)x, (UIntPtr)y, (UIntPtr)width, (UIntPtr)height, mappingNative.Instance, out exception);
 #endif
 #if ANYCPU
           else
 #endif
 #if !WIN64 || ANYCPU
           result = NativeMethods.X86.PixelCollection_ToByteArray(Instance, (UIntPtr)x, (UIntPtr)y, (UIntPtr)width, (UIntPtr)height, mappingNative.Instance, out exception);
 #endif
           MagickException magickException = MagickExceptionHelper.Create(exception);
           if (MagickExceptionHelper.IsError(magickException))
           {
               if (result != IntPtr.Zero)
               {
                   MagickMemory.Relinquish(result);
               }
               throw magickException;
           }
           RaiseWarning(magickException);
           return(result);
       }
   }
示例#2
0
 public IntPtr WriteBlob(MagickImage image, MagickSettings settings, out UIntPtr length)
 {
     using (INativeInstance settingsNative = MagickSettings.CreateInstance(settings))
     {
         IntPtr exception = IntPtr.Zero;
         IntPtr result;
         if (NativeLibrary.Is64Bit)
         {
             result = NativeMethods.X64.MagickImageCollection_WriteBlob(MagickImage.GetInstance(image), settingsNative.Instance, out length, out exception);
         }
         else
         {
             result = NativeMethods.X86.MagickImageCollection_WriteBlob(MagickImage.GetInstance(image), settingsNative.Instance, out length, out exception);
         }
         MagickException magickException = MagickExceptionHelper.Create(exception);
         if (MagickExceptionHelper.IsError(magickException))
         {
             if (result != IntPtr.Zero)
             {
                 MagickMemory.Relinquish(result);
             }
             throw magickException;
         }
         RaiseWarning(magickException);
         return(result);
     }
 }
示例#3
0
 public IntPtr ToShortArray(int x, int y, int width, int height, string mapping)
 {
     using (INativeInstance mappingNative = UTF8Marshaler.CreateInstance(mapping))
     {
         IntPtr exception = IntPtr.Zero;
         IntPtr result;
         #if PLATFORM_AnyCPU
         if (NativeLibrary.Is64Bit)
         #endif
         #if PLATFORM_x64 || PLATFORM_AnyCPU
         result = NativeMethods.X64.PixelCollection_ToShortArray(Instance, (UIntPtr)x, (UIntPtr)y, (UIntPtr)width, (UIntPtr)height, mappingNative.Instance, out exception);
         #endif
         #if PLATFORM_AnyCPU
         else
         #endif
         #if PLATFORM_x86 || PLATFORM_AnyCPU
         result = NativeMethods.X86.PixelCollection_ToShortArray(Instance, (UIntPtr)x, (UIntPtr)y, (UIntPtr)width, (UIntPtr)height, mappingNative.Instance, out exception);
         #endif
         var magickException = MagickExceptionHelper.Create(exception);
         if (magickException == null)
         {
             return(result);
         }
         if (magickException is MagickErrorException)
         {
             if (result != IntPtr.Zero)
             {
                 MagickMemory.Relinquish(result);
             }
             throw magickException;
         }
         RaiseWarning(magickException);
         return(result);
     }
 }
示例#4
0
        ///<summary>
        /// Writes the imagse to the specified stream. If the output image's file format does not
        /// allow multi-image files multiple files will be written.
        ///</summary>
        ///<param name="stream">The stream to write the images to.</param>
        ///<exception cref="MagickException"/>
        public void Write(Stream stream)
        {
            Throw.IfNull("stream", stream);

            if (_Images.Count == 0)
            {
                return;
            }

            MagickSettings settings = _Images[0].Settings;

            settings.FileName = null;

            try
            {
                AttachImages();

                UIntPtr length;
                IntPtr  data = _NativeInstance.WriteBlob(_Images[0], settings, out length);
                MagickMemory.WriteBytes(data, length, stream);
            }
            finally
            {
                DetachImages();
            }
        }
示例#5
0
        internal static string NativeToManagedAndRelinquish(IntPtr nativeData)
        {
            string result = NativeToManaged(nativeData);

            MagickMemory.Relinquish(nativeData);

            return(result);
        }
示例#6
0
        /// <summary>
        /// Returns the values of the pixels as an array.
        /// </summary>
        ///<param name="x">The X coordinate of the area.</param>
        ///<param name="y">The Y coordinate of the area.</param>
        ///<param name="width">The width of the area.</param>
        ///<param name="height">The height of the area.</param>
        ///<param name="mapping">The mapping of the pixels (e.g. RGB/RGBA/ARGB).</param>
        public byte[] ToByteArray(int x, int y, int width, int height, string mapping)
        {
            Throw.IfNullOrEmpty("mapping", mapping);

            CheckArea(x, y, width, height);
            IntPtr nativeResult = _NativeInstance.ToByteArray(x, y, width, height, mapping);

            byte[] result = ByteConverter.ToArray(nativeResult, width * height * mapping.Length);
            MagickMemory.Relinquish(nativeResult);
            return(result);
        }
示例#7
0
        public ushort[] ToShortArray(int x, int y, int width, int height, string mapping)
        {
            Throw.IfNullOrEmpty(nameof(mapping), mapping);

            CheckArea(x, y, width, height);
            IntPtr nativeResult = _NativeInstance.ToShortArray(x, y, width, height, mapping);

            ushort[] result = ShortConverter.ToArray(nativeResult, width * height * mapping.Length);
            MagickMemory.Relinquish(nativeResult);
            return(result);
        }
示例#8
0
        public virtual ushort[]? ToShortArray(int x, int y, int width, int height, string mapping)
        {
            var nativeResult = IntPtr.Zero;

            try
            {
                nativeResult = _nativeInstance.ToShortArray(x, y, width, height, mapping);
                return(ShortConverter.ToArray(nativeResult, width * height * mapping.Length));
            }
            finally
            {
                MagickMemory.Relinquish(nativeResult);
            }
        }
示例#9
0
        public virtual byte[] ToByteArray(int x, int y, int width, int height, string mapping)
        {
            var nativeResult = IntPtr.Zero;

            byte[] result = null;

            try
            {
                nativeResult = _nativeInstance.ToByteArray(x, y, width, height, mapping);
                result       = ByteConverter.ToArray(nativeResult, width * height * mapping.Length);
            }
            finally
            {
                MagickMemory.Relinquish(nativeResult);
            }

            return(result);
        }
示例#10
0
        public virtual ushort[] ToShortArray(int x, int y, int width, int height, string mapping)
        {
            Throw.IfNullOrEmpty(nameof(mapping), mapping);

            IntPtr nativeResult = IntPtr.Zero;

            ushort[] result = null;

            try
            {
                nativeResult = _nativeInstance.ToShortArray(x, y, width, height, mapping);
                result       = ShortConverter.ToArray(nativeResult, width * height * mapping.Length);
            }
            finally
            {
                MagickMemory.Relinquish(nativeResult);
            }

            return(result);
        }
示例#11
0
        /// <summary>
        /// Returns the values of the pixels as an array.
        /// </summary>
        /// <param name="x">The X coordinate of the area.</param>
        /// <param name="y">The Y coordinate of the area.</param>
        /// <param name="width">The width of the area.</param>
        /// <param name="height">The height of the area.</param>
        /// <param name="mapping">The mapping of the pixels (e.g. RGB/RGBA/ARGB).</param>
        /// <returns>A <see cref="byte"/> array.</returns>
        public byte[] ToByteArray(int x, int y, int width, int height, string mapping)
        {
            Throw.IfNullOrEmpty(nameof(mapping), mapping);

            CheckArea(x, y, width, height);
            IntPtr nativeResult = IntPtr.Zero;

            byte[] result = null;

            try
            {
                nativeResult = _nativeInstance.ToByteArray(x, y, width, height, mapping);
                result       = ByteConverter.ToArray(nativeResult, width * height * mapping.Length);
            }
            finally
            {
                MagickMemory.Relinquish(nativeResult);
            }

            return(result);
        }