简体   繁体   English

位图加载内存使文件大小增加 10 倍

[英]bitmap loaded memory increase 10x the size of the file

I am loading an image and i get an increase of memory around 10x the size of the file.我正在加载图像,并且内存增加了文件大小的 10 倍左右。

this is the output for the code below这是下面代码的输出

Loading file img_6.jpg with originally 513kb加载文件 img_6.jpg 原来是 513kb

Memory for image img_6.jpg is 63704kb (124.12x)图像 img_6.jpg 的内存为 63704kb (124.12x)

Thanks!谢谢!

this is the code i use to load这是我用来加载的代码

      string filename = "img_6.jpg";

        Directory.SetCurrentDirectory(@"C:\Users\Admin\Desktop\isolated images");


        Helpers.membefore(filename);
        

        BitmapImage bitmap = new BitmapImage();
        //using (Stream stream = new FileStream(filepath, FileMode.Open))
        {
            bitmap.BeginInit();
            //bitmap.StreamSource = stream;
            bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache;

            bitmap.CacheOption = BitmapCacheOption.OnLoad;
            bitmap.UriSource = new Uri(filename, UriKind.Relative);
            bitmap.EndInit();
          
        }
        

        ImageBrush ib = new ImageBrush() { ImageSource = bitmap };

        Helpers.memafter(ib);

these are the memory log helpers这些是内存日志助手

      public static void memafter(object result)
    {
        //debugging
        if (result.GetType() == typeof(ImageBrush) && (result as ImageBrush).ImageSource != null)
        {

            var after = Process.GetCurrentProcess().VirtualMemorySize64;
            string factor = ((double)(after - before) / (double)len).ToString("N") ;
            string source = (result as ImageBrush).ImageSource.ToString();
            Console.WriteLine(String.Format("Memory for image {0} is {1}kb ({2}x)",
               source,
                (after - before) / 1024,
                factor.ToString()));
            string s = result.ToString();
        }
    }

    public static void membefore(string xaml)
    {

        FileInfo fi = new FileInfo(xaml);
        len = fi.Length;
        Console.WriteLine(string.Format("Loading file {0} with originally {1}kb", xaml, fi.Length / 1024));

        if (xaml.Contains("ico") || xaml.Contains("jpg") || xaml.Contains("bmp") || xaml.Contains("png"))
        {
            before = Process.GetCurrentProcess().VirtualMemorySize64;
        }
    }

    private static long len = 0;
    static long before = 0;

Ok right, the reason there are different file formats was behind it.好吧,背后有不同文件格式的原因。 Irfanview helped a lot with pressing I opening image information shows file and loaded memory size. Irfanview 在按下 I 打开图像信息显示文件和加载的内存大小方面有很大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 处理后,图片的数据存储量大10倍 - Picture is 10x bigger in datastorage after manipulation 相对于x86,在x64下启动Winforms程序10倍 - Startup of Winforms program 10x slower under x64 relative to x86 Active Report 10:文本框大小增加时标签大小增加 - Active Report 10 : label size increase when textbox size increase 为什么在线程中执行此任务需要 10 倍的时间? - Why does it take 10x the time to execute this task in a thread than not? 来自递归方法的 IEnumerable 比使用 foreach 构造的相同 IEnumerable 慢 10 倍 - IEnumerable from recursive method is 10x slower than same IEnumerable constructed with foreach Linq To Sql令人惊讶的快速撤退数据。 它是否比ADO快10倍是正常的吗? - Linq To Sql surprisingly fast retreving data. Is it normal that it is 10x faster than ADO? 在Windows服务中托管的WCF服务运行速度比控制台应用程序慢10倍 - WCF Service Hosted in Windows Service running 10x slower than console app 看似纯真的.NET正则表达式会使页面响应时间缩短10倍 - Seemingly Innocent .NET Regular Expression Blows Up Page Response Time 10X Entity Framework Core 3.0.Include 调用时间增加 10 倍 - Entity Framework Core 3.0 .Include call taking 10x more time C#上传图像并保存为位图增加图像的大小 - C# Upload image and saving as Bitmap Increase size of the image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM