如何从 Image 对象获取 byte[] 数据?

发布于 2024-11-28 16:47:21 字数 64 浏览 1 评论 0原文

我有根据移动内存中存储的图像创建的图像对象。我想获取这些 Image 对象的 byte[] 值。如何实现这一目标?

I have Image objects created from images stored in the mobile memory. I want to get the byte[] value of these Image objects. How to achieve that ?

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

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

发布评论

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

评论(1

英雄似剑 2024-12-05 16:47:21

您可以使用以下方法将com.sun.lwuit.Image转换为byte[]。

public byte[] imageProcessing(String imageName, Image image) {

        int[] rgb = image.getRGB();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        dos.writeUTF(imageName);

        for (int i = 0; i < rgb.length; i++) {
            dos.writeInt(rgb[i]);
        }

   return baos.toByteArray();
 }

You can use below method to convert the com.sun.lwuit.Image to byte[].

public byte[] imageProcessing(String imageName, Image image) {

        int[] rgb = image.getRGB();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        dos.writeUTF(imageName);

        for (int i = 0; i < rgb.length; i++) {
            dos.writeInt(rgb[i]);
        }

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