我是wpf中的新手,我正在開發一個使用相同的非常簡單的應用程序。 我有,我已經把DockPanel中的窗口,在DockPanel中有兩個菜單,wpf錯誤內存不足,無法在visual studio 2012中繼續執行
「動作 - >關於,幫助,退出」 & 「區域 - >區域1,區域2,Area3中」
點擊區域菜單中的區域1時,我在同一窗口中加載用戶控件。這個用戶控件有一個網格。整個網格被劃分爲40列,其中網格的背景是跨越整個網格的圖像。實際上我想把圖像分成160個可以點擊的相等方格。 在40交叉40網格的每個單元格中,我放了一個透明按鈕,增量名稱如b1,b2,b3 ... upto b160。在任何按鈕上執行anybuttonclick方法(我在後面的代碼中定義) 我也有160個獨立的高分辨率圖像在解決方案目錄中的單獨文件夾中,所有這些圖像的名稱也被放在b1.jpg中, b2.jpg,b3.jpg .. upto b160.jpg !!! 在代碼後面我已經把anybuttonclick方法,其中我得到的用戶點擊按鈕的名稱,並藉助於此,我能夠決定在新窗口中加載哪個圖像。例如,如果用戶單擊b35,我會在新窗口中加載圖像b35.jpg。此圖像在新窗口中是高分辨率圖像(單元格1的縮放版本)。
我打倒面積2同樣的事情.. 高達區域1中的圖像文件夾,這裏的大小爲670 MB和圖像的數量是160 而在區域2圖像文件夾的大小我785 MB和iamges數量是160
一切工作正常。只有當我嘗試爲area3做同樣的事情時,問題纔會出現。即當我嘗試將area3的高分辨率圖像複製到名爲「images3」的文件夾中時 area3文件夾中的圖像數量爲160,圖像大小爲783 mb我在運行時發現內存異常時發生錯誤。有時它說內存不足以繼續執行。 然後刪除area3的圖像(每個區域有160個圖像),我可以正確調試項目。 我試圖僅用兩個區域發佈應用程序。並在我的系統上進行測試。它工作正常。(英特爾酷睿i5 2.4 Ghz 16 GB RAM RAM的Windows 7 32位,視覺工作室2012) 但是,當我將相同的已發佈的應用程序傳遞到我的筆記本電腦(英特爾酷睿i7 2.4 GHz,4 GB RAM RAM 7 32位,視覺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>
問題不在WPF中。如果使用正確,對使用圖像的數量或大小沒有限制。 爲了澄清你所要求的: 1)有3倍大的圖像 2)如果用戶點擊了在版本放大示出了圖像的一部分 3)將所述縮放圖像的3圖像你後用完了RAM 對不對? 什麼應用程序崩潰你的VS或VS? 問題可能出在您加載圖像的方式上,但我無法從您提供的內容中知曉。請添加一些源代碼;尤其是anybuttonclick – ChronosMOT
我已添加圖片和代碼。感謝您的幫助 –