更新图像

发布于 2024-09-06 09:08:52 字数 84 浏览 1 评论 0原文

我正在开发一个使用一些图像的应用程序。我们需要在图像上打印一些文本,但这不是固定的意思,当更改变量值时会自动更改文本。简单地说,我们在图像上打印一个变量?

i am developing an application that use some images. We require some text print on image but that is not a fixed mean when change the variable value automatically change the text. Simply we say that we print a variable on image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兮颜 2024-09-13 09:08:52

试试这个

 public class Test extends UiApplication {

        public static void main(String[] arg) {
            Test app = new Test();
            app.enterEventDispatcher();
        }

        public Test() {
            MyScreen screen = new MyScreen();
            pushScreen(screen);
        }
    }
    class MyScreen extends MainScreen {
        LabelField label;
        public MyScreen() {
            label = new LabelField() {
                protected void paint(Graphics g) {
                    Bitmap bitmap = Bitmap.getBitmapResource("bgimage.jpg");
                    g.drawBitmap(0, 0, getWidth(), getHeight(), bitmap, 0, 0);
                    super.paint(g);
                }
            };

            ButtonField button = new ButtonField("update") {
                protected void fieldChangeNotify(int context) {
                    update();
                    super.fieldChangeNotify(context);
                }
            };

            add(label);
            add(button);
        }

        public void setMessage(String message) {
            synchronized (UiApplication.getEventLock()) {
                label.setText(message);
            }
        }

        private void update() {
            LocationHandler handler = new LocationHandler(this);
            handler.start();
        }
    }

    class LocationHandler extends Thread {
        private MyScreen screen;

        public LocationHandler(MyScreen screen) {
            this.screen = screen;
        }

        public void run() {

            Criteria criteria = new Criteria();
            criteria.setVerticalAccuracy(50);
            criteria.setHorizontalAccuracy(50);
            criteria.setCostAllowed(true);
            criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
            try {

                LocationProvider provider = LocationProvider.getInstance(criteria);
                Location location = provider.getLocation(-1);
                String speed = location.getSpeed() + "m/s";
                screen.setMessage(speed);
            } catch (LocationException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }

try this

 public class Test extends UiApplication {

        public static void main(String[] arg) {
            Test app = new Test();
            app.enterEventDispatcher();
        }

        public Test() {
            MyScreen screen = new MyScreen();
            pushScreen(screen);
        }
    }
    class MyScreen extends MainScreen {
        LabelField label;
        public MyScreen() {
            label = new LabelField() {
                protected void paint(Graphics g) {
                    Bitmap bitmap = Bitmap.getBitmapResource("bgimage.jpg");
                    g.drawBitmap(0, 0, getWidth(), getHeight(), bitmap, 0, 0);
                    super.paint(g);
                }
            };

            ButtonField button = new ButtonField("update") {
                protected void fieldChangeNotify(int context) {
                    update();
                    super.fieldChangeNotify(context);
                }
            };

            add(label);
            add(button);
        }

        public void setMessage(String message) {
            synchronized (UiApplication.getEventLock()) {
                label.setText(message);
            }
        }

        private void update() {
            LocationHandler handler = new LocationHandler(this);
            handler.start();
        }
    }

    class LocationHandler extends Thread {
        private MyScreen screen;

        public LocationHandler(MyScreen screen) {
            this.screen = screen;
        }

        public void run() {

            Criteria criteria = new Criteria();
            criteria.setVerticalAccuracy(50);
            criteria.setHorizontalAccuracy(50);
            criteria.setCostAllowed(true);
            criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
            try {

                LocationProvider provider = LocationProvider.getInstance(criteria);
                Location location = provider.getLocation(-1);
                String speed = location.getSpeed() + "m/s";
                screen.setMessage(speed);
            } catch (LocationException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文