最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
flash 在线视频拍照并且保存图片
时间:2022-07-02 17:01:28 编辑:袖梨 来源:一聚教程网
方法一 as 2.0
cam= Camera.get(); //抓取当前默认的摄像头图像
MyCam.attachVideo(cam);
方法二 as 2.0
var my_video:Video;
my_video.clear()
my_video._x=100;
my_video._y=40;
var my_cam:Camera = Camera.get();
my_cam.setMode(180, 140, 10, true);
my_video.attachVideo(my_cam);
shutter.onRelease = function() {
myBitmap = new flash.display.BitmapData(160, 120, true, 0);
myBitmap.draw(my_video);
var tempObj = _root.createEmptyMovieClip("photo", 100);
tempObj._x = 300;
tempObj._y = 40;
tempObj._;
tempObj._;
tempObj.attachBitmap(myBitmap, 1, "always", true);
};
方法三 as 3.0
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();
}
}
}
最后再加上一个拍照后再保存到服务器吧。jsp版式
String width");
String 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);
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(0.2f);
// save to file
ImageOutputStream outputStream2 = ImageIO
.createImageOutputStream(response.getOutputStream());
writer.setOutput(outputStream2);
writer.write(null, iioImage, param);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("w = " + w + ",h=" + h);
response.setContentType("image/jpeg");
return null;
相关文章
- 无限暖暖翩翩愿飞去怎么样 无限暖暖翩翩愿飞去能力套装介绍 12-27
- 无限暖暖流星绚烂时怎么样 无限暖暖流星绚烂时套装介绍 12-27
- 无限暖暖1.1版本流星季怎么玩 无限暖暖1.1流星季版本活动介绍 12-27
- 第五人格孽蜥耶梦加得怎么样 第五人格孽蜥耶梦加得稀世时装介绍 12-27
- 重返未来1999趋光性研究夜幕之外怎么玩 12-27
- 桃源深处有人家养怡尘世装饰大赛怎么玩 12-27