redknt42 Posted April 25, 2008 Share Posted April 25, 2008 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=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! Quote Link to comment Share on other sites More sharing options...
pyrochild Posted April 25, 2008 Share Posted April 25, 2008 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=document.layers[0]; Or something like that. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
redknt42 Posted April 27, 2008 Author Share Posted April 27, 2008 Thanks, Pyrochild! The actual call to add a layer is this: doc.Layers.Add(new BitmapLayer(Surface.CopyFromBitmap()); 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! Quote Link to comment Share on other sites More sharing options...
pyrochild Posted April 27, 2008 Share Posted April 27, 2008 Glad to be of (partial) help 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." Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.