Bitmap: get png encoded data implementation
This commit is contained in:
parent
fab7020d3d
commit
44b40608f6
@ -21,6 +21,7 @@ import android.graphics.BitmapFactory;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static android.graphics.Bitmap.Config.ARGB_8888;
|
||||
@ -43,6 +44,13 @@ public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
|
||||
return mBitmap != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPngEncodedData() {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
this.mBitmap.compress(Bitmap.CompressFormat.PNG, 0, outputStream);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param format ignored always ARGB8888
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ import android.graphics.BitmapFactory;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static android.graphics.Bitmap.Config.ARGB_8888;
|
||||
@ -43,6 +44,13 @@ public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
|
||||
return mBitmap != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPngEncodedData(){
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
this.mBitmap.compress(Bitmap.CompressFormat.PNG, 0, outputStream);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param format ignored always ARGB8888
|
||||
*/
|
||||
|
@ -25,6 +25,7 @@ import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.renderer.bucket.TextureBucket;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -151,4 +152,15 @@ public class AwtBitmap implements Bitmap {
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPngEncodedData(){
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(this.bitmap, "png", outputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
@ -189,6 +189,13 @@ public class IosBitmap implements Bitmap {
|
||||
return this.cgBitmapContext != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPngEncodedData() {
|
||||
UIImage uiImage = new UIImage(cgBitmapContext.toImage());
|
||||
NSData data = uiImage.toPNGData();
|
||||
return data.getBytes();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a ByteArray from InputStream
|
||||
|
@ -62,4 +62,6 @@ public interface Bitmap {
|
||||
void uploadToTexture(boolean replace);
|
||||
|
||||
boolean isValid();
|
||||
|
||||
byte[] getPngEncodedData();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user