This commit is contained in:
2012-09-02 15:24:38 +02:00
commit 5b667b5781
250 changed files with 70477 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
using System;
using System.IO;
using FreeImageAPI;
namespace Sample02
{
class Program
{
static void Main(string[] args)
{
// Check if FreeImage.dll is available (can be in %path%).
if (!FreeImage.IsAvailable())
{
Console.WriteLine("FreeImage.dll seems to be missing. Aborting.");
return;
}
Sample sample = new Sample();
sample.Example();
}
}
public class Sample
{
const string fileName = @"multipaged.tif";
FIMULTIBITMAP dib = new FIMULTIBITMAP();
Random rand = new Random();
public void Example()
{
if (!File.Exists(fileName))
{
Console.WriteLine("File not found. Aborting.");
return;
}
// Load the multipaged bitmap.
// 'OpenMultiBitmapEx' tries to find the correct file format, loads the bitmap
// with default options, with write support and does not use caching.
dib = FreeImage.OpenMultiBitmapEx(fileName);
// Check whether loading succeeded.
if (dib.IsNull)
{
Console.WriteLine("File could not be loaded. Aborting.");
return;
}
// Get the number of bitmaps the multipaged bitmap contains.
int count = FreeImage.GetPageCount(dib);
// Multipaged bitmaps consist of multiple single FIBITMAPs
FIBITMAP page = new FIBITMAP();
// There are bitmaps we can work with.
if (count > 0)
{
// Lock a random bitmap to work with.
page = FreeImage.LockPage(dib, rand.Next(0, count));
}
// Check whether locking succeeded.
if (page.IsNull)
{
// Locking failed. Unload the bitmap and return.
FreeImage.CloseMultiBitmapEx(ref dib);
return;
}
// Get a list of locked pages. This can be usefull to check whether a page has already been locked.
int[] lockedPages = FreeImage.GetLockedPages(dib);
// Lets modify the page.
if (FreeImage.AdjustGamma(page, 2d))
{
Console.WriteLine("Successfully changed gamma of page {0}.", lockedPages[0]);
}
else
{
Console.WriteLine("Failed to adjust gamma ...");
}
// Print out the list of locked pages
foreach (int i in lockedPages)
Console.WriteLine("Page {0} is locked.", i);
// Use 'UnlockPage' instead of 'Unload' to free the page. Set the third parameter to 'true'
// so that FreeImage can store the changed page within the multipaged bitmap.
FreeImage.UnlockPage(dib, page, true);
// Retieve the list again to see whether unlocking succeeded.
lockedPages = FreeImage.GetLockedPages(dib);
// No output should be produced here.
foreach (int i in lockedPages)
Console.WriteLine("Page {0} is still locked.", i);
// If there are more than one page we can swap them
if (count > 1)
{
if (!FreeImage.MovePage(dib, 1, 0))
{
Console.WriteLine("Swapping pages failed.");
}
}
if (count > 2)
{
// Lock page 2
page = FreeImage.LockPage(dib, 2);
if (!page.IsNull)
{
// Clone the page for later appending
FIBITMAP temp = FreeImage.Clone(page);
// Unlock the page again
FreeImage.UnlockPage(dib, page, false);
// Delete the page form the multipaged bitmap
FreeImage.DeletePage(dib, 2);
// Append the clone again
FreeImage.AppendPage(dib, temp);
// Check whether the number of pages is still the same
Console.WriteLine("Pages before: {0}. Pages after: {1}", count, FreeImage.GetPageCount(dib));
// Unload clone to prevent memory leak
FreeImage.UnloadEx(ref temp);
}
}
// We are done and close the multipaged bitmap.
if (!FreeImage.CloseMultiBitmapEx(ref dib))
{
Console.WriteLine("Closing bitmap failed!");
}
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("35960522-c01a-40d2-a86b-37b9839b131c")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,95 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AF8B72BD-1A8B-4E6B-A0F1-0BD57497777B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample02</RootNamespace>
<AssemblyName>Sample02</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="FreeImageNET, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Bin\FreeImageNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="multipaged.tif">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\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>