import
This commit is contained in:
@@ -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("dc891ffc-ab5c-451f-97da-2c0d5d90edcc")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,108 @@
|
||||
<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>{491042DB-495B-420C-A3BE-5D13019707C5}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Sample08</RootNamespace>
|
||||
<AssemblyName>Sample08</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" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SampleForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SampleForm.Designer.cs">
|
||||
<DependentUpon>SampleForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="SerializationPlugin.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Sample.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="SampleForm.resx">
|
||||
<DependentUpon>SampleForm.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</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>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 123 KiB |
@@ -0,0 +1,119 @@
|
||||
namespace Sample08
|
||||
{
|
||||
partial class SampleForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Erforderliche Designervariable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Verwendete Ressourcen bereinigen.
|
||||
/// </summary>
|
||||
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Vom Windows Form-Designer generierter Code
|
||||
|
||||
/// <summary>
|
||||
/// Erforderliche Methode für die Designerunterstützung.
|
||||
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.bLoad = new System.Windows.Forms.Button();
|
||||
this.SaveToSer = new System.Windows.Forms.Button();
|
||||
this.LoadSerBitmap = new System.Windows.Forms.Button();
|
||||
this.bClearBitmap = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.pictureBox.Location = new System.Drawing.Point(12, 12);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(600, 400);
|
||||
this.pictureBox.TabIndex = 0;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// bLoad
|
||||
//
|
||||
this.bLoad.Location = new System.Drawing.Point(12, 418);
|
||||
this.bLoad.Name = "bLoad";
|
||||
this.bLoad.Size = new System.Drawing.Size(98, 23);
|
||||
this.bLoad.TabIndex = 1;
|
||||
this.bLoad.Text = "Load any bitmap";
|
||||
this.bLoad.UseVisualStyleBackColor = true;
|
||||
this.bLoad.Click += new System.EventHandler(this.bLoad_Click);
|
||||
//
|
||||
// SaveToSer
|
||||
//
|
||||
this.SaveToSer.Location = new System.Drawing.Point(324, 418);
|
||||
this.SaveToSer.Name = "SaveToSer";
|
||||
this.SaveToSer.Size = new System.Drawing.Size(98, 23);
|
||||
this.SaveToSer.TabIndex = 2;
|
||||
this.SaveToSer.Text = "Save as .ser";
|
||||
this.SaveToSer.UseVisualStyleBackColor = true;
|
||||
this.SaveToSer.Click += new System.EventHandler(this.SaveToSer_Click);
|
||||
//
|
||||
// LoadSerBitmap
|
||||
//
|
||||
this.LoadSerBitmap.Location = new System.Drawing.Point(220, 418);
|
||||
this.LoadSerBitmap.Name = "LoadSerBitmap";
|
||||
this.LoadSerBitmap.Size = new System.Drawing.Size(98, 23);
|
||||
this.LoadSerBitmap.TabIndex = 3;
|
||||
this.LoadSerBitmap.Text = "Load .ser bitmap";
|
||||
this.LoadSerBitmap.UseVisualStyleBackColor = true;
|
||||
this.LoadSerBitmap.Click += new System.EventHandler(this.LoadSerBitmap_Click);
|
||||
//
|
||||
// bClearBitmap
|
||||
//
|
||||
this.bClearBitmap.Location = new System.Drawing.Point(116, 418);
|
||||
this.bClearBitmap.Name = "bClearBitmap";
|
||||
this.bClearBitmap.Size = new System.Drawing.Size(98, 23);
|
||||
this.bClearBitmap.TabIndex = 4;
|
||||
this.bClearBitmap.Text = "Clear screen";
|
||||
this.bClearBitmap.UseVisualStyleBackColor = true;
|
||||
this.bClearBitmap.Click += new System.EventHandler(this.bClearBitmap_Click);
|
||||
//
|
||||
// SampleForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(627, 448);
|
||||
this.Controls.Add(this.bClearBitmap);
|
||||
this.Controls.Add(this.LoadSerBitmap);
|
||||
this.Controls.Add(this.SaveToSer);
|
||||
this.Controls.Add(this.bLoad);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "SampleForm";
|
||||
this.ShowIcon = false;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Sample 08";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.PictureBox pictureBox;
|
||||
private System.Windows.Forms.Button bLoad;
|
||||
private System.Windows.Forms.Button SaveToSer;
|
||||
private System.Windows.Forms.Button LoadSerBitmap;
|
||||
private System.Windows.Forms.Button bClearBitmap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using FreeImageAPI;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace Sample08
|
||||
{
|
||||
public partial class SampleForm : Form
|
||||
{
|
||||
SerializationPlugin serialPlugin;
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// Check if FreeImage is available
|
||||
if (!FreeImage.IsAvailable())
|
||||
{
|
||||
throw new Exception("FreeImage is not available!");
|
||||
}
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new SampleForm());
|
||||
}
|
||||
|
||||
public SampleForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message);
|
||||
|
||||
// Creating a new instance of the plugin will register it automatically.
|
||||
serialPlugin = new SerializationPlugin();
|
||||
}
|
||||
|
||||
void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message)
|
||||
{
|
||||
// Show the message
|
||||
MessageBox.Show(String.Format("Format: {0}\nMessage: {1}", fif, message), "FreeImage Message");
|
||||
}
|
||||
|
||||
private void bLoad_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Create a new dialog instance
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
try
|
||||
{
|
||||
// Apply settings
|
||||
ofd.CheckPathExists = true;
|
||||
ofd.CheckFileExists = true;
|
||||
ofd.RestoreDirectory = true;
|
||||
ofd.Filter = "All files (*.*)|*.*";
|
||||
|
||||
// Get filename
|
||||
if (ofd.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
Bitmap bitmap = null;
|
||||
try
|
||||
{
|
||||
// Try loading the selected file
|
||||
// a ser-file will create an exception
|
||||
bitmap = (Bitmap)Bitmap.FromFile(ofd.FileName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Unable to load bitmap from file.", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
// Unload old bitmap
|
||||
if (pictureBox.Image != null)
|
||||
{
|
||||
pictureBox.Image.Dispose();
|
||||
}
|
||||
|
||||
// Set new bitmap
|
||||
pictureBox.Image = bitmap;
|
||||
MessageBox.Show("Bitmap loaded successfully", "Success");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Action aborted.");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Unload dialog
|
||||
ofd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadSerBitmap_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Creat a new dialog
|
||||
OpenFileDialog ofd = new OpenFileDialog();
|
||||
|
||||
FIBITMAP dib = new FIBITMAP();
|
||||
try
|
||||
{
|
||||
// Apply settings
|
||||
ofd.CheckPathExists = true;
|
||||
ofd.CheckFileExists = true;
|
||||
ofd.RestoreDirectory = true;
|
||||
ofd.Filter = "Serialized bitmap (*.ser)|*.ser";
|
||||
|
||||
// Get filename
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
// Try loading the file forcing the new format
|
||||
dib = FreeImage.Load(serialPlugin.Format, ofd.FileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
|
||||
if (dib.IsNull)
|
||||
{
|
||||
MessageBox.Show("Loading bitmap failed", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the loaded bitmap into a .NET bitmap
|
||||
Bitmap bitmap = FreeImage.GetBitmap(dib);
|
||||
if (bitmap == null)
|
||||
{
|
||||
MessageBox.Show("Converting bitmap failed.", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
// Unload the picturebox
|
||||
if (pictureBox.Image != null)
|
||||
{
|
||||
pictureBox.Image.Dispose();
|
||||
}
|
||||
|
||||
// Apply the loaded bitmap
|
||||
pictureBox.Image = bitmap;
|
||||
MessageBox.Show("Bitmap loaded successfully", "Success");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Action aborted.");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Unload bitmap
|
||||
FreeImage.UnloadEx(ref dib);
|
||||
|
||||
// Unload dialog
|
||||
ofd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToSer_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Create a new dialog
|
||||
SaveFileDialog sfd = new SaveFileDialog();
|
||||
|
||||
FIBITMAP dib = new FIBITMAP();
|
||||
try
|
||||
{
|
||||
// Check if the picture box contains a bitmap that can be saved.
|
||||
if (pictureBox.Image == null)
|
||||
{
|
||||
MessageBox.Show("No bitmap loaded.", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the picture-boxes bitmap into a FreeImage bitmap.
|
||||
dib = FreeImage.CreateFromBitmap((Bitmap)pictureBox.Image);
|
||||
if (dib.IsNull)
|
||||
{
|
||||
MessageBox.Show("Unable to convert bitmap to FIBITMAP.", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply settings
|
||||
sfd.Filter = "Serialized bitmap (*.ser)|*.ser";
|
||||
sfd.FileName = "Bitmap.ser";
|
||||
sfd.OverwritePrompt = true;
|
||||
sfd.RestoreDirectory = true;
|
||||
|
||||
// Get filename
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
// Save bitmap in the new format
|
||||
if (FreeImage.SaveEx(dib, sfd.FileName, serialPlugin.Format))
|
||||
MessageBox.Show("Bitmap saved successfully.", "Success");
|
||||
else
|
||||
MessageBox.Show("Saving bitmap failed.", "Failure");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Action aborted.");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Unload bitmap
|
||||
FreeImage.UnloadEx(ref dib);
|
||||
|
||||
// Unload dialog
|
||||
sfd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void bClearBitmap_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Unload the picture-box
|
||||
if (pictureBox.Image != null)
|
||||
{
|
||||
pictureBox.Image.Dispose();
|
||||
pictureBox.Image = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,222 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using FreeImageAPI;
|
||||
using FreeImageAPI.IO;
|
||||
using FreeImageAPI.Plugins;
|
||||
|
||||
namespace Sample08
|
||||
{
|
||||
public sealed class SerializationPlugin : LocalPlugin
|
||||
{
|
||||
// Header for the file
|
||||
private byte[] header = new byte[] { 0xff, 0x12, 0x0f, 0xff, 0x01, 0x00 };
|
||||
|
||||
// Structure that will store all bitmap data.
|
||||
[Serializable]
|
||||
private struct SerialDib
|
||||
{
|
||||
public uint width;
|
||||
public uint height;
|
||||
public int pitch;
|
||||
public uint bpp;
|
||||
public uint red_mask;
|
||||
public uint green_mask;
|
||||
public uint blue_mask;
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
// Implementation of 'GetImplementedMethods()'
|
||||
// All implemented methods are listed.
|
||||
protected override LocalPlugin.MethodFlags GetImplementedMethods()
|
||||
{
|
||||
return
|
||||
MethodFlags.DescriptionProc |
|
||||
MethodFlags.SupportsExportBPPProc |
|
||||
MethodFlags.SupportsExportTypeProc |
|
||||
MethodFlags.SupportsICCProfilesProc |
|
||||
MethodFlags.LoadProc |
|
||||
MethodFlags.SaveProc |
|
||||
MethodFlags.ValidateProc |
|
||||
MethodFlags.ExtensionListProc;
|
||||
}
|
||||
|
||||
// Returns a format string.
|
||||
protected override string FormatProc()
|
||||
{
|
||||
return "Serialization";
|
||||
}
|
||||
|
||||
// Returns a more specific description
|
||||
protected override string DescriptionProc()
|
||||
{
|
||||
return "Serializes bitmaps for .NET";
|
||||
}
|
||||
|
||||
// Returns whether a color depth is supported.
|
||||
protected override bool SupportsExportBPPProc(int bpp)
|
||||
{
|
||||
return ((bpp == 1) ||
|
||||
(bpp == 4) ||
|
||||
(bpp == 8) ||
|
||||
(bpp == 16) ||
|
||||
(bpp == 24) ||
|
||||
(bpp == 32));
|
||||
}
|
||||
|
||||
// This plugin can only export standard bitmaps
|
||||
protected override bool SupportsExportTypeProc(FREE_IMAGE_TYPE type)
|
||||
{
|
||||
return (type == FREE_IMAGE_TYPE.FIT_BITMAP);
|
||||
}
|
||||
|
||||
// This plugin does not support icc profiles
|
||||
protected override bool SupportsICCProfilesProc()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// The function reads the first bytes of the file and compares it
|
||||
// with the predefined header.
|
||||
protected override bool ValidateProc(ref FreeImageIO io, fi_handle handle)
|
||||
{
|
||||
for (int i = 0; i < header.Length; i++)
|
||||
if (ReadByte(io, handle) != header[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Loading function
|
||||
protected override FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data)
|
||||
{
|
||||
// Check if the data has the correct format
|
||||
if (!ValidateProc(ref io, handle))
|
||||
{
|
||||
// Create a free-image message
|
||||
FreeImage.OutputMessageProc(format, "Invalid format.");
|
||||
// return 0 (operation failed)
|
||||
return FIBITMAP.Zero;
|
||||
}
|
||||
|
||||
SerialDib sdib;
|
||||
int read = 0;
|
||||
System.IO.MemoryStream stream = new System.IO.MemoryStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
do
|
||||
{
|
||||
// Use the helper function 'Read' to read from the source
|
||||
read = Read(io, handle, 1, 1024, ref buffer);
|
||||
|
||||
// Store the data in a temporary buffer
|
||||
stream.Write(buffer, 0, read);
|
||||
}
|
||||
while (read != 0);
|
||||
|
||||
// Set the memory stream back to the beginning.
|
||||
stream.Position = 0;
|
||||
|
||||
// Unzip the stream
|
||||
GZipStream zipStream = new GZipStream(stream, CompressionMode.Decompress);
|
||||
|
||||
// Create a serializer
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
|
||||
// Deserialize the stream
|
||||
sdib = (SerialDib)formatter.Deserialize(zipStream);
|
||||
|
||||
// Unload the stream
|
||||
zipStream.Dispose();
|
||||
|
||||
// Use 'ConvertFromRawBits and the deserialized struct to recreate the bitmap
|
||||
// In this case the marshaller is used to create the needed IntPtr to the data
|
||||
// array.
|
||||
FIBITMAP dib = FreeImage.ConvertFromRawBits(
|
||||
Marshal.UnsafeAddrOfPinnedArrayElement(sdib.data, 0),
|
||||
(int)sdib.width, (int)sdib.height, sdib.pitch, sdib.bpp,
|
||||
sdib.red_mask, sdib.green_mask, sdib.blue_mask,
|
||||
false);
|
||||
|
||||
// Unload the temporary stream
|
||||
stream.Dispose();
|
||||
|
||||
// Return the created bitmap
|
||||
return dib;
|
||||
}
|
||||
|
||||
// Saving function
|
||||
protected override bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data)
|
||||
{
|
||||
SerialDib sdib;
|
||||
uint size = FreeImage.GetDIBSize(dib);
|
||||
|
||||
// Store all data needed to recreate the bitmap
|
||||
sdib.width = FreeImage.GetWidth(dib);
|
||||
sdib.height = FreeImage.GetHeight(dib);
|
||||
sdib.pitch = (int)FreeImage.GetPitch(dib);
|
||||
sdib.bpp = FreeImage.GetBPP(dib);
|
||||
sdib.red_mask = FreeImage.GetRedMask(dib);
|
||||
sdib.green_mask = FreeImage.GetGreenMask(dib);
|
||||
sdib.blue_mask = FreeImage.GetBlueMask(dib);
|
||||
sdib.data = new byte[size];
|
||||
|
||||
// Copy the bitmaps data into the structures byte-array
|
||||
// The marshaller is used to create an IntPtr for using
|
||||
// 'ConvertToRawBits'.
|
||||
FreeImage.ConvertToRawBits(Marshal.UnsafeAddrOfPinnedArrayElement(sdib.data, 0),
|
||||
dib, sdib.pitch, sdib.bpp,
|
||||
sdib.red_mask, sdib.green_mask, sdib.blue_mask,
|
||||
false);
|
||||
|
||||
// Use the healper function to write the header to the destination
|
||||
if (Write(io, handle, (uint)header.Length, 1, ref header) != 1)
|
||||
return false;
|
||||
|
||||
// Create a serializer
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
|
||||
// Create a temporary stream
|
||||
MemoryStream stream = new MemoryStream();
|
||||
|
||||
// Create a compression stream
|
||||
GZipStream zipStream = new GZipStream(stream, CompressionMode.Compress);
|
||||
|
||||
// Serialize the structure into the compression stream
|
||||
formatter.Serialize(zipStream, sdib);
|
||||
|
||||
// Unload the compression stream
|
||||
zipStream.Dispose();
|
||||
|
||||
// Get the result data
|
||||
byte[] buffer = stream.GetBuffer();
|
||||
|
||||
// Use the healper function 'Write' to write the data to the destination
|
||||
if (Write(io, handle, 1, (uint)buffer.Length, ref buffer) != buffer.Length)
|
||||
{
|
||||
// Unload the temporary stream
|
||||
stream.Dispose();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Unload the temporary stream
|
||||
stream.Dispose();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return a list of supported file extensions (comma seperated)
|
||||
protected override string ExtensionListProc()
|
||||
{
|
||||
return "ser";
|
||||
}
|
||||
|
||||
// Implementation of 'ToString()'
|
||||
public override string ToString()
|
||||
{
|
||||
return DescriptionProc();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user