Deal with poorly sized images. Make an X sprite showing an error instead of crashing out.

This commit is contained in:
Tim Young 2017-10-10 13:25:24 -05:00
parent 244ab8373f
commit ccdc4e0dd6
4 changed files with 37 additions and 2 deletions

View File

@ -61,8 +61,8 @@ namespace SpriteLibrary.Properties {
}
/// <summary>
/// Looks up a localized string similar to {\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f34\fbidi \froman\fcharset0\fprq2{\*\panose 00000000000000000000}Cambria Math;}
///{\f39\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\f40\fbidi \fmodern\fcharset0\fprq1{\*\panose 020b0609020204030204}Consolas;}{\flomajor [rest of string was truncated]&quot;;.
/// Looks up a localized string similar to {\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f34\fbidi \froman\fcharset1\fprq2{\*\panose 02040503050406030204}Cambria Math;}
///{\f39\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\f40\fbidi \fmodern\fcharset0\fprq1{\*\panose 00000000000000000000}Consolas;}{\flomajor [rest of string was truncated]&quot;;.
/// </summary>
internal static string ChangeLog {
get {
@ -89,5 +89,15 @@ namespace SpriteLibrary.Properties {
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap X {
get {
object obj = ResourceManager.GetObject("X", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -94,6 +94,17 @@ namespace SpriteLibrary
y += height;
x = 0;
}
//If we managed to send it a bad size or something and we could not make a single image.
if(Frames.Count ==0)
{
Bitmap tImage = new Bitmap(width, height);
Image XImage = Properties.Resources.X;
Graphics.FromImage(tImage).DrawImage(Properties.Resources.X,0,0,tImage.Width,tImage.Height);
AnimationSingleFrame newSingle = new AnimationSingleFrame(tImage, Smart_Image.FrameCount);
AnimationFrame newFrame = new AnimationFrame(Smart_Image.FrameCount, TimeSpan.FromMilliseconds(duration));
Frames.Add(newFrame);
Smart_Image.AddFrame(newSingle);
}
}
/// <summary>
@ -131,6 +142,17 @@ namespace SpriteLibrary
y += height;
x = 0;
}
//If we managed to send it a bad size or something and we could not make a single image.
if (Frames.Count == 0)
{
Bitmap tImage = new Bitmap(width, height);
Image XImage = Properties.Resources.X;
Graphics.FromImage(tImage).DrawImage(Properties.Resources.X, 0, 0, tImage.Width, tImage.Height);
AnimationSingleFrame newSingle = new AnimationSingleFrame(tImage, Smart_Image.FrameCount);
AnimationFrame newFrame = new AnimationFrame(Smart_Image.FrameCount, TimeSpan.FromMilliseconds(duration));
Frames.Add(newFrame);
Smart_Image.AddFrame(newSingle);
}
}
internal Animation(SmartImage Smart_Image, int AnimationToCopy, bool MirrorHorizontally, bool MirrorVertically)

View File

@ -89,6 +89,9 @@
<None Include="Resources\licence.rtf" />
<None Include="Resources\SLIcon.ico" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\X.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.