Image 在J2ME中如何将图像转换为字节数组?

Image 在J2ME中如何将图像转换为字节数组?,image,java-me,bytearray,midp,lcdui,Image,Java Me,Bytearray,Midp,Lcdui,我的要求是这样的。我需要使用文件连接从手机读取文件,创建该图像的缩略图并发布到服务器。我能够使用FileConnectionAPI读取图像,也能够创建缩略图 创建缩略图后,我无法找到将该图像转换回字节[]的方法。可能吗 缩略图转换代码: private Image createThumbnail(Image image) { int sourceWidth = image.getWidth(); int sourceHeight = image.getHe

我的要求是这样的。我需要使用文件连接从手机读取文件,创建该图像的缩略图并发布到服务器。我能够使用FileConnectionAPI读取图像,也能够创建缩略图

创建缩略图后,我无法找到将该图像转换回字节[]的方法。可能吗

缩略图转换代码:

    private Image createThumbnail(Image image) {
        int sourceWidth = image.getWidth();
        int sourceHeight = image.getHeight();

        int thumbWidth = 128;
        int thumbHeight = -1;

        if (thumbHeight == -1)
            thumbHeight = thumbWidth * sourceHeight / sourceWidth;

        Image thumb = Image.createImage(thumbWidth, thumbHeight);
        thumb.getGraphics();
        Graphics g = thumb.getGraphics();

        for (int y = 0; y < thumbHeight; y++) {
            for (int x = 0; x < thumbWidth; x++) {
                g.setClip(x, y, 1, 1);
                int dx = x * sourceWidth / thumbWidth;
                int dy = y * sourceHeight / thumbHeight;
                g.drawImage(image, x - dx, y - dy);
            }
        }

        Image immutableThumb = Image.createImage(thumb);

        return thumb;
    }
私有图像创建缩略图(图像){
int sourceWidth=image.getWidth();
int sourceHeight=image.getHeight();
int thumbWidth=128;
int thumbHeight=-1;
如果(拇指高度==-1)
thumbHeight=thumbWidth*sourceHeight/sourceWidth;
Image thumb=Image.createImage(拇指宽度、拇指高度);
getGraphics();
Graphics g=thumb.getGraphics();
对于(int y=0;y
MIDP2.0是您的朋友。您可以按如下方式获取作为int数组的ARGB像素数据:

int w = theImage.getWidth();
int h = theImage.getHeight();
int[] argb = new int[w * h];
theImage.getRGB(argb, 0, w, 0, 0, w, h);
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
img.setRGB(0, 0, w, h, ints, 0, w);
然后,int数组可以用作参数,或者在桌面Java中,可以按如下方式使用:

int w = theImage.getWidth();
int h = theImage.getHeight();
int[] argb = new int[w * h];
theImage.getRGB(argb, 0, w, 0, 0, w, h);
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
img.setRGB(0, 0, w, h, ints, 0, w);

您需要显示一些有关缩略图转换的代码。你还剩下什么样的东西?您使用的是什么J2ME/第三方API?要将图像上载到服务器,我需要将此argb int数组转换为字节数组。我可以通过以下代码执行此操作:tearrayoutputstream baos=new ByteArrayOutputStream();DataOutputStream dos=新的DataOutputStream(BAS);对于(int i=0;i