Archive Browser
Download CorelDrawPalPaletteWriter.zip, last updated 05/08/2018 (30.38 KB)
Download- md5: 5dc2a39ffc96357d70d670fae102a69c
- sha1: 87cd30771c13132db0584ebbc03986265fa278dc
- sha256: 9cc4800ea9713c1d7f95660b1deba20f3c13e9f317171b2cbc0ff358ace10f7e
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
// Working with CorelDRAW Palettes part 2, writing .pal files
// https://www.cyotek.com/blog/working-with-coreldraw-palettes-part-2-writing-pal-files
// Copyright © 2018 Cyotek Ltd. All Rights Reserved.
// This work is licensed under the Creative Commons Attribution 4.0 International License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.
// Found this example useful?
// https://www.paypal.me/cyotek
namespace Cyotek.Demonstrations.CorelDrawPaletteWriter
{
internal partial class WriteTestDialog : Form
{
#region Constants
private readonly List<FileInfo> _files;
#endregion
#region Constructors
public WriteTestDialog()
{
this.InitializeComponent();
_files = new List<FileInfo>();
}
public WriteTestDialog(List<FileInfo> files)
: this()
{
_files = files;
}
#endregion
#region Methods
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
if (_files.Count != 0)
{
for (int i = 0; i < _files.Count; i++)
{
paletteComboBox.Items.Insert(i, _files[i]);
}
paletteComboBox.SelectedIndex = 0;
}
else
{
paletteComboBox.SelectedIndex = paletteComboBox.FindStringExact("Windows (256)");
}
outputTextBox.Font = FontHelpers.GetFixedFont();
}
private void closeButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void Compare(CorelDrawPalette source)
{
using (MemoryStream output = new MemoryStream())
{
PaletteCompareResult compareResult;
Color[] src;
Color[] dst;
source.Save(output);
output.Position = 0;
compareResult = PaletteComparer.Compare(source, output);
if (compareResult != PaletteCompareResult.Mismatch)
{
resultLabel.Text = "Files are identical";
resultLabel.BackColor = Color.Green;
}
else
{
resultLabel.Text = "Files do not match.";
resultLabel.BackColor = Color.Red;
}
src = source.ToArray();
output.Position = 0;
dst = CorelDrawPalette.LoadFrom(output).ToArray();
outputTextBox.Text = Encoding.ASCII.GetString(output.ToArray());
sourceView.Palette = src;
destinationView.ComparePalette = src;
destinationView.Palette = dst;
}
}
private void paletteComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
CorelDrawPalette palette;
int index;
index = paletteComboBox.SelectedIndex;
if (index < _files.Count)
{
palette = CorelDrawPalette.LoadFrom(_files[index].FullPath);
}
else
{
Color[] colors;
switch (index - _files.Count)
{
case 0:
colors = ColorPalettes.HexagonPalette;
break;
case 1:
colors = ColorPalettes.NamedColors;
break;
case 2:
colors = ColorPalettes.PaintPalette;
break;
case 3:
colors = ColorPalettes.WebSafe;
break;
case 4:
colors = ColorPalettes.QbColors;
break;
case 5:
colors = ColorPalettes.StandardPalette;
break;
case 6:
colors = ColorPalettes.RedScale;
break;
case 7:
colors = ColorPalettes.GreenScale;
break;
case 8:
colors = ColorPalettes.BlueScale;
break;
case 9:
colors = ColorPalettes.GreyScale;
break;
default:
colors = null;
break;
}
if (colors != null && colors.Length != 0)
{
palette = new CorelDrawPalette(colors);
}
else
{
palette = null;
}
}
if (palette != null && palette.Count != 0)
{
this.Compare(palette);
}
else
{
sourceView.Palette = null;
destinationView.Palette = null;
}
}
#endregion
}
}
Donate
This software may be used free of charge, but as with all free software there are costs involved to develop and maintain.
If this site or its services have saved you time, please consider a donation to help with running costs and timely updates.
Donate