首页 文章

什么是codenameone中java.awt.image.BufferedImage的替代方法

提问于
浏览
0

嗨我需要像java.awt.image.BufferedImage中的bufferedImage对象 . 怎么可能在codenameone中定义这样的东西?

更新:这是一个我想要移植到codenameone的类

package org.rajman.map.awt;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.imageio.ImageIO;

import org.rajman.core.graphics.Bitmap;

class AwtBitmap implements Bitmap {
    final BufferedImage bufferedImage;

    AwtBitmap(InputStream inputStream) throws IOException {
       this.bufferedImage = ImageIO.read(inputStream);
        if (this.bufferedImage == null) {
           throw new IOException("ImageIO filed to read inputStream");
        }
}

AwtBitmap(int width, int height) {
    this.bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
}

@Override
public void compress(OutputStream outputStream) throws IOException {
    ImageIO.write(this.bufferedImage, "png", outputStream);
}

@Override
public void decrementRefCount() {
    // no-op
}

@Override
public int getHeight() {
    return this.bufferedImage.getHeight();
}

@Override
public int getWidth() {
    return this.bufferedImage.getWidth();
}

@Override
public void incrementRefCount() {
    // no-op
}

@Override
public void scaleTo(int width, int height) {
    // TODO implement
}

@Override
public void setBackgroundColor(int color) {
    // TODO implement
}

}

1 回答

  • 1

    Image.create(width,height,argbBackground) 将创建您可以修改的图像 . 您可以使用该类中的许多静态方法从流或字节数组加载图像,我们有自己的 ImageIO API来保存图像 .

相关问题