Jump to content

FileType plugins Using WIC CODEC


MikeFr
 Share

Recommended Posts

hi there!

I just develop a new file format and the associated WIC codec.

Now I'm trying to develop the paint.NET File Type plugins to open and SAVE in my format into PDN.

I succeed to open an image in PDN with the function onLoad :

protected override Document OnLoad(Stream input)
{
try
{
	BitmapSource bitmapSourcetest = null;
	MemoryStream imageStream = null;
	BitmapCreateOptions createOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;
	BitmapDecoder myDecoder = BitmapDecoder.Create(input, createOptions, BitmapCacheOption.None);

	if (myDecoder.Frames[0] != null)
	{
		bitmapSourcetest = myDecoder .Frames[0];
	}

	//Save the image in a Memory stream
	System.Windows.Media.Imaging.BmpBitmapEncoder bmpEncoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();

	bmpEncoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmapSourcetest));
	imageStream = new MemoryStream();
	bmpEncoder.Save(imageStream);
	Bitmap b = new System.Drawing.Bitmap(imageStream);

	myContainerFormat = myDecoder.CodecInfo.ContainerFormat;

	return Document.FromImage(;
}
catch
{
	MessageBox.Show("Problem Importing File");
	Bitmap b = new Bitmap(500, 500);
	return Document.FromImage(;
}
}

BitmapDecoder.Create creates the decoder by calling the wic dll. and myContainerFormat gives me the correct GUID container format.

Now it's getting more complicated with the method onSave.

I try this code :

protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
{
myEncoder = BitmapEncoder.Create(myContainerFormat);

myEncoder.Save(output);
 /*using (RenderArgs ra = new RenderArgs(scratchSurface))
{
	input.Render(ra, true);
	ra.Bitmap.Save(output, ImageFormat.Bmp);
 }*/
}

I can't create the encoder based on my wic dll it always return an UnknownBitmapEncoder.

Anyone as a clue on using the WIC with PDN ????

Thanks for answers.

Mike

Link to comment
Share on other sites

No idea. I'm not even sure if WPF's WIC wrappers support custom container formats.

The WPF wrapper only supports saving the built-in codecs.

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Link to comment
Share on other sites

In PDN 4.0 I have my own wrapper for WIC, but for what you're doing it won't be usable. The decoder/encoder/metadata portion of the wrapper is incomplete and I won't be finishing it since nothing in PDN4 will be using it (rather, I won't be finishing it for 4.0) and because all that metadata stuff is confusing and it'd be a huge time sink. Once it's ready, however, this will provide you a straightforward way to do what you've been trying to achieve. If you're familiar with WPF's WIC wrapper, then you already mostly know WIC itself and it shouldn't be too difficult to convert. I'm hoping to do this for PDN 4.1.

I also have wrappers for Direct2D, DirectWrite, DXGI (partial), and Windows Animation Manager. I also have a "mini-WPF" that is proving to be fantastic for writing new UI for tools. Hopefully someday these will all be accessible to plugins.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...