当前位置: 代码迷 >> ASP.NET >> [讨论]asp.net(C#)+Flash在线拍照功能解决思路
  详细解决方案

[讨论]asp.net(C#)+Flash在线拍照功能解决思路

热度:1273   发布时间:2013-02-25 00:00:00.0
[讨论]asp.net(C#)+Flash在线拍照功能
想实现asp.net(C#)+Flash在线拍照功能,搜了一大圈,只找到了jsp版的,代码如下:


主要用到Camera类,MovieClip   类,BitmapData类,LoadVars类,如果要实现这个功能,必须先去了解这几个类

实现的过程如下。

1,先在库中新建一个视频元件,把视频元件拖放到场景中,取名为my_video,新建一个按纽元件,取名为btn_print.

2,加入以下代码实现视频的播放
myCam   =   Camera.get();
myCam.setMode(266,200,10);
my_video.attachVideo(myCam);

3   ,以下代码实现图片的获得和上传
import   flash.display.BitmapData;
import   flash.geom.Rectangle;
import   flash.geom.ColorTransform;

class   PrintScreen   {

public   var   addListener:Function
public   var   broadcastMessage:Function

private   var   id:   Number;
public   var   record:LoadVars;

function   PrintScreen(){
AsBroadcaster.initialize(   this   );
}
public   function   print(mc:MovieClip,   w:Number,   h:Number){
broadcastMessage( "onStart ",   mc);
w   =   Math.floor(w);
h   =   Math.floor(h);
var   bmp:BitmapData   =   new   BitmapData(w,   h,   false);
record   =   new   LoadVars();
record.width   =   w
record.height   =   h
record.cols   =   0
record.rows   =   0
bmp.draw(mc);
id   =   setInterval(copysource,   1,   this,   mc,   bmp);
}

private   function   copysource(scope,   movie,   bit){
var   pixel:Number
var   str_pixel:String
scope.record[ "px "   +   scope.record.rows]   =   new   Array();
for(var   a   =   0;   a   <   bit.width;   a++){
pixel   =   bit.getPixel(a,   scope.record.rows   )
str_pixel   =   pixel.toString(16)
scope.record[ "px "   +   scope.record.rows].push(str_pixel)
}

scope.record.rows   +=   1
if(scope.record.rows   > =   bit.height){
clearInterval(scope.id)
bit.dispose();
}
}
}

4   以下代码在服务器段接受数据,生成图片(jsp版)
String   width   =   request.getParameter( "width ");
String   height   =   request.getParameter( "height ");
int   w   =   Integer.parseInt(width);
int   h   =   Integer.parseInt(height);
try   {
OutputStream   fos   =   response.getOutputStream();
BufferedImage   bf   =   new   BufferedImage(w,   h,
BufferedImage.TYPE_INT_RGB);

for   (int   i   =   0;   i   <   bf.getHeight();   i++)   {
String   data   =   request.getParameter( "px "   +   i);
String[]   ds   =   data.split( ", ");
for   (int   j   =   0;   j   <   bf.getWidth();   j++)   {
int   d   =   Integer.parseInt(ds[j],   16);
bf.setRGB(j,   i,   d);
}
}

ImageWriter   writer   =   null;
ImageTypeSpecifier   type   =   ImageTypeSpecifier
.createFromRenderedImage(bf);
Iterator   iter   =   ImageIO.getImageWriters(type,   "jpg ");
if   (iter.hasNext())   {
writer   =   (ImageWriter)   iter.next();
}
if   (writer   ==   null)   {
return   null;
}
IIOImage   iioImage   =   new   IIOImage(bf,   null,   null);
  相关解决方案