Skip to content

Commit

Permalink
Update 1-17-17
Browse files Browse the repository at this point in the history
- Changed file directory name
- Added fixed aspect ratio check box
  • Loading branch information
Whiplash141 committed Jan 17, 2017
1 parent f728759 commit 328a90b
Show file tree
Hide file tree
Showing 36 changed files with 158 additions and 38 deletions.
2 changes: 1 addition & 1 deletion WindowsForms2.sln → WhipsImageConverter.sln
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WhipsImageConverter", "WindowsForms2\WhipsImageConverter.csproj", "{9643C76C-617C-4B4B-AAB9-ABDB489E2AAD}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WhipsImageConverter", "WhipsImageConverter\WhipsImageConverter.csproj", "{9643C76C-617C-4B4B-AAB9-ABDB489E2AAD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -8,7 +8,7 @@
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms2
namespace WhipsImageConverter
{
public partial class DitheringPopup : Form
{
Expand All @@ -21,19 +21,19 @@ public DitheringPopup(int mode)
private void ShowImages(int mode)
{
/*var assembly = System.Reflection.Assembly.GetExecutingAssembly();
using (var imgStream = assembly.GetManifestResourceStream("WindowsForms2.original.png"))
using (var imgStream = assembly.GetManifestResourceStream("WhipsImageConverter.original.png"))
{
var img = new Bitmap(imgStream);
OriginalBox.Image = img;
}
using (var imgStream = assembly.GetManifestResourceStream("WindowsForms2.dithering.png"))
using (var imgStream = assembly.GetManifestResourceStream("WhipsImageConverter.dithering.png"))
{
var img = new Bitmap(imgStream);
DitherBox.Image = img;
}
using (var imgStream = assembly.GetManifestResourceStream("WindowsForms2.nodithering.png"))
using (var imgStream = assembly.GetManifestResourceStream("WhipsImageConverter.nodithering.png"))
{
var img = new Bitmap(imgStream);
NoDitherBox.Image = img;
Expand Down
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -13,7 +13,7 @@

//Reference: http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT

namespace WindowsForms2
namespace WhipsImageConverter
{
public partial class ImageToLCD : Form
{
Expand Down Expand Up @@ -68,12 +68,119 @@ void CacheImages()
}

baseImage = (Bitmap)Image.FromFile(fileDirectory, true);
squareImage = new Bitmap(baseImage, new Size(178, 178));
rectangleImage = new Bitmap(baseImage, new Size(356, 178));

bool maintainAspectRatio = checkBox_aspectratio.Checked; //default is false

if (!maintainAspectRatio)
{
squareImage = new Bitmap(baseImage, new Size(178, 178));
rectangleImage = new Bitmap(baseImage, new Size(356, 178));
}
else
{
squareImage = FrameImage(baseImage, 178, 178);
rectangleImage = FrameImage(baseImage, 356, 178);
}

imageLoaded = true;
}

Bitmap FrameImage(Bitmap baseImage, int width, int height)
{
Bitmap framedImage;
int borderThickness = 0;
float compressionRatio = 1;
int borderMode = 0; //0 = none; 1 = horizontal; 2 = vertical bars
int desiredWidth = 0;
int desiredHeight = 0;


framedImage = new Bitmap(width, height);
if ((float)baseImage.Width / width > (float)baseImage.Height / height) //horizontal bars
{
desiredWidth = width;
compressionRatio = (float)width / baseImage.Width;
desiredHeight = (int)(baseImage.Height * compressionRatio);

borderThickness =Math.Abs(desiredHeight - height) / 2;
borderMode = 1;
}
else if ((float)baseImage.Width / width == (float)baseImage.Height / height)
{
borderMode = 0;
desiredWidth = width;
desiredHeight = height;
}
else //vertical bars
{
desiredHeight = height;
compressionRatio = (float)height / baseImage.Height;
desiredWidth = (int)(baseImage.Width * compressionRatio);

borderThickness = Math.Abs(desiredWidth - width) / 2;
borderMode = 2;
}

if (borderThickness == 0)
{
borderMode = 0;
}

Bitmap imageNoBorder = new Bitmap(baseImage, new Size(desiredWidth, desiredHeight));
Bitmap border;

switch (borderMode)
{
case 0:
framedImage = imageNoBorder;
break;

case 1: // horizontal bars
border = new Bitmap(width, borderThickness);

for (int w = 0; w < width; w++)
{
for (int h = 0; h < height; h++)
{
if (h < borderThickness)
{
framedImage.SetPixel(w, h, border.GetPixel(w, h));
}
else
{
if (h - borderThickness < imageNoBorder.Height)
framedImage.SetPixel(w, h, imageNoBorder.GetPixel(w, h - borderThickness));
}
}
}

break;

case 2: //vertical bars
border = new Bitmap(borderThickness, height);

for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
if (w < borderThickness)
{
framedImage.SetPixel(w, h, border.GetPixel(w, h));
}
else
{
if (w - borderThickness < imageNoBorder.Width)
framedImage.SetPixel(w, h, imageNoBorder.GetPixel(w - borderThickness, h));
}
}
}

break;
}

return framedImage;
}

void DitherImage()
{
if (!imageLoaded)
Expand Down Expand Up @@ -1535,5 +1642,14 @@ private void combobox_resize_SelectedIndexChanged(object sender, EventArgs e)

DitherImage();
}

private void checkBox_aspectratio_CheckedChanged(object sender, EventArgs e)
{
//reset return string
textBox_Return.Text = "";

CacheImages();
DitherImage();
}
}
}
File renamed without changes.
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms2
namespace WhipsImageConverter
{
static class Program
{
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{9643C76C-617C-4B4B-AAB9-ABDB489E2AAD}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WindowsForms2</RootNamespace>
<AssemblyName>Whips Image Converter</AssemblyName>
<RootNamespace>WhipsImageConverter</RootNamespace>
<AssemblyName>Whip`s Image Converter</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -8,7 +8,7 @@
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms2
namespace WhipsImageConverter
{
public partial class popup_credits : Form
{
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -11,7 +11,7 @@
using System.IO;
using System.Numerics;

namespace WindowsForms2
namespace WhipsImageConverter
{
public partial class popup_imagebox : Form
{
Expand Down
File renamed without changes.
Binary file removed WindowsForms2/bin/Debug/Whips Image Converter.exe
Binary file not shown.
6 changes: 0 additions & 6 deletions WindowsForms2/bin/Debug/Whips Image Converter.exe.config

This file was deleted.

Binary file removed WindowsForms2/bin/Debug/Whips Image Converter.pdb
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file removed WindowsForms2/bin/Release/Whips Image Converter.exe
Binary file not shown.

0 comments on commit 328a90b

Please sign in to comment.