示例#1
0
        public async Task DownloadTest4_LoadOnlyImageInfo()
        {
            var imgUrl = "https://raw.githubusercontent.com/cs-util-com/cscore/master/CsCore/assets/logo-cscore1024x1024_2.png";
            var h      = 1024;
            var w      = 1024;

            var timingForFullImage = Log.MethodEntered("Load full image");
            var fullImage          = await new Uri(imgUrl).SendGET().GetResult <Stream>();
            var info2 = await ImageLoader.GetImageInfoFrom(fullImage);

            fullImage.Dispose();
            Assert.Equal(h, info2.Height);
            Assert.Equal(w, info2.Width);
            Log.MethodDone(timingForFullImage);

            var timingForImageInfoOny = Log.MethodEntered("Load only first bytes");
            var stream     = await new Uri(imgUrl).SendGET().GetResult <Stream>();
            var firstBytes = await ImageLoader.CopyFirstBytes(stream, bytesToCopy : 500);

            Assert.True(firstBytes.CanSeek);
            var info = await ImageLoader.GetImageInfoFrom(firstBytes);

            firstBytes.Dispose();
            Assert.Equal(w, info.Width);
            Assert.Equal(h, info.Height);
            Log.MethodDone(timingForImageInfoOny);
            stream.Dispose();

            var    xTimesFaster = 3; // Loading only the image info should be at least this factor faster then loading the full image
            string e            = $"{timingForImageInfoOny} was not {xTimesFaster} times faster then {timingForFullImage}!";

            Assert.True(timingForImageInfoOny.ElapsedMilliseconds * xTimesFaster < timingForFullImage.ElapsedMilliseconds, e);
        }