Return to Snippet

Revision: 6733
at June 11, 2008 11:06 by chrisaiv


Updated Code
import com.adobe.images.JPGEncoder;

function createJPG(mc:MovieClip, n:Number, fileName:String) {
	
	var jpgSource:BitmapData = new BitmapData (mc.width, mc.height);
		jpgSource.draw(mc);
	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 ("download.php?name=" + fileName + ".jpg");
		jpgURLRequest.requestHeaders.push(header);
		jpgURLRequest.method = URLRequestMethod.POST;
		jpgURLRequest.data = jpgStream;

	var loader:URLLoader = new URLLoader();
	navigateToURL(jpgURLRequest, "_blank");
}


//createJPG(movieClip, quality, fileName);
createJPG(myMovieClip, 90, "myDog");

///////////////////////////////////////////////////////////////
//This is an Example of the Server-side that will return the JPEG
///////////////////////////////////////////////////////////////
/*
<?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.';
?>
*/

Revision: 6732
at June 11, 2008 11:05 by chrisaiv


Initial Code
import com.adobe.images.JPGEncoder;

function createJPG(mc:MovieClip, n:Number, fileName:String) {
	
	var jpgSource:BitmapData = new BitmapData (mc.width, mc.height);
		jpgSource.draw(mc);
	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 ("download.php?name=" + fileName + ".jpg");
		jpgURLRequest.requestHeaders.push(header);
		jpgURLRequest.method = URLRequestMethod.POST;
		jpgURLRequest.data = jpgStream;

	var loader:URLLoader = new URLLoader();
	navigateToURL(jpgURLRequest, "_blank");
}


//createJPG(movieClip, quality, fileName);
createJPG(myMovieClip, 90, "myDog");



///////////////////////////////////////////////////////////////
//This is an Example of the Server-side that will return the JPEG
///////////////////////////////////////////////////////////////
/*
<?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.';
?>
*/

Initial URL
http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash

Initial Description
I found this excellent tutorial on how to save JPEG images from Flash.  You will need the Adobe JPEG Encoder class which can be found here: http://code.google.com/p/as3corelib/.  You will also need some server-side action which in this case was done in PHP

Initial Title
AS3: Save JPEG's from Flash

Initial Tags

                                

Initial Language
ActionScript 3