J2ME 拍照API:getSnapshot参数设置大全

最近做摄像头相关软件,发现这个参数设置有门道,API链了无数回,终于找到了这段对截图参数的详细设置,大家可以参考下。

Describing the video or image encodings:

     video_encodings   = video_enc_param *( "&" video_param )
     video_enc_param   = "encoding=" video_enc
     video_enc         = "gray8" / "rgb888" / "bgr888" /
                         "rgb565" / "rgb555" / "yuv444" /
                         "yuv422" / "yuv420" / "jpeg" / "png" /
                         content_type
     video_param       = "width=" width /
                         "height=" height /
                         "fps=" fps /
                         "colors=" colors /
                         "progressive=" progressive /
                         "interlaced=" interlaced /
                         "type=" video_type
     width             = pos_integer
     height            = pos_integer
     fps               = pos_number
     quality           = pos_integer
     colors            = "p" colors_in_palette /
                       = "rgb" r_bits g_bits b_bits /
                       = "gray" gray_bits
     colors_in_palette = pos_integer
     r_bits            = pos_integer
     g_bits            = pos_integer
     b_bits            = pos_integer
     gray_bits         = pos_integer
     progressive       = boolean
     video_type        = jfif / exif / other_type
     other_type        = alphanumeric
     interlaced        = boolean
     pos_number        = 1*DIGIT [ "." 1*DIGIT ]
     boolean           = "true" / "false"
 
   and
     content type is given in the MIME syntax.
 
    Examples:

     encoding=gray8&width=160&height=120
     encoding=jpeg&quality=80&progressive=true&type=jfif
         (progressive JPEG with quality 80 in jfif format)
     encoding=jpeg&type=exif
         (JPEG in exif format)
     encoding=png&colors=rgb888
         (24 bits/pixel PNG)
     encoding=rgb888
         (raw 24-bit rgb image)
     encoding=rgb&colors=rgb888
         (raw 24-bit rgb image)


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/c30gcrk/archive/2007/08/28/1762299.aspx

展开阅读全文

J2ME 手机拍照问题

01-15

rtrn大家好:rn我是用Eclipse编写的一个J2ME手机拍照程序。rn代码如下:rnpackage cam;rnrnrnimport javax.microedition.io.Connector;rnimport javax.microedition.io.file.FileConnection;rnimport javax.microedition.lcdui.*;rnimport javax.microedition.media.*;rnimport javax.microedition.media.control.*;rnimport java.io.IOException;rnimport java.io.OutputStream;rnimport java.util.Calendar;rnrn// The CameraScreen class shows the live viewrn// of the camera using the MMAPI and givesrn// commands to capture the contents of the camerarnclass CameraScreenrn extends Canvasrn implements CommandListener rn private final cam midlet;rn private final Command exitCommand;rn private Player player = null;rn private Command captureCommand = null;rn private VideoControl videoControl = null;rn CameraScreen(cam midlet) rn this.midlet = midlet;rn rn // Builds the user interfacern exitCommand = new Command("退出", Command.EXIT, 1);rn addCommand(exitCommand);rn captureCommand = new Command("拍照", Command.SCREEN, 1);rn addCommand(captureCommand);rn setCommandListener(this); rn rn rn // Paint the canvas' background in blackrn public void paint(Graphics g) rn // black backgroundrn g.setColor(0xFFFFFF); rn g.fillRect(0, 0, getWidth(), getHeight());rn rn rn public void commandAction(Command c, Displayable d) rn if (c == exitCommand) rn midlet.exitApplication();rn else if (c == captureCommand) rn captureImage();rn rn rn rn public void keyPressed(int keyCode) rn if (getGameAction(keyCode) == FIRE) rn captureImage();rn rn rn rn // Creates and starts the video playerrn synchronized void start() rn try rn player = Manager.createPlayer("capture://video");rn player.realize();rn // Get VideoControl for the viewfinderrn videoControl = (VideoControl)player.getControl("VideoControl");rn if (videoControl == null) rn discardPlayer();rn // midlet.showError("Cannot get the video control.\n"rn // +"Capture may not be supported.");rn player = null;rn else rn // Set up the viewfinder on the screen.rn videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,rn this);rn int canvasWidth = getWidth();rn int canvasHeight = getHeight();rn// int displayWidth = videoControl.getDisplayWidth();rn// int displayHeight = videoControl.getDisplayHeight();rn// int x = (canvasWidth - displayWidth) / 2;rn// int y = (canvasHeight - displayHeight) / 2;rn// videoControl.setDisplayLocation(x, y);rn videoControl.setDisplayLocation(2, 2);rn videoControl.setDisplaySize(canvasWidth - 4, canvasHeight - 4);rn player.start();rn videoControl.setVisible(true);rn rn catch (IOException ioe) rn discardPlayer();rn // midlet.showError("IOException: " + ioe.getMessage());rn catch (MediaException me) rn // midlet.showError("MediaException: " + me.getMessage());rn catch (SecurityException se) rn // midlet.showError("SecurityException: " + se.getMessage());rn rn rn rn // Stops the video playerrn synchronized void stop() rn if (player != null) rn try rn videoControl.setVisible(false);rn player.stop();rn catch (MediaException me) rn // midlet.showError("MediaException: " + me.getMessage());rn rn rn rn rn // this method will discard the video playerrn private void discardPlayer() rn if (player != null) rn player.deallocate();rn player.close();rn player = null;rn rn videoControl = null;rn rn rn // captures the image from the video playerrn // in a separate threadrn private void captureImage() rn if (player != null) rn // Capture image in a new thread.rn new Thread() rn public void run() rn try rn byte[] pngImage =rn videoControl.getSnapshot(null);rn midlet.imageCaptured(pngImage);rn videoControl.setVisible(false); rn discardPlayer();rn// 获取时间 rn String strtime=gettime(); rn try rn FileConnection conn = (FileConnection) Connector.open("file:///root1/"+strtime+".png", rn Connector.READ_WRITE); rn if (conn.exists()) rn conn.delete(); rn conn.create(); rn else rn conn.create(); rn rn OutputStream os = conn.openOutputStream(); rnrn os.write(pngImage); rn os.flush(); rn os.close(); rn conn.close(); rnrn catch (IOException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn catch (MediaException me) rn // midlet.showError("MediaException: " + me.getMessage());rn catch (SecurityException se) rn //midlet.showError("SecurityException: " + se.getMessage());rn rn rn rn rn .start();rn rn rn public String gettime() rn rn Calendar cal=Calendar.getInstance(); rn int year=cal.get(Calendar.YEAR); rn int month=cal.get(Calendar.MONTH); rn int day=cal.get(Calendar.DATE); rn int hour=cal.get(Calendar.HOUR); rn int minute=cal.get(Calendar.MINUTE); rn int second=cal.get(Calendar.MINUTE); rn String time=year+"-"+month+"-"+day+"-"+hour+"-"+minute+"-"+second; rn return time; rn rn rnrn我在WTK的模拟器上运行这个程序。一点问题都没有。也可以看到我拍的照看。rn当我把这个程序打包成JAR文件时,放到真机(Nokia5130)上测试的时候。rn按下拍照键,程序完全没有反应。rn小弟刚接触J2ME。请知道的告诉小弟点。rn在这里不胜感激。 论坛

没有更多推荐了,返回首页