Omid Gharib
Omid Gharib

Reputation: 321

what is alternative of java.awt.image.BufferedImage in codenameone

Hi I need something like bufferedImage object in java.awt.image.BufferedImage. how is it possible to define something like this in codenameone?

updated: this is a class that i want to port to the 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
}

}

Upvotes: 0

Views: 1508

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

Image.create(width,height,argbBackground) will create an image you can modify. You can load an image from a stream or a byte array using the many static methods in that class and we have our own ImageIO API to save an image.

Upvotes: 1

Related Questions