Jump to content

Accessing Document Layers


Recommended Posts

I was wondering if somone could tell me the best way to add layers to the document object from a bitmap source, and also to retrieve layers int a bitmap for saving.

i.e.

bitmap b;

Document document;

document.layers.add(???(B));

b=document.layers.???;

I could spend an hour or two digging through the code, but I am too lazy, especially as I am sure someone knows it off the top of their head.

Thanks in advance!

Link to comment
Share on other sites

I haven't messed around with that for a while, but I believe you add a Layer object, of which BitmapLayer is the only current implementation.

bitmap b;

Document document;

document.layers.add(new BitmapLayer(B));

b=document.layers[0];

Or something like that.

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to comment
Share on other sites

Thanks, Pyrochild! The actual call to add a layer is this:

doc.Layers.Add(new BitmapLayer(Surface.CopyFromBitmap(B)));

and to convert a layer into a bitmap is this:

BitmapLayer l = (BitmapLayer)doc.Layers[0];

Bitmap b = l.Surface.CreateAliasedBitmap();

which would have taken ages to figure out without your reply!

Link to comment
Share on other sites

Glad to be of (partial) help :D

One note on that second part, though. Make sure the Surface does not go out of scope while the Bitmap is still in scope. Otherwise, the Surface could get garbage collected, and the bitmap will die as well, and you'll end up getting all sorts of errors that make no sense to any normal human. ("Aliased" means it's using the same memory locations)

You may have already known that, but I though I'd throw that out there anyway. That particular issue certainly gave me a few good headaches "back in the day."

:lol:

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

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...