开发者

Java Graphics2D streaming?

Is there a way in java to use Graphics2D API to paint on screen of remote java process? Any API to stream and deserialize painting instructions?

Or I have to use my own "api call" serialization/deserialization mechanis开发者_C百科m?


That really depends on the kind of media you're dealing with. If you're playing video, the codec you're using might have be APIs to do this, but you'll need to search around to find out. Graphics2D is really meant for more primitive painting operations, such as drawing shapes, rendering text, and copying image data from place to place.

If you're writing your own streaming algorithm, then it could be as simple as defining a PaintEvent class that does what you need. The idea of the PaintEvent class would be that it contains instructions of what to do. For example, if you draw a circle with radio 50 on the remote system, then rather than transmit the pixel data over the network, it's much more efficient to transmit a message that basically says, "draw a circle with radius 50" across the network, and have the client render it on their side.

A PaintEvent class, I would think, would look something like this:

public class PaintEvent {
  public static final int OPER_DRAW_CIRCLE = 0;
  public static final int OPER_DRAW_RECT   = 1;
  public static final int OPER_DRAW_TEXT   = 2;
  ...etc...

  int paintOperationID;
  int[] paintDetails;           // where 'paintDetails' contains data such as a circle's radius, a rectangle's dimensions, the (x, y) location where to render text, etc.
  java.awt.Color renderColor;
  String text;

  public PaintEvent(int paintOperationID, int[] paintDetails, Color renderColor, String text) {
     ...
  }

}

So, depending on what the paintOperationID is, it would treat the data in paintDetails differently. And unless it's a OPER_DRAW_TEXT operation, the text field would just be ignored.

This is one way to do it, anyway. Then you just design a communications protocol around this, to get the data from one place to another.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