Flex and. NET Interop (15): Using byte array (ByteArray) in FluorineFX to upload pictures
A few days ago a friend asked me a question, he said: "I use HTTP interface or WebService interface can achieve picture upload function, then use FLUORINEFX how to achieve picture upload function?" ", in fact, look at the official documents and sample programs themselves can find the answer, upload can have a lot of implementations, here I have provided by the official sample as the basis for a little change, through the ByteArray class to achieve picture upload."
First set up FluorineFX Library and Web site, in the remote server class to add a processing file upload method, the detailed code is as follows:
namespace Bytestream.services
{
[Remotingservice]
public class Bytestreamservice
{
public ByteArray uploadimage (ByteArray ba)
{
MemoryStream ms = new MemoryStream (BA. GetBuffer ());
Image img = bitmap.fromstream (ms);
Bitmap newimage = new Bitmap (IMG);
MemoryStream tempstream = new MemoryStream ();
Newimage.save (Tempstream, System.Drawing.Imaging.ImageFormat.Png);
String path = HttpContext.Current.Server.MapPath ("Upload/bytearray.png");
FileStream fs = new FileStream (path, filemode.create);
Tempstream.writeto (FS);
FS. Close ();
ByteArray result = new ByteArray (tempstream);
return result;
}
}
}
The way to handle image uploads is to wrap the byte array passed by the flex client into a memory stream, and then save the picture in the specified directory by writing a file. The example provides a drawing board that allows the user to choose a color to draw a different image and then save it to a directory specified on the server. The implementation of the drawing board is based on the movement of the mouse down the line, the code is as follows:
private function doMouseDown():void
{
x1 = myCanvas.mouseX;
y1 = myCanvas.mouseY;
isDrawing = true;
}
private function doMouseMove():void
{
x2 = myCanvas.mouseX;
y2 = myCanvas.mouseY;
if (isDrawing)
{
myCanvas.graphics.lineStyle(2, drawColor);
myCanvas.graphics.moveTo(x1, y1);
myCanvas.graphics.lineTo(x2, y2);
x1 = x2;
y1 = y2;
}
}
private function doMouseUp():void
{
isDrawing = false;
}
//清空画图板
private function onErase (event:MouseEvent):void
{
myCanvas.graphics.clear();
}