Flex and. NET Interop (15)

Source: Internet
Author: User
Tags file upload

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();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.