wpf错误内存不足以在visual studio 2012中继续执行

时间:2016-01-20 14:41:46

标签: wpf visual-studio-2012 out-of-memory runtime-error

error list我是wpf的新手,我正在开发一个使用相同的非常简单的应用程序。 我有一个窗口,我放了一个dockpanel,dockpanel有两个菜单,

"动作 - >关于,帮助,退出" &安培; "&区域 - GT; Area1,Area2,Area3"

在区域菜单中单击area1时,我在同一窗口中加载用户控件。该用户控件具有网格。整个网格分为40行和在40列中,网格的背景是一个图像,使其跨越整个网格。实际上我的想法是将图像划分为160个可点击的相等正方形。 在40 cross 40 grid的每个单元格中,我放置了一个带有增量名称的透明按钮,如b1,b2,b3 ......直到b160。在单击任何按钮时,执行anybuttonclick方法(我在后面的代码中定义) 我还在解决方案目录的单独文件夹中有160个单独的高分辨率图像,所有这些图像的名称也放在b1.jpg,b2.jpg,b3.jpg .. upto b160.jpg !!! 在后面的代码我已经把anybuttonclick方法,其中我得到用户点击的按钮的名称,并借助于此我能够决定在新窗口中加载哪个图像。例如,如果用户单击b35,我将在新窗口中加载图像b35.jpg ..新窗口中的此图像是高分辨率图像(单元格1的缩放版本)。

我和area2一样 在这里,area1文件夹中的图像大小为670 mb,图像数量为160 并且area2文件夹中的图像大小为785 mb,并且iamges的数量为160

一切正常。只有当我尝试对area3做同样的事情时才会出现问题。即当我尝试将area3的高分辨率图像复制到名为“images3”的文件夹中时 area3文件夹中的图像数量为160,图像大小为783 mb 我有时会在运行时说出outofmemory异常。有时它表示内存不足以继续执行。 然后我删除了area3的图像(每个区域有160个图像)我能够正确调试项目。 我试图只用两个区域发布应用程序。并在我的系统上测试。它工作正常。(英特尔酷睿i5 2.4 ghz 16 gb ram windows 7 32位,visual studio 2012) 但当我将相同的已发布应用程序传送到我的笔记本电脑(intel core i7 2.4 ghz,4 gb ram windows 7 32 bit,visual studio 2012)时,应用程序在安装时崩溃。

我的问题是我对wpf的错误?没有限制。我们可以使用的图像或图像大小?我尝试将修补程序应用到v2012仍然是同样的问题。开发此类应用程序的最佳做法是在解决方案目录中包含大量图像时。我不想使用sql来存储图像,因为我不想在图像质量上做出妥协。

DalLake.xaml中的

代码

