| View previous topic :: View next topic |
| Author |
Message |
violetfemme
Joined: 09 Oct 2003 Posts: 10 Location: Atlanta, GA
|
Posted: Wed Jan 28, 2004 5:42 pm Post subject: exporting as image? |
|
|
Hi gang!
I'm working with a charting application where the user will need to be able to both print and save a dynamically created line chart. I've got the kinks figured out with the printing... but the exporting is throwing me for a bit of a loop! I figure since you can print a movieclip as a bitmap, you should be able to save a movieclip as a bitmap, too. I know that Flash can publish in different formats... but this chart is being generated by data on the fly, so I'll need the generated .swf to do all the work.
Any ideas? Can a .swf export part of itself in an image format?
Thanks in advance! |
|
| Back to top |
|
 |
ZaxisNet Administrator

Joined: 01 Aug 2002 Posts: 276 Location: Toronto, ON
|
Posted: Wed Jan 28, 2004 7:27 pm Post subject: |
|
|
you are looking to save the data graph to disk? or are you looking to sav the image to disk for them to print out later?
If your saving the info, I would suggest using PHP and mySQL or Cold Fusion and some database to save the info...or save the info via Shared Object on the users HD.
however, if your trying to save the image to disk (user's HD or server) I'm not sure how to go about doing that.
Flash exports different file types within the application itself, not at runtime (on the fly).
I have never heard of saving a MC as a bitmap, only printing...but that's how the Flash Player prints...it takes a snap shot and sends that data to the printer.
If you can give me more info on why you need to save the image it might help, so I can suggest another method.
Hope that helps _________________ Thomas Schemmer
ZaxisNet - Creative Media
o Please do a search before you post
o Reply here for the benfit of all
|
|
| Back to top |
|
 |
violetfemme
Joined: 09 Oct 2003 Posts: 10 Location: Atlanta, GA
|
Posted: Thu Jan 29, 2004 10:36 am Post subject: |
|
|
I need to save the movieclip as a bitmap to disk... so that the users can use the chart in their own reports if need be.
It's frustrating because I've seen solutions using PHP and other scripting methods to do this (like you suggested) and generate another chart to save... but if that's the case... perhaps Flash isn't the solution for charting that I hoped it was.
Though I guess "print screen" would work just as well, eh?  |
|
| Back to top |
|
 |
i11uminatus

Joined: 21 Aug 2003 Posts: 110 Location: Toronto, ON
|
Posted: Fri Jan 30, 2004 1:45 pm Post subject: |
|
|
The only way I am aware of to get Flash to output a bitmap using dynamic objects is by using Generator, and I haven't heard anything about Generator in a long time. I'm not sure if it's still supported, or even works with current versions of Flash. _________________
 |
|
| Back to top |
|
 |
FlashGuru
Joined: 01 Feb 2004 Posts: 1
|
Posted: Sun Feb 01, 2004 12:26 am Post subject: |
|
|
As people have already mentioned when a flash movie is running in the Flash Player in a browser, their is no functionality for an image to be created by the flash movie itself. You can however build up the raw source of a .jpeg image and then send that raw data to a server-side script which would then output a http header:
Content-type: image/jpeg
Plus(+) the raw source you sent to the script from flash and the user would be prompted to save the file to disk in the browser.
Of course to do this you need to understand the jpeg file format and with actionscript create a class that would create jpegs. I can imagine this been rather a complex task.
You could also build the jpeg on the server-side using some of the image library functions available to the language. Then your script, after receiving the various co-ordinates, colour information etc.. of the vector image they have created in the flash could then output a http header and the image source to the browser for the user to save. _________________ FlashGuru's MX 101 - The Flash MX Knowledge Base |
|
| Back to top |
|
 |
ZaxisNet Administrator

Joined: 01 Aug 2002 Posts: 276 Location: Toronto, ON
|
Posted: Sun Feb 01, 2004 2:54 pm Post subject: |
|
|
Welcome to Flash Goddess, FlashGuru.
Thanks for posting that tid bit of info....just wondering, what do you mean by the raw source from actionscript? just the info to build the image (in this case the chart)? _________________ Thomas Schemmer
ZaxisNet - Creative Media
o Please do a search before you post
o Reply here for the benfit of all
|
|
| Back to top |
|
 |
whirledserpent
Joined: 07 Feb 2006 Posts: 2 Location: Saint Augustine, FL
|
Posted: Tue Feb 07, 2006 4:09 pm Post subject: |
|
|
| Quote: | | You can however build up the raw source of a .jpeg image |
Can you though? I have been working on this issue for a while now. I am very proficient in ActionScript 2.0 classes and I really cannot see a way to do this part. Flash treats images as movie clips and I really havent found any way to "parse" the image data out of them. The rest of your theory is fine... if you could actually parse the raw binary data that makes the image it would be relatively simple to drop that into a service request that generated a file or stored a blob in a database.
I wish someone would figure out how to do this, we are in need of some reporting functionality in a flash based application and this has got me at a brick wall  |
|
| Back to top |
|
 |
whirledserpent
Joined: 07 Feb 2006 Posts: 2 Location: Saint Augustine, FL
|
Posted: Mon Feb 13, 2006 1:33 pm Post subject: |
|
|
Well I did finally find a way to do this in AS 2.0. Flash 8 has flash.display.BitmapData. You can use GetPixel32 to get a big array of pixel argb values. I then pass that array to my C# assembly and use System.Drawing to reassemble them and save as a .jpg. Anyhow, if its of any use to you:
Action Script:
| Code: |
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.services.Log;
import mx.remoting.NetServices;
import mx.remoting.Service;
import flash.display.BitmapData;
class imageManagement{
private var service:Service;
private var pixelObject:Object;
private var requestObject:Object;
private var GATEWAY_URL:String = "http://myserver.com/services/gateway.aspx";
public function imageManagement() {
service = new Service(GATEWAY_URL, new Log(), "FileManagement.Image", null, null);
}
public function takeSnapshot(objImage:Object) {
var outputImage = new BitmapData(objImage.clipName._width, objImage.clipName._height);
outputImage.draw(objImage.clipName);
var w:Number = outputImage.width, tmp
var h:Number = outputImage.height
pixelObject = new Object();
var j:Number = 0;
for(var a=0; a<=w; a++){
for(var b=0; b<=h; b++){
var alpha:String = (outputImage.getPixel32(a, b) >> 24 & 0xFF).toString(16);
var red:String = (outputImage.getPixel32(a, b) >> 16 & 0xFF).toString(16);
var green:String = (outputImage.getPixel32(a, b) >> 8 & 0xFF).toString(16);
var blue:String = (outputImage.getPixel32(a, b) & 0xFF).toString(16);
tmp = alpha + red + green + blue;
pixelObject[j] = tmp;
j++
}
}
requestObject = new Object();
requestObject.width = w;
requestObject.height = h;
requestObject.totalPixels = j;
requestObject.fileName = objImage.fileName;
var helloPc:PendingCall = this.service.writeImage(requestObject, pixelObject);
helloPc.responder = new RelayResponder(this, "onCallData","onCallFault");
}
private function onCallData( re:ResultEvent ):Void {
trace("success");
}
private function onCallFault( fault:FaultEvent ):Void {
trace("failure");
}
}
|
c# to make the image
| Code: |
using System;
using FlashGateway.IO;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.IO;
using System.Globalization;
namespace FileManagement
{
public class Image
{
public ASObject writeImage(ASObject requestObject, ASObject pixelObject)
{
ASObject resultObject = new ASObject();
resultObject.Add("eventStatus", "success");
int imageWidth = Convert.ToInt32(requestObject["width"]);
int imageHeight = Convert.ToInt32(requestObject["height"]);
string fileName = requestObject["fileName"].ToString();
Double totalPixels = Convert.ToDouble(requestObject["totalPixels"]);
string sPhysicalPath = "G:" + @"\" + "WWW_DATA" + @"\" + "wwwroot";
Bitmap myBitmap=new Bitmap(imageWidth,imageHeight);
int j = 0;
int w = 0;
int h = 0;
string colorValue = "";
string stringNumber = "0";
string thisColorVal = "";
for(w=0; w<=imageWidth; w++)
{
for(h=0; h<=imageHeight; h++)
{
stringNumber = j.ToString();
thisColorVal = pixelObject[stringNumber].ToString();
if(thisColorVal.Length == 8)
{
colorValue = thisColorVal;
Color c = Color.FromArgb(Int32.Parse(colorValue, NumberStyles.HexNumber));
myBitmap.SetPixel(w,h,c);
}
else
{
//not valid
}
j++;
}
}
myBitmap.Save(sPhysicalPath + @"\" + fileName,ImageFormat.Jpeg);
return resultObject;
}
}
}
|
|
|
| Back to top |
|
 |
|