0

我有两个问题。

第一个是关于更新 UI,第二个是当我尝试连接到相机以获取 mjpeg 流并运行 getResponseCode() 时,应用程序锁定在那里。MDS 显示大量数据传输。

我有一些课程,例如.....:

Http extends Thread {
  public abstract String getUrl();
  public abstract String getBase64Encode();
  public abstract void onReturn(int responseCode, InputStream is,int lenght);
  protected abstract void onError(Exception e);
}

CameraHttp 扩展了 Http 并且 MjpegHttp 扩展了 CameraHttp。

http 连接到一个 URL,该 URL 是 jpeg 或 mjpeg 相机地址。

我有一个相机课。它使用被覆盖的方法 mjpegconnection.go() 开始连接;我在 ViewCam 屏幕上也有一个静态位图,它扩展了 MainScreen。

启动后:

url = getUrl();
queryString = encodeURL(queryString);
byte postmsg[] = queryString.getBytes("UTF-8");
httpConnection = (HttpConnection) Connector.open(url
    + ";deviceside=false", Connector.READ_WRITE);
httpConnection.setRequestMethod(HttpConnection.GET);
httpConnection.setRequestProperty("Authorization", getBase64Encode());
os = httpConnection.openDataOutputStream(); 

for (int i = 0; i < postmsg.length; i++) {
    os.write(postmsg[i]);
}
{
     if (!cancel) {
         System.out.println(httpConnection.getURL()+ 
             " *****"+httpConnection.getPort());
         System.out.println("onreturn oncesi"
             + httpConnection.getResponseCode());
         onReturn(httpConnection.getResponseCode(), httpConnection
             .openInputStream(),(int) httpConnection.getLength());

         System.out.println("onreturn sornrası");
     }
     os.close();
     httpConnection.close();
}
} catch (Exception e) {
    System.out.println("hata " + e.getMessage());
    try {
        httpConnection.close();
        Thread.sleep(60);
    } catch (Exception ie) {
}
onError(e);
}

做某事之后

 // decides mjpeg-jpeg stream
 // if it is mjpeg, direct to parser,
 // else it sets image with setImage() and return to connection with go();
 public void parse(InputStream is, int lenght) {
     try {
         if (!type.isMjpegStream()) {
             setImage(is, lenght);
             System.gc();
             StaticVar.ActiveCam.setConnected(true);
         } else { 
             if (parser == null) {
             parser = new JpegParser(is, this);
         } else {
             parser.setInputSteam(is, this);
         }
         parser.parse();
         is.close();
     }
     } catch (Exception e) {
     } 
}

 public void setImage(InputStream is, int lenght) {
     byte[] raw = new byte[lenght];
     try {
         is.read(raw);
         currentImage = Bitmap.createBitmapFromBytes(raw, 0, raw.length, 1);
         ViewCam.ViewCam=currentImage;       //static var.
     } catch (IOException e) {
         System.out.println("catche***********");
         // TODO Auto-generated catch block
         e.printStackTrace();
     }
 }

如何重新绘制屏幕以显示位图?

还有我的 ViewCam

public class ViewCam extends MainScreen {
Header header;
String headerString;
public static Bitmap ViewCam;// cam image shows
private static Thread My;// runs connection

void OnStart() {
    My = new Thread() {
        public void run() {
            System.out.println("ONSTART");
            StaticVar.ActiveCam.go();
        };
    };
    My.start();
    Bitmap bitmap = Bitmap.getBitmapResource("res/main.png");
    Bitmap bmp2 = ResizeImage.resizeBitmap(bitmap, Display.getWidth(),
            Display.getHeight());
    Background bg = BackgroundFactory.createBitmapBackground(bmp2);
    this.setBackground(bg);
    this.getMainManager().setBackground(bg);


}


public ViewCam() {
    StaticVar.ActiveCam.getIp();

    OnStart();

    headerString ="Cam View";
    header = new Header("res/bartop.png", headerString, 0);
    add(header);

    ViewCam = Bitmap.getBitmapResource("res/spexco_splash.png");
    ViewCam = ResizeImage.bestFit(ViewCam, Display.getWidth(), Display
            .getHeight());
    BitmapField bf = new BitmapField(ViewCam);
    add(bf);
}
}
4

1 回答 1

1

尝试 Screen.invalidate()

公共无效无效(int x,int y,int 宽度,int 高度)

使该屏幕的一个区域无效。
此方法将此屏幕的一个区域标记为需要重新绘制。重绘稍后由主事件调度线程处理。

注意:任何线程都可以安全地调用此方法,并且不需要在事件锁上进行同步。

覆盖:
类管理器中的无效
参数:
x - ContentRect 坐标中区域的左边缘。
y - ContentRect 坐标中区域的顶部边缘。
width - 区域的宽度(以像素为单位)。
height - 区域的高度(以像素为单位)。

于 2010-11-12T11:59:04.513 回答