<UserControl x:Class="HmiLike.Pages.DalLake"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:pages="clr-namespace:HmiLike.Pages"
             mc:Ignorable="d" 
             d:DesignHeight="800" d:DesignWidth="800"
             >


    <Grid>
        <Grid.Background>
            <ImageBrush ImageSource="/Images/background.jpg">

            </ImageBrush>
        </Grid.Background>
            <Grid.ColumnDefinitions>

        <ColumnDefinition Width="50*"/>
            <ColumnDefinition Width="44*"/>
            <ColumnDefinition Width="42*"/>
            <ColumnDefinition Width="44*"/>
            <ColumnDefinition Width="45*"/>
            <ColumnDefinition Width="45*"/>
            <ColumnDefinition Width="44*"/>
            <ColumnDefinition Width="44*"/>
            <ColumnDefinition Width="43*"/>
            <ColumnDefinition Width="47*"/>
            <ColumnDefinition Width="44*"/>
            <ColumnDefinition Width="42*"/>
            <ColumnDefinition Width="45*"/>
            <ColumnDefinition Width="13*"/>


        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>

            <RowDefinition Height="50*"/>
            <RowDefinition Height="46*"/>
            <RowDefinition Height="44*"/>
            <RowDefinition Height="42*"/>
            <RowDefinition Height="45*"/>
            <RowDefinition Height="45*"/>
            <RowDefinition Height="44*"/>
            <RowDefinition Height="44*"/>
            <RowDefinition Height="43*"/>
            <RowDefinition Height="46*"/>
            <RowDefinition Height="45*"/>
            <RowDefinition Height="41*"/>
            <RowDefinition Height="45*"/>
            <RowDefinition Height="45*"/>
            <RowDefinition Height="45*"/>
            <RowDefinition Height="44*"/>
            <RowDefinition Height="46*"/>
            <RowDefinition Height="11*"/>

        </Grid.RowDefinitions>

        <Button Grid.ColumnSpan="1" Content="" Grid.Column="5" Grid.Row="0" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_001" Click="anyButtonClicked" />
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="6" Grid.Row="0" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_002" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="7" Grid.Row="0" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_003" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="4" Grid.Row="1" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_004" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="5" Grid.Row="1" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_005" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="6" Grid.Row="1" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_006" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="7" Grid.Row="1" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_007" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="8" Grid.Row="1" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_008" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="4" Grid.Row="2" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_009" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="5" Grid.Row="2" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_010" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="6" Grid.Row="2" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_011" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="7" Grid.Row="2" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_012" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="8" Grid.Row="2" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_013" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="9" Grid.Row="2" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_014" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="4" Grid.Row="3" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_015" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="5" Grid.Row="3" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_016" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="6" Grid.Row="3" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_017" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="7" Grid.Row="3" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_018" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="8" Grid.Row="3" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_019" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="9" Grid.Row="3" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_020" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="2" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_021" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="3" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_022" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="4" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_023" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="5" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_024" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="6" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_025" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="7" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_026" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="8" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_027" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="9" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_028" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="10" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_029" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="11" Grid.Row="4" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_030" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="1" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_031" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="2" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_032" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="3" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_033" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="4" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_034" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="5" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_035" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="6" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_036" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="7" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_037" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="8" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_038" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="9" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_039" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="10" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_040" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="11" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_041" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="12" Grid.Row="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_042" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="1" Grid.Row="6" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_043" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="2" Grid.Row="6" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_044" Click="anyButtonClicked"/>
        <Button Grid.ColumnSpan="1" Content="" Grid.Column="3" Grid.Row="6" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Width="auto" Height="auto" Opacity="0" Name="one_045" Click="anyButtonClicked"/>









        <!--<CheckBox  Content="2003:IKONOS" Name="y3" HorizontalAlignment="Stretch"  Grid.Row="1" VerticalAlignment="Center" Grid.Column="1" Height="auto" Width="auto"   Style="{StaticResource myCheckboxStyle}" Grid.ColumnSpan="4" FontWeight="Bold" FontSize="18" Foreground="White"/>-->
        <RadioButton  Content="2003:IKONOS" Name="y3" HorizontalAlignment="Stretch"  Grid.Row="1" VerticalAlignment="Center" Grid.Column="1" Height="auto" Width="auto"    Grid.ColumnSpan="4" FontWeight="Bold" FontSize="18" Foreground="White"/>
        <!--<RadioButton Content="2007:QUICKBIRD"  Name="y7"  HorizontalAlignment="Stretch"  Grid.Row="2" VerticalAlignment="Center" Grid.Column="1" Height="auto" Width="auto"    Grid.ColumnSpan="4" FontWeight="Bold" FontSize="18" Foreground="White" />-->
        <RadioButton Content="2014:GEOEYE"  Name="y14" HorizontalAlignment="Stretch"  Grid.Row="3" VerticalAlignment="Center" Grid.Column="1" Height="auto" Width="auto"   Grid.ColumnSpan="4" FontWeight="Bold" FontSize="18" Foreground="White" />
        <pages:SwitcherMenu Grid.Row="0" Grid.ColumnSpan="30" Height="20" VerticalAlignment="Top" Width="auto"/>



    </Grid>
</UserControl>
DalLake.cs中的

代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace HmiLike.Pages
{
    /// <summary>
    /// Interaction logic for DalLake.xaml
    /// </summary>
    public partial class DalLake : UserControl
    {
        public DalLake()
        {
            InitializeComponent();
        }
        private void anyButtonClicked(object sender, RoutedEventArgs e)
        {

            //CHECKING WHICH CheckBox isChecked

            if (y3.IsChecked == true)
            {


                var source = e.OriginalSource as FrameworkElement;

                if (source == null)
                    return;
                Year2003 Year2003_Window = new Year2003();


                string imagename = "Images\\"+"Dal\\"+"y3\\" + source.Name.ToString() + ".jpg";
                //Year2003_Window.win2label.Content = imagename;
                Year2003_Window.gridimage.Source = new BitmapImage(new Uri(imagename, UriKind.Relative));
                Year2003_Window.Show();


            }
            //else if (y7.IsChecked == true)
            //{

            //    var source = e.OriginalSource as FrameworkElement;

            //    if (source == null)
            //        return;
            //    Year2007 Year2007_Window = new Year2007();


            //    string imagename = "Images\\" + "Dal\\" + "y7\\" + source.Name.ToString() + ".jpg";
            //    //Year2007_Window.win2label.Content = imagename;
            //    Year2007_Window.gridimage.Source = new BitmapImage(new Uri(imagename, UriKind.Relative));
            //    Year2007_Window.Show();

            //    Year2007_Window.Show();
            //}
            else if (y14.IsChecked == true)
            {

                var source = e.OriginalSource as FrameworkElement;

                if (source == null)
                    return;
                Year2014 Year2014_Window = new Year2014();


                string imagename = "Images\\" + "Dal\\" + "y14\\" + source.Name.ToString() + ".jpg";

                Year2014_Window.gridimage.Source = new BitmapImage(new Uri(imagename, UriKind.Relative));
                Year2014_Window.Show();

                Year2014_Window.Show();
            }



        }
    }
}

继承了我添加的清单文件中的代码

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">

        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>

    </application>
  </compatibility>



</asmv1:assembly>

1 个答案:

答案 0 :(得分:0)

您的Visual Studio在尝试创建清单文件时崩溃,因为您的清单文件变大了。

根据this article,您应该更改图片的build mode

我会尝试构建模式“资源”,但我无法测试它。