Commit ba93b572 by David Neumaier

init

parents
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
</configuration>
\ No newline at end of file
This diff is collapsed. Click to expand it.
using System;
using System.IO;
using System.Diagnostics;
using Pgm;
class PgmCreatorDemo {
//TYPICAL USAGE OF THE PGMCREATOR CLASS:
static void MakeLenaBlackWhite() {
// for the specification of PGM-Files, see: http://netpbm.sourceforge.net/doc/pgm.html
// A byte-array is used for storing the gray-color-values.
// The img has the size 256x256 pixel;
// Each pixel has a gray-color-value from 0-255 (0...black, 255...white).
// Note also that the FIRST dimension (row-index) corresponds
// to the x-Coordinate (!!!) in the image, the second dimension (col-index)
// to the y-coordinate (!!!). The y coordinate goes from up to down!
// Thus, an index of [50, 250] is at the left and bottom of the image.
// (The Write/ReadPGM-Methods internally transpose the matrix.)
// Open Lena, make it black-white (threshold is the value 128), and save it:
try {
byte[,] lenaImgData = PgmCreator.ReadPgmFile("lena.pgm");
for (int x = 0; x < lenaImgData.GetLength(0); x++) {
for (int y = 0; y < lenaImgData.GetLength(1); y++) {
if (lenaImgData[x, y] < 128) lenaImgData[x, y] = 0;
else lenaImgData[x, y] = 255;
}
}
PgmCreator.WritePgmFile("lena_black_white.pgm", lenaImgData, PgmType.P5);
Console.WriteLine("Success making Lena black-white!");
}
catch (FileNotFoundException e) {
Console.WriteLine("Where ist the file? " + e.Message);
}
catch (FormatException e) {
Console.WriteLine("Wrong file format: " + e.Message);
}
catch (Exception e) {
Console.WriteLine(e.Message);
}
}
static void Main(string[] args) {
TestBinaryAndASCIIFormat();
MakeLenaBlackWhite();
}
//Helper Method which produces a byte-array representing a gradient image:
private static byte[,] ProduceGradientImage() {
byte[,] imgData = new byte[256, 256];
// fill the imgData-Array with the gray-color-values:
for (int y = 0; y < imgData.GetLength(1); y++) {
for (int x = 0; x < imgData.GetLength(0); x++) {
// produce a gray-color gradient image:
// top-left corner: black, bottom-right corner: white.
// Note that x and y go from 0 to 255, so x/2 + y/2 cannot exceed the value 254.
imgData[x, y] = (byte)(x / 2 + y / 2);
}
}
return imgData;
}
//Tests whether both pgm file formats work:
private static void TestBinaryAndASCIIFormat() {
byte[,] imgData = ProduceGradientImage();
byte[,] readDataAscii;
byte[,] readDataBinary;
try {
// write imgData to P2 file (ascii):
PgmCreator.WritePgmFile("testASCII.pgm", imgData, PgmType.P2);
// read from P2 file (ascii):
readDataAscii = PgmCreator.ReadPgmFile("testASCII.pgm");
// write image data to P5 file (binary):
PgmCreator.WritePgmFile("testBinary.pgm", readDataAscii, PgmType.P5);
// read P5 file (binary):
readDataBinary = PgmCreator.ReadPgmFile("testBinary.pgm");
//check if the image loaded from the P2-type file (ascii)
//is the same as from the P5-type file (binary):
for (int y = 0; y < imgData.GetLength(1); y++) {
for (int x = 0; x < imgData.GetLength(0); x++) {
Debug.Assert(readDataAscii[x,y] == readDataBinary[x,y]);
}
}
Console.WriteLine("Success in testing two generated files of both types!");
} catch (Exception e) {
Console.WriteLine(e.Message);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace task_78
{
class Program
{
static void Main(string[] args) {
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("task_78")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("task_78")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ddc7d81a-b435-4906-9a02-b2560d46f755")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
File added
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DDC7D81A-B435-4906-9A02-B2560D46F755}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>task_78</RootNamespace>
<AssemblyName>task_78</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "task_78", "task_78.csproj", "{DDC7D81A-B435-4906-9A02-B2560D46F755}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DDC7D81A-B435-4906-9A02-B2560D46F755}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDC7D81A-B435-4906-9A02-B2560D46F755}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDC7D81A-B435-4906-9A02-B2560D46F755}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDC7D81A-B435-4906-9A02-B2560D46F755}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment