Archived

This topic is now archived and is closed to further replies.

Pen15

Screenshot with alpha value

Recommended Posts

Pen15    122
Hi, I've been reading on here for a couple months but this is my first post so bear with me . (Using DirectX 8.1) What I would like to do is take a screenshot and preserve an alpha value. For example, draw a cube on screen (or to a backbuffer) with a translucent background, and be able to save that to some format (such as .png) that will be able to preserve this alpha. 1) Is this possible? 2) How might I go about doing this? I have been reading a lot of stuff everywhere to try and figure this out, but I'm not sure. I know DirectX only supports writing BMP and DDS directly, and I don't know how I would write an alpha to them. Right now I am using THIS method of taking a screenshot (using D3DXSaveSurfaceToFile). When I write to a .bmp it just uses a white background if I haven't cleared the display. If I don't clear the display, is the background transparent or just a bunch of garbage? I have recently set up DevIL to see if I could work with that. If the above question is yes (background is transparent), would I be able to create an image in DevIL with the IDirect3DSurface8 data? If so, I'd appreciate it if someone showed me a little example. I've read through the docs and examples and it says you can create a picture directly from a data stream. I come from a Java background and have recently started doing c++ stuff, and I'm not extremely comfortable with the whole memory and data streams stuff yet. If the above is not possible, might I have to resort to just getting the surface data and then directly filtering it somehow to create an alpha value for the whole texture? ... Or if I'm going in the totally wrong direction, let me know. There's probably more stuff I forgot to say but I have a lot runnin through my head . Thanks, Pen15 [edited by - Pen15 on August 8, 2003 12:37:33 AM] [edited by - Pen15 on August 8, 2003 12:38:06 AM]

Share this post


Link to post
Share on other sites
Nerusai    103
Are you sure it''s even possible? I doubt the alpha channels are stored on the primary surface that is the screen, they are most likely rendered by then.

Share this post


Link to post
Share on other sites
Khaile    122
Just an idea... but what about using an off-screen surface...

Start by clearing the surface to black, then set the cube's diffuse colors to full white (but keep the alpha values you want) and render it on the surface. This will be your alpha channel since the stronger alpha the cube had, the more white will the cube be on the black background.

Copy the alpha information to some other memory location and then redo the step but with your correct colors. Then write a PNG or TGA to file by using these two rendered surfaces... Should do the trick, but will probably not be so good if you're having something more complex to render than a single model (the cube)...

EDIT: speelign erors!

[edited by - Khaile on August 9, 2003 10:54:58 AM]

Share this post


Link to post
Share on other sites
Pen15    122
After finding some more resources to get me thinking, I think I know what I''m going to have to do to get what I''m looking for.. which will consist of writing my own exporter, some bit manipulation, and something similar to what Khaile said. Now for implementation...

Thanks for the replies.

Share this post


Link to post
Share on other sites
Wavewash    202
I dunno how you'd take the screenshot but I have a little utility that takes two bitmaps and uses one as the alpha to make a texture with a alpha value and then it saves it to a TGA.

www.opticuslabs.com/alphatexgen

lookit the code it might beable to help you.

I'm confused about what part is transparent. What exactly is supposed to be transparent and visible in the picture? Do you mean like having the color background be transparent and then everything that gets drawn on top of it is not?

~Wave

[edited by - Wavewash on August 9, 2003 7:11:21 PM]

Share this post


Link to post
Share on other sites
sadwanmage    122
Or you could render the scene twice, once with a black background, once with a white. From those two screenshots you could also calculate the alpha value. Less elegant than Khaile''s method, but would probably require less change to the code already in place.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Yeah, this is a relatively simple question.

You need to have both a surface format which has an alpha channel, and save to a file type which supports alpha channel.

Lock() the surface, copy all the bytes, export to file.

D3DXSaveSurfaceToFile does this automatically for you, but it might not support any file types with alpha channels. (BMP does not support alpha)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by Anonymous Poster
(BMP does not support alpha)


WRONG! BMP supports alpha, yet no image manipulation software that I''m aware of can handle 32 bit BMPs...

Share this post


Link to post
Share on other sites
Pen15    122
Wavewash: your program/code is rather helpful to me.

The idea I had in mind was to have a translucent background and perhaps some objects on top with some varying degrees of opacity. Obviously, when whatever is rendered in the scene, the whole screen will have a background and be opaque, but I wanted to have the option of making parts of it "see-thru" when writing what is on screen to some type of image format. I wasn''t exactly sure how to go about writing the screenshot out to a non .bmp file but your code, Wavewash, and some code snippets on MSDN have demystified some things for me. I''m using this for some non-game stuff which isn''t too complex as far as how much and what is on screen. It won''t really be a "screenshot" in the typical sense, I guess, and I think it will be feasible to be able to do what I''m going for.

Share this post


Link to post
Share on other sites