Skip to content

Commit

Permalink
Bug fixes, v1.2.4.
Browse files Browse the repository at this point in the history
Fixed a bug caused by non-standard encoded images.
You just add <bitmapImage.CreateOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;>
i dont understanddddddd
  • Loading branch information
ChiNoel-osu committed Jan 4, 2023
1 parent fbc89e7 commit aaad645
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
31 changes: 30 additions & 1 deletion App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System;
using System.Globalization;
using System.Threading.Tasks;
using System.Windows;

Expand All @@ -11,6 +12,12 @@ public partial class App : Application
{
public App()
{
#if DEBUG
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Dispatcher.UnhandledException += Dispatcher_UnhandledException;
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
#endif
#region Load settings.
try
{
Expand All @@ -23,5 +30,27 @@ public App()
}
#endregion
}

#if DEBUG
private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{
throw new NotImplementedException();
}

private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}

private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}

public void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}
#endif
}
}
2 changes: 1 addition & 1 deletion FolderThumbnailExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ApplicationIcon>icon.ico</ApplicationIcon>
<IsPublishable>False</IsPublishable>
<SignAssembly>False</SignAssembly>
<Version>1.2.3</Version>
<Version>1.2.4</Version>
<Authors>Victor</Authors>
<Copyright>GNU AFFERO GENERAL PUBLIC LICENSE</Copyright>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
Expand Down
2 changes: 1 addition & 1 deletion View/ImageControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ private void AOTBtn_Changed(object sender, RoutedEventArgs e)
};
}
#endregion
}
}
}
14 changes: 13 additions & 1 deletion ViewModel/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public void ReGetContent()
using (FileStream stream = File.OpenRead(firstFilePath))
{ //Use stream sourec instead of regular uri source to improve responsiveness.
bitmap.BeginInit();
//This will fix badly encoded images.
bitmap.CreateOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;
//Use BitmapCacheOption.OnLoad to even make it display.
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = stream;
Expand All @@ -194,11 +196,21 @@ public void ReGetContent()
bitmap.UriSource = new Uri("pack://application:,,,/folder.png");
bitmap.EndInit();
}
//catch(ArgumentException)
//{ //Bad encoded image? Fixed with bitmap.CreateOptions.
// GC.Collect();
// continue;
//}
catch (System.Runtime.InteropServices.COMException)
{
GC.Collect();
continue; //Stupid cloud storages, skip.
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "im ded", MessageBoxButton.OK, MessageBoxImage.Warning);
continue;
}
finally //This is VITAL for it to be passed between threads.
{ bitmap.Freeze(); }
}
Expand Down Expand Up @@ -247,7 +259,7 @@ public void SubfolderIconClicked(string folderName)
PATHtoShow = PATHtoShow.EndsWith('\\') ? string.Format("{0}{1}", PATHtoShow, folderName) : string.Format("{0}\\{1}", PATHtoShow, folderName);
}

private void ThumbnailMouseUpHandler(object sender, MouseButtonEventArgs e) //Open Photo Viewer or advance path.
private void ThumbnailMouseUpHandler(object sender, MouseButtonEventArgs e) //Open Photo Viewer or advance path.
{
string imageFolder = ((Image)sender).ToolTip.ToString();
if (e.ChangedButton == MouseButton.Left)
Expand Down
3 changes: 3 additions & 0 deletions ViewModel/PhotoViewerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public CustomListItem SelectedImg //Load the image
{
_BigImage = new BitmapImage();
_BigImage.BeginInit();
_BigImage.CreateOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;
_BigImage.CacheOption = BitmapCacheOption.OnLoad;
_BigImage.StreamSource = stream;
_BigImage.EndInit();
Expand All @@ -104,6 +105,7 @@ public CustomListItem SelectedImg //Load the image
{
_BigImage2 = new BitmapImage();
_BigImage2.BeginInit();
_BigImage2.CreateOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;
_BigImage2.CacheOption = BitmapCacheOption.OnLoad;
_BigImage2.StreamSource = stream;
_BigImage2.EndInit();
Expand Down Expand Up @@ -232,6 +234,7 @@ private void AddImgs(string path)
using (FileStream stream = File.OpenRead(img.Value))
{
bitmapImage.BeginInit();
bitmapImage.CreateOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = stream;
bitmapImage.DecodePixelWidth = 128; //TODO: make it configurable.
Expand Down

0 comments on commit aaad645

Please sign in to comment.