working on it ...

Filters

Explore Public Snippets

Sort by

Found 517 snippets matching: framework-development

    public by Geometry  128551  0  5  0

    Hann: Creates a new Hann Window.

    Creates a new Hann Window.
    /// <summary>
    ///   Creates a new Hann Window.
    /// </summary>
    /// 
    public static RaisedCosineWindow Hann(double length, int sampleRate)
    {
        return new RaisedCosineWindow(0.5, length, sampleRate);
    }

    public by Geometry  125448  0  5  0

    FromFile: Load bitmap from file.

    Load bitmap from file. File name to load bitmap from. Returns loaded bitmap. The method is provided as an alternative of method to solve the issues of locked file. The standard .NET's method locks the source file until image's object is disposed, so the file can not be deleted or overwritten. This method workarounds the issue and
    /// <summary>
    /// Load bitmap from file.
    /// </summary>
    /// 
    /// <param name="fileName">File name to load bitmap from.</param>
    /// 
    /// <returns>Returns loaded bitmap.</returns>
    /// 
    /// <remarks><para>The method is provided as an alternative of <see cref="System.Drawing.Image.FromFile(string)"/>
    /// method to solve the issues of locked file. The standard .NET's method locks the source file until
    /// image's object is disposed, so the file can not be deleted or overwritten. This method workarounds the issue and
    /// does not lock the source file.</para>
    /// 
    /// <para>Sample usage:</para>
    /// <code>
    /// Bitmap image = Accord.Imaging.Image.FromFile( "test.jpg" );
    /// </code>
    /// </remarks>
    /// 
    public static System.Drawing.Bitmap FromFile(string fileName)
    {
        Bitmap loadedImage = null;
        FileStream stream = null;
    
        try
        {
            // read image to temporary memory stream
            stream = File.OpenRead(fileName);
            MemoryStream memoryStream = new MemoryStream();
    
            byte[] buffer = new byte[10000];
            while (true)
            {
                int read = stream.Read(buffer, 0, 10000);
    
                if (read == 0)
                    break;
    
                memoryStream.Write(buffer, 0, read);
            }
    
            loadedImage = (Bitmap)Bitmap.FromStream(memoryStream);
        }
        finally
        {
            if (stream != null)
            {
                stream.Close();
                stream.Dispose();
            }
        }
    
        return loadedImage;
    }

    public by Geometry  112775  0  6  0

    DeepClone: Copies a collection by calling the ICloneable.Clone method for each element inside it.

    Copies a collection by calling the ICloneable.Clone method for each element inside it. yThe collection to be cloned. A copy of the collection where each element has also been copied.
    /// <summary>
    ///   Copies a collection by calling the ICloneable.Clone method for each element inside it.
    /// </summary>
    /// 
    /// <typeparam name="T"></typeparam>
    /// <param name="list">The collection to be cloned.</param>
    /// 
    /// <returns>A copy of the collection where each element has also been copied.</returns>
    /// 
    public static T DeepClone<T>(this T list)
        where T : IList<ICloneable>, ICloneable
    {
        T clone = (T)list.Clone();
        for (int i = 0; i < clone.Count; i++)
            clone[i] = (ICloneable)list[i].Clone();
        return clone;
    }

    public by Geometry  110593  0  5  0

    IsMatrix: Determines whether an array is an multidimensional array.

    Determines whether an array is an multidimensional array.
    /// <summary>
    ///   Determines whether an array is an multidimensional array.
    /// </summary>
    /// 
    public static bool IsMatrix(this Array array)
    {
        return array.Rank > 1;
    }

    public by Geometry  109533  0  5  0

    FromRGB: Convert from RGB to YCbCr color space (Rec 601-1 specification).

    Convert from RGB to YCbCr color space (Rec 601-1 specification). Source color in RGB color space. Destination color in YCbCr color space.
    /// <summary>
    /// Convert from RGB to YCbCr color space (Rec 601-1 specification). 
    /// </summary>
    /// 
    /// <param name="rgb">Source color in <b>RGB</b> color space.</param>
    /// <param name="ycbcr">Destination color in <b>YCbCr</b> color space.</param>
    /// 
    public static void FromRGB(RGB rgb, YCbCr ycbcr)
    {
        float r = (float)rgb.Red / 255;
        float g = (float)rgb.Green / 255;
        float b = (float)rgb.Blue / 255;
    
        ycbcr.Y = (float)(0.2989 * r + 0.5866 * g + 0.1145 * b);
        ycbcr.Cb = (float)(-0.1687 * r - 0.3313 * g + 0.5000 * b);
        ycbcr.Cr = (float)(0.5000 * r - 0.4184 * g - 0.0816 * b);
    }

    public by Geometry  109526  0  5  0

    Random: Creates a rows-by-cols matrix random data drawn from a given distribution.

    Creates a rows-by-cols matrix random data drawn from a given distribution.
    /// <summary>
            ///   Creates a rows-by-cols matrix random data drawn from a given distribution.
            /// </summary>
            /// 
            [Obsolete("Please use INumberGenerator<T> instead.")]
    #pragma warning disable 0618
            public static double[,] Random(int rows, int cols, IRandomNumberGenerator generator)
            {
                return Random<double>(rows, cols, new RandomNumberGeneratorAdapter(generator));
            }

    public by Geometry  108203  0  5  0

    Reshape: Transforms a vector into a matrix of given dimensions.

    Transforms a vector into a matrix of given dimensions.
    /// <summary>
    ///   Transforms a vector into a matrix of given dimensions.
    /// </summary>
    /// 
    public static T[][] Reshape<T>(this T[] array, int rows, int cols, T[][] result, MatrixOrder order = MatrixOrder.Default)
    {
        if (order == MatrixOrder.CRowMajor)
        {
            int k = 0;
            for (int i = 0; i < rows; i++)
                for (int j = 0; j < cols; j++)
                    result[i][j] = array[k++];
        }
        else
        {
            int k = 0;
            for (int j = 0; j < cols; j++)
                for (int i = 0; i < rows; i++)
                    result[i][j] = array[k++];
        }
    
        return result;
    }

    public by Geometry  98080  0  5  0

    Diagonal: Returns a matrix with a vector of values on its diagonal.

    Returns a matrix with a vector of values on its diagonal.
    /// <summary>
            ///   Returns a matrix with a vector of values on its diagonal.
            /// </summary>
            /// 
    #if NET45
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
    #endif
            public static T[][] Diagonal<T>(int rows, int cols, T[] values, T[][] result)
            {
                int size = Math.Min(rows, Math.Min(cols, values.Length));
                for (int i = 0; i < size; i++)
                    result[i][i] = values[i];
                return result;
            }

    public by Geometry  97957  0  5  0

    CartesianProduct: Computes the Cartesian product of two sets.

    Computes the Cartesian product of two sets.
    /// <summary>
    ///   Computes the Cartesian product of two sets.
    /// </summary>
    /// 
    [Obsolete("Please use Cartesian instead.")]
    public static T[][] CartesianProduct<T>(this T[] sequence1, T[] sequence2)
    {
        return Cartesian(new T[][] { sequence1, sequence2 });
    }

    public by Geometry  93329  0  5  0

    Convert: Converts a signed 16-bit integer sample into a 32-bit signed integer sample.

    Converts a signed 16-bit integer sample into a 32-bit signed integer sample. The original sample. The resulting sample.
    /// <summary>
    ///   Converts a signed 16-bit integer sample
    ///   into a 32-bit signed integer sample.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(Int16 from, out Int32 to)
    {
        to = (byte)(((from) >> 8) + 128);
    }
    • Public Snippets
    • Channels Snippets