Ejemplo n.º 1
0
    public void Scale(int?width, int?height, WicBitmapInterpolationMode mode)
    {
        if (!width.HasValue && !height.HasValue)
        {
            throw new ArgumentException();
        }
        int neww;
        int newh;

        if (width.HasValue && height.HasValue)
        {
            neww = width.Value;
            newh = height.Value;
        }
        else
        {
            int w = Width;
            int h = Height;
            if (w == 0 || h == 0)
            {
                return;
            }
            if (width.HasValue)
            {
                neww = width.Value;
                newh = (width.Value * h) / w;
            }
            else
            {
                newh = height.Value;
                neww = (height.Value * w) / h;
            }
        }
        if (neww <= 0 || newh <= 0)
        {
            throw new ArgumentException();
        }
        CheckDisposed();
        _source = Scale(_source, neww, newh, mode);
        Stats();
    }
Ejemplo n.º 2
0
    private static IWICBitmapScaler Scale(IWICBitmapSource source, int width, int height, WicBitmapInterpolationMode mode)
    {
        var wfac = (IWICImagingFactory) new WICImagingFactory();
        IWICBitmapScaler scaler = null;

        try
        {
            scaler = wfac.CreateBitmapScaler();
            scaler.Initialize(source, width, height, mode);
            Marshal.ReleaseComObject(source);
            return(scaler);
        }
        finally
        {
            Release(wfac);
        }
    }