|
marziac, Newbie
Posted: 13 June 2011 06:48 AM Total Posts: 4
Hello,
I’m trying to save what I see on screen to a jpeg file. I tried
capturing the View as a Sprite, but the result is a blank file. There
is some method to render directly to a file?.
This is the code I’m using to create the JPG:
public function createJPG(spr:Sprite, n:Number,
fileName:String):void {
var jpgSource:BitmapData = new BitmapData (spr.width, spr.height);
jpgSource.draw(spr);
var jpgEncoder:JPGEncoder = new JPGEncoder(n);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
var header:URLRequestHeader = new URLRequestHeader ("Content-type",
"application/octet-stream");
//Make sure to use the correct path to jpg_encoder_download.php
var jpgURLRequest:URLRequest = new URLRequest (Comun._URL_+"/php/
download.php?name=" + fileName + ".jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
var loader:URLLoader = new URLLoader();
navigateToURL(jpgURLRequest, "_blank");
}
Spr is the view. Thanks.
|
Alejandro Santander, Administrator
Posted: 13 June 2011 01:57 PM Total Posts: 414
[ # 1 ]
Hey, I know we should rely on the forum filter for this, but we still need to tag topics with the away3d version that you selected when creating a post, need to fix that…
What Away3D version are you using?
|
marziac, Newbie
Posted: 13 June 2011 02:01 PM Total Posts: 4
[ # 2 ]
Hola Alejandro,
for this project I’m using version 4.0. Is there some kind of incompatibility with the player? Thanks.
|
Alejandro Santander, Administrator
Posted: 13 June 2011 02:07 PM Total Posts: 414
[ # 3 ]
Ah, then I believe you can’t use a normal graphics API method to redraw the view. Molehill 3D content is not in the regular flash display tree, it is on an object called Stage3D, behind the display tree and independent from it. Check out the Molehill documentation to see what Molehill API method you could use to draw the content of the view to a BitmapData.
|
marziac, Newbie
Posted: 13 June 2011 02:35 PM Total Posts: 4
[ # 4 ]
Ok, thanks.
Where I can find the LiveDocs for Molehill? I’ve done a search on google but found nothing.
When you find a solution I’ll tell you.
|
Alejandro Santander, Administrator
Posted: 13 June 2011 03:20 PM Total Posts: 414
[ # 5 ]
I can’t remember where the docs are, probably when you download the API in a reference folder?
|
marziac, Newbie
Posted: 13 June 2011 03:24 PM Total Posts: 4
[ # 6 ]
This works great:
public function createJPG( n:Number, fileName:String):void {
var jpgSource:BitmapData = new BitmapData(1024,768);
World3D._pWorld3d.view.renderer.swapBackBuffer = false;
World3D._pWorld3d.view.render();
World3D._pWorld3d.view.renderer.context.drawToBitmapData(jpgSource);
World3D._pWorld3d.view.renderer.swapBackBuffer = true;
var jpgEncoder:JPGEncoder = new JPGEncoder(n);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
//Make sure to use the correct path to jpg_encoder_download.php
var jpgURLRequest:URLRequest = new URLRequest (Comun._URL_+"/php/download.php?name=" + fileName + ".jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
var loader:URLLoader = new URLLoader();
navigateToURL(jpgURLRequest, "_blank");
}
n parameter is the quality of jpeg and this is download.php:
<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
// get bytearray
$im = $GLOBALS["HTTP_RAW_POST_DATA"];
// add headers for download dialog-box
header('Content-Type: image/jpeg');
header("Content-Disposition: attachment; filename=".$_GET['name']);
echo $im;
} else echo 'An error occured.';
?>
Prerelease Documentation:
http://www.matthewfabb.com/fp11incubator27_02_11/
|
Alejandro Santander, Administrator
Posted: 13 June 2011 03:57 PM Total Posts: 414
[ # 7 ]
That’s awesome marziac. I knew it was something along those lines. Thanks for sharing the solution, this should be useful for reference.
I’ll try to see if we can mark these sort of topics as examples or resolved issues in some way.
|
vedran, Newbie
Posted: 18 June 2011 03:01 PM Total Posts: 8
[ # 8 ]
Can you render the view in higher resolution than stage? It should be possible since view works with 3D data (it’s a kind of vector data). What I have in mind is doing hi-res (8000x4000px) jpg images for print. Right now I use Blender and VVVV for stuff like that and since Flash is a tool that I use every day that would be so awsome :D
Cheers!
Vedran
|
vedran, Newbie
Posted: 21 June 2011 11:26 PM Total Posts: 8
[ # 9 ]
|
vedran, Newbie
Posted: 21 June 2011 11:30 PM Total Posts: 8
[ # 10 ]
any kind of help or hint would be great…
|
Alejandro Santander, Administrator
Posted: 22 June 2011 12:42 AM Total Posts: 414
[ # 11 ]
Well, it isn’t simple. Flash has too many limitations for that kind of thing, basically because it is not intended to do that. For instance, there is a limitation on how big a bitmapdata can be, and I guess you would need a bitmapdata to produce an external image.
So, my guess is that this is not possible straight away, unless it was for a very complex project, someone COULD find a solution to the problem with some clever programming.
Not trivial.
|