Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Feb 2011

    camera getSnapshot not behaveing as planned

    Hi all! First I want to thank in advance anyone who helps and say that I am aware that this is NOKIA forum.

    I use SE K310, MIDP 2.0, CLDC 1.1.

    My goal is to:
    1.image1 = getSnapshot from camera
    2.wait 200ms
    3.image2 = getSnapshot from camera
    4.process 2 previously captured images to see if they are different
    5.if threy are different - exit the loop and draw the 2nd image - if not, continue to loop

    Below is partial code I use, but sometimes it restarts the phone, sometimes goes very slowly.
    I am not sure if I use the newly created thread correctly and wonder if something needs to be synchronized?! Or is this in general the right way to go about?!
    How can I speed up things?

    The CaptureCanvas is set on display externaly with:

    Code below has been striped for null value checking and try-catch blocks.

    public class CaptureScreen extends Canvas implements Runnable{
    //...various variable declarations and initializations, constructor...
            public void start(){
                    quit = false;
                    Thread CaptureThread = new Thread(this,"DT");
            public void run(){
                    int[] Data1=null;
                    int[] Data2=null;
                                    capturedImage1 = captureImage();             //capture no.1
                                    Data1 = makeData(capturedImage1);       //change 1st into array of integers(pixels)
                                    capturedImage2 = captureImage();             //capture no.2
                                    Data2 = makeData(capturedImage2);       //change 2nd into array of integers(pixels)
                                    quit = differentData(Data1,Data2);             //see if images are different
            private Image captureImage() {
                    byte[] imageData = null;
                    Image img = null;
                    imageData = vc.getSnapshot("encoding=jpeg&width=120&height=160");
                    img = Image.createImage(imageData, 0, imageData.length);
                    return img;
            protected void paint(Graphics g){
                            if ((capturedImage2!=null) && quit){
                                    g.drawImage(capturedImage2, 0, 0, 0);
            public void initPlayer() {
                            playerVideo = Manager.createPlayer("capture://video?encoding=jpeg&width=120&height=160");
                            if ((vc = (VideoControl) playerVideo.getControl("VideoControl")) != null) {
                                    vc.initDisplayMode(vc.USE_DIRECT_VIDEO, this);
                                    vc.setDisplayLocation(0, 0);	
                                    vc.setDisplaySize(120, 60); 
            private int SingleColorThreshold = 15;
            private int Step = 10;
            private int ThresholdCount = 1000;
            // check if RED channel difference in every 10th(Step) pixel between 2 images is greater the SingleColorThreshold
           // if 2 pixels are recognized as different then increase the counter
           // run the for loop as long as counter is less than ThresholdCount
            public final synchronized  boolean differentData(int[] Data1, int[] Data2) throws IOException {
                    count = 0;
                    boolean temp = false;
                    for (int i = 0; i < Data1.length; i += Step) {
                            if (java.lang.Math.abs(((Data2[i]>>16) & 0xff) - ((Data1[i] >> 16) & 0xff)) > SingleColorThreshold) {
                    return temp;
            private int[] makeData(Image img) {
                    int[] DataTemp = null;
                    DataTemp = new int[img.getWidth() * img.getHeight()];
                    img.getRGB(DataTemp, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
                    return DataTemp;
            public void stop() {
                            vc = null;
                            playerVideo = null;
                            playerSound = null;
    In short, all I want to do is capture images(in loop) on Sony Erricsson k310 and stop if they are different.
    I havent figured it out what encodings are for setting gray capturing. I belive the device is capable of capturing in gray through j2me because there are options for gray capturing when using phones own camera software.

    I would appreciate if anyone could help me with this or at least give me some pointers and information. Thank you!

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Cheshire, UK

    Re: camera getSnapshot not behaveing as planned

    There is some sample code in the wiki...


Similar Threads

  1. Why Was The N93i Discontinued/ Not launch in the USA as planned.
    By Techops in forum General Development Questions
    Replies: 3
    Last Post: 2010-10-20, 08:54
  2. Camera : alternative to getSnapshot()
    By hxvvhxvv in forum Mobile Java General
    Replies: 2
    Last Post: 2008-10-20, 14:45
  3. Replies: 0
    Last Post: 2006-12-08, 08:08
  4. N70: getSnapshot() always activates camera flash
    By mobile07 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2006-08-31, 20:26
  5. Camera support planned for 3rd edition emulator?
    By jlamberg in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2006-02-01, 11:12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts