-
Posts
6 -
Joined
-
Last visited
-
Days Won
1
Posts posted by MadDugan
-
-
This might help.
Hidden Content:///////////////////////////////////////////////////////////////////////////////// // paint.net // // Copyright (C) dotPDN LLC, Rick Brewster, and contributors. // // All Rights Reserved. // ///////////////////////////////////////////////////////////////////////////////// using PaintDotNet.SystemLayer; using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; namespace PaintDotNet.Data { /// <summary> /// Implements FileType for generic GDI+ codecs. /// </summary> /// <remarks> /// GDI+ file types do not support custom headers. /// </remarks> internal class GdiPlusFileType : FileType { private ImageFormat imageFormat; public ImageFormat ImageFormat { get { return this.imageFormat; } } protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback) { GdiPlusFileType.Save(input, output, scratchSurface, this.ImageFormat, callback); } public static void Save(Document input, Stream output, Surface scratchSurface, ImageFormat format, ProgressEventHandler callback) { // flatten the document scratchSurface.Clear(ColorBgra.FromBgra(0, 0, 0, 0)); using (RenderArgs ra = new RenderArgs(scratchSurface)) { input.Render(ra, true); } using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap()) { LoadProperties(bitmap, input); bitmap.Save(output, format); } } public static void LoadProperties(Image dstImage, Document srcDoc) { LoadProperties(dstImage, srcDoc, _ => true); } public static void LoadProperties(Image dstImage, Document srcDoc, Func<PropertyItem, bool> selectorFn) { Bitmap asBitmap = dstImage as Bitmap; if (asBitmap != null) { // Sometimes GDI+ does not honor the resolution tags that we // put in manually via the EXIF properties. float dpiX; float dpiY; switch (srcDoc.DpuUnit) { case MeasurementUnit.Centimeter: dpiX = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuX); dpiY = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuY); break; case MeasurementUnit.Inch: dpiX = (float)srcDoc.DpuX; dpiY = (float)srcDoc.DpuY; break; default: case MeasurementUnit.Pixel: dpiX = 1.0f; dpiY = 1.0f; break; } try { asBitmap.SetResolution(dpiX, dpiY); } catch (Exception) { // Ignore error } } Metadata metaData = srcDoc.Metadata; foreach (string key in metaData.GetKeys(Metadata.ExifSectionName)) { string blob = metaData.GetValue(Metadata.ExifSectionName, key); PropertyItem pi = PdnGraphics.DeserializePropertyItem(blob); bool include = selectorFn(pi); if (include) { try { dstImage.SetPropertyItem(pi); } catch (ArgumentException) { // Ignore error: the image does not support property items } } } } protected override Document OnLoad(Stream input) { using (Image image = Image.FromStream(input, false, true)) { Document document = Document.FromGdipImage(image, false); return document; } } public static ImageCodecInfo GetImageCodecInfo(ImageFormat format) { ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders(); foreach (ImageCodecInfo icf in encoders) { if (icf.FormatID == format.Guid) { return icf; } } return null; } public GdiPlusFileType(string name, ImageFormat imageFormat, bool supportsLayers, string[] extensions) : this(name, imageFormat, supportsLayers, extensions, false) { } public GdiPlusFileType(string name, ImageFormat imageFormat, bool supportsLayers, string[] extensions, bool savesWithProgress) : base(name, (supportsLayers ? FileTypeFlags.SupportsLayers : 0) | FileTypeFlags.SupportsLoading | FileTypeFlags.SupportsSaving | (savesWithProgress ? FileTypeFlags.SavesWithProgress : 0), extensions) { this.imageFormat = imageFormat; } } }
Exactly what I needed. Thanks!
-
Working on a compatibility fix
-
v1.2.1
Updated plugin to honor a layer's visibility flag
Scenerio where this would be used: Multiple sprite animations in one file for proper centering and resizing then only making visible layers you want to export.
-
Hi MadDugan - welcome to the forum
Your first plugin is very nicely done. Works just as anticipated without hassle or fuss. You've made a nice job of it.
You might want to mention in your post that it is a filetype plugin and the DLL should go in the /Filetypes/ folder.
Thanks for the feedback. I have made the changes as suggested.
-
7/24/2014 - v1.2.2 Minor Code change and recompile to support Paint.NET 4
I was in need of a consistent way to create simple, evenly spaced spritesheets from multiple layers in Paint.NET and I figured I would share the plugin.
DOWNLOAD: https://ssplugin.codeplex.com/releases/view/125730
This is a FileType plugin that will generate a PNG formatted file.
v1.2.1 - Add honoring layer visibility.
v1.2.2 - Minor Code change and recompile to support Paint.NET 4Installation Instructions
- Verify Paint.NET is not running
- Copy spritesheet.dll into the /Paint.NET/FileTypes sub-directory
- Start Paint.NET and verify "SpriteSheet (*.ss.png)" is now an option for "Save as"
If there is a lot of interest, I will consider adding features, but as is, it suits my requirements.
Please cite if you use this tool for your application development and I will return the favor by linking to your application.
An example of multilayer sprite
The resulting file created by exporter
- 1
- 1
Spritesheet Export Plugin
in FileType Plugins
Posted
I got notified before your edit and immediately thought maybe it was still finding 1.2.1 somewhere. Glad to see you resolved it.
-M