以前发过一个抓图的,没有实现存储,这次给完成,主要就下面些
Flash部分:因为以前发过,这次就主要发传数据的部分,看不懂得可以去搜Flash视频+抓图
//传值
var send_lv:LoadVars=new LoadVars();
var load_lv:LoadVars=new LoadVars();
load_lv.onLoad=function(success) {
trace("ok");
}
//抓图///
import flash.display.BitmapData;
var pixData:String="";
photo_btn.onRelease=function(){
var WIDTH:Number=my_video.width;
var HEIGHT:Number=my_video.height;
timer=getTimer();
var bd:BitmapData=new BitmapData(WIDTH/2.5,HEIGHT/2.5,false,0x00CCCCCC);
bd.draw(my_video);
var tempObj:MovieClip = _root.createEmptyMovieClip("tempObj", 100);
tempObj._x = 50;
tempObj._y = 25;
tempObj.attachBitmap(bd, 1, "always", true);
var space:Array=new Array("cao","00000","0000","000","00","0");
for(var i=0;i<160;i++) {
for(var j=0;j<120;j++) {
pixInfo=bd.getPixel(i,j).toString(16);
if(pixInfo.length<6){
pixInfo=space[pixInfo.length]+pixInfo;
}//endif
pixData+=pixInfo+",";//String.fromCharCode(pixInfo)+",";
}//endfor1
}//endfor2
trace(pixData.length);
}
save_btn.onRelease=function(){
send_lv.pixData=pixData;
send_lv.sendAndLoad("http://127.0.0.1:8080/test/ProcessPixServlet",load_lv,"POST");
}
Servlet:
CreateJPEG.java
/*createimage class
* write by 烟头
*2007/04/26
*/
import
java.io.
*
;
import
java.util.
*
;
import
com.sun.image.codec.jpeg.
*
;
import
java.awt.image.
*
;
import
java.awt.
*
;

public
class
CreateJPEG
...
{
BufferedImageimage;
privateStringpixData=null;


publicStringgetPixData()...{
returnthis.pixData;
}

publicvoidsetPixData(StringpixData)...{
this.pixData=pixData;
}

publicvoidcreateJpg(Stringpath)...{

try...{
FileOutputStreamfos=newFileOutputStream(path);
BufferedOutputStreambos=newBufferedOutputStream(fos);
JPEGImageEncoderencoder=JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image);
bos.close();

}catch(FileNotFoundExceptionfnfe)...{
System.out.println(fnfe);

}catch(IOExceptionioe)...{
System.out.println(ioe);
}
}

publicvoiddrawImage()...{
intwidth=160,height=120;


CreateJPEGjg=newCreateJPEG();
jg.image=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphicsg=jg.image.getGraphics();


try...{
BufferedWriterwriterBuff=newBufferedWriter(newFileWriter("d:/ww.txt"));
writerBuff.write(pixData,0,pixData.length());
writerBuff.close();
}
catch(IOExceptione)

...{
System.out.println(e.toString());
}

String[]pixInfo=pixData.split(",");
System.out.println(pixInfo.length);
intcount=0;

for(inti=0;i<width;i++)...{

for(intj=0;j<height;j++)...{

StringpixRStr=pixInfo[count].substring(0,2);
StringpixGStr=pixInfo[count].substring(2,4);
StringpixBStr=pixInfo[count].substring(4);

intpixR=Integer.parseInt(pixRStr,16);
intpixG=Integer.parseInt(pixGStr,16);
intpixB=Integer.parseInt(pixBStr,16);
//System.out.println("R:"+pixR+"=G:"+pixG+"+B:"+pixB);
g.setColor(newColor(pixR,pixG,pixB));

g.fillRect(i,j,1,1);
count++;
}
}
jg.createJpg("d:/myJPG.jpg");
}
}
web.xml
<?
xmlversion="1.0"encoding="UTF-8"
?>
<
web-app
id
="WebApp_ID"
version
="2.4"
xmlns
="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>
<
display-name
>
test
</
display-name
>

<
servlet
>
<
servlet-name
>
ProcessPixServlet
</
servlet-name
>
<
servlet-class
>
SavePixInfo
</
servlet-class
>
</
servlet
>


<
servlet-mapping
>
<
servlet-name
>
ProcessPixServlet
</
servlet-name
>
<
url-pattern
>
/ProcessPixServlet
</
url-pattern
>
</
servlet-mapping
>

</
web-app
>
源文件就不发了,如果看不懂得话建议去翻翻帮助
烟头 2007-04-26