Flash ve ASP.NET jpeg export
Beni günlerce uğraştırdıktan sonrainternette önce PHP versiyonuna rastladığım flash jpeg export olayının ASP.NET olanını da çalıştırmayı başardım.İşte Kodlarımız
Flash da timeline de ilk kodlarımız bunlar
import it.sephiroth.mloaderWindow
import it.sephiroth.PrintScreen
loadMovie("flash içerisine dışarıdan çağırılacak swf",_root.dummy);
mc._x=0;// x ve y koordinatları
mc._y=0;
var loader:mloaderWindow = this.createClassObject(mloaderWindow, "loader", 10, {_x:-1000, _y:-1000})
loader.setStyle("borderColor", 0x006699)
// listener which receives the broadcast message
// from the PrintScreen class
var listener:Object = new Object();
// copy in progress...
listener.onProgress = function(target:MovieClip, loaded:Number, total:Number){
var perc = Math.round((loaded/total)*100)
loader.label = "computing... " + perc + "%"
loader.value = perc
}
// copy is complete, send the result LoadVars to PHP
listener.onComplete = function(target:MovieClip, load_var:LoadVars){
loader.label = "sending to php..."
load_var.send("FlashToImage.aspx", "_blank", "POST")
loader.close()
}
/**
* Print Button has been clicked
*/
function print_me(){
video_mc.pause() // first pause the playing video
pn = new PrintScreen(); // initialize the PrintScreen class
pn.addListener( listener ); // assign a listener
pn.print(this,0,0,485,165) // copy the _root
loader.label = "computing... 0%"
loader.open(true, true, true); // open a loader
}
ve buton tanımlayıp
on (click) {
this._parent.print_me()
}
dedikten sonra C# kodumuzu yazalım.
FlashToImage.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
protected void Page_Load(object sender, EventArgs e)
{
int height = Convert.ToInt32(Request["height"]);
int width = Convert.ToInt32(Request["width"]);
// create the image with desired width and height
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);
// now fill the image with blank color
// do you remember i wont pass the 0xFFFFFF pixels
// from flash?
g.FillRectangle(new SolidBrush(Color.White), 0, 0, bmp.Width, bmp.Height);
// now process every POST variable which
// contains a pixel color
for (int rows = 0; rows < height; rows++)
{
// convert the string into an array of n elements
string[] row = Request["px" + rows].ToString().Split(",".ToCharArray());
for (int cols = 0; cols < width; cols++)
{
// get the single pixel color value
string value = row[cols];
// if value is not empty (empty values are the blank pixels)
if (value != "")
{
// get the hexadecimal string (must be 6 chars length)
// so add the missing chars if needed
value = value.PadLeft(6, Convert.ToChar("0"));
// Convert the hex code color string to a standard color class.
int R = Convert.ToInt32(value.Substring(0, 2), 16);
int G = Convert.ToInt32(value.Substring(2, 2), 16);
int B = Convert.ToInt32(value.Substring(4, 2), 16);
System.Drawing.Color color = Color.FromArgb(R, G, B);
g.FillRegion(new SolidBrush(color), new Region(new Rectangle(cols, rows, 1, 1)));
}
}
}
bmp.Save(Server.MapPath("~/test.jpg"), ImageFormat.Jpeg);
g.Dispose();
bmp.Dispose();
}
Hiç yorum yok :
Yorum Gönder