wpf错误内存不足,无法在visual studio 2012中继续执行
我是wpf新手,我正在开发一个非常简单的应用程序。 我有一个窗口,我在其中放置了一个dockpanel,dockpanel有两个菜单 “操作->关于、帮助、退出” & “区域->区域1、区域2、区域3” 单击区域菜单中的区域1,我将在同一窗口中加载用户控件。此用户控件具有网格。整个网格分为40行和40列,网格的背景是一个图像,它跨越整个网格。实际上,我的想法是将图像分成160个相等的正方形,可以点击。 在40交叉40网格的每个单元格中,我放置了一个透明按钮,其递增名称为b1、b2、b3…直至b160。单击任意按钮时,执行方法anybuttonclick(我在后面的代码中定义了该方法) 我在解决方案目录中的一个单独文件夹中也有160个单独的高分辨率图像,所有这些图像的名称也都放在b1.jpg、b2.jpg、b3.jpg中。。高达b160.jpg!!! 在代码隐藏中,我使用了anybuttonclick方法,在该方法中,我获得了用户单击的按钮的名称,借助于此,我可以决定在新窗口中加载哪个图像。例如,如果用户单击b35,我将在新窗口中加载图像b35.jpg。。新窗口中的此图像是高分辨率图像(单元格1的缩放版本) 我在2区也有同样的事情。。 到目前为止,area1文件夹中的图像大小为670 mb,图像数量为160 区域2文件夹I中的图像大小为785 mb,图像数量为160 一切正常。只有在我尝试对区域3执行相同操作时,问题才会出现。i、 e当我尝试将区域3的高分辨率图像复制到名为“images3”的文件夹中时 area3文件夹中的图像数为160,图像大小为783 mb 我有时会在运行时遇到错误,比如outofmemory异常。有时它会说内存不足,无法继续执行。 然后我删除区域3的图像(每个区域有160个图像),这样我就能够正确地调试项目了。 我试图发布只有两个区域的应用程序。并在我的系统上进行了测试。工作正常。(英特尔core i5 2.4 ghz 16 gb ram windows 7 32位,visual studio 2012) 但当我将同一个发布的应用程序传输到我的笔记本电脑(英特尔core i7 2.4 ghz,4 gb ram windows 7 32位,visual studio 2012)时,该应用程序在安装时崩溃 我的问题是我对wpf有什么错?我们可以处理的图像数量或大小是否有任何限制?我尝试将修补程序应用到v2012,但仍然存在相同的问题。在解决方案目录中包含大量图像时,开发此类应用程序的最佳实践是什么。我不想使用sql存储图像,因为我不想在图像质量上妥协 DalLake.xaml中的代码wpf错误内存不足,无法在visual studio 2012中继续执行,wpf,visual-studio-2012,out-of-memory,runtime-error,Wpf,Visual Studio 2012,Out Of Memory,Runtime Error,我是wpf新手,我正在开发一个非常简单的应用程序。 我有一个窗口,我在其中放置了一个dockpanel,dockpanel有两个菜单 “操作->关于、帮助、退出” & “区域->区域1、区域2、区域3” 单击区域菜单中的区域1,我将在同一窗口中加载用户控件。此用户控件具有网格。整个网格分为40行和40列,网格的背景是一个图像,它跨越整个网格。实际上,我的想法是将图像分成160个相等的正方形,可以点击。 在40交叉40网格的每个单元格中,我放置了一个透明按钮,其递增名称为b1、b2、b3…直至b
<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();
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间类似于.Pages
{
///
///DalLake.xaml的交互逻辑
///
公共部分类DalLake:UserControl
{
公共图书馆()
{
初始化组件();
}
private void anybutton已选中(对象发送方,RoutedEventArgs e)
{
//检查选中了哪个复选框
如果(y3.IsChecked==true)
{
var source=e.OriginalSource作为框架元素;
if(source==null)
返回;
Year2003 Year2003_Window=new Year2003();
字符串imagename=“Images\\”+“Dal\\”+“y3\\”+source.Name.ToString()+“.jpg”;
//Year2003_Window.win2label.Content=imagename;
Year2003_Window.gridimage.Source=新的位图图像(新的Uri(imagename,UriKind.Relative));
Year2003_Window.Show();
}
//else if(y7.IsChecked==true)
//{
//var source=e.OriginalSource作为框架元素;
//if(source==null)
//返回;
//Year2007 Year2007_Window=new Year2007();
//字符串imagename=“Images\\”+“Dal\\”+“y7\\”+source.Name.ToString()+“.jpg”;
////Year2007_Window.win2label.Content=imagename;
//Year2007_Window.gridimage.Source=新的位图图像(新的Uri(imagename,UriKind.Relative));
//Year2007_Window.Show();
//Year2007_Window.Show();
//}
else if(y14.IsChecked==true)
{
var source=e.OriginalSource作为框架元素;
if(source==null)
返回;
Year2014 Year2014_Window=new Year2014();
<?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>