Bitmap.getPngEncodedData improvements, PR #71
This commit is contained in:
parent
44b40608f6
commit
a5679ce214
@ -1,5 +1,7 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 Longri
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -21,6 +23,8 @@ import android.graphics.BitmapFactory;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLUtils;
|
||||
|
||||
import org.oscim.utils.IOUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
@ -44,13 +48,6 @@ 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
|
||||
*/
|
||||
@ -108,4 +105,16 @@ public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
|
||||
|
||||
mBitmap.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPngEncodedData() {
|
||||
ByteArrayOutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = new ByteArrayOutputStream();
|
||||
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
|
||||
return outputStream.toByteArray();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 Longri
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -21,6 +23,8 @@ import android.graphics.BitmapFactory;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLUtils;
|
||||
|
||||
import org.oscim.utils.IOUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
@ -44,13 +48,6 @@ 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
|
||||
*/
|
||||
@ -108,4 +105,16 @@ public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
|
||||
|
||||
mBitmap.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPngEncodedData() {
|
||||
ByteArrayOutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = new ByteArrayOutputStream();
|
||||
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
|
||||
return outputStream.toByteArray();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
* Copyright 2016 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -23,6 +24,9 @@ import com.badlogic.gdx.utils.BufferUtils;
|
||||
import org.oscim.backend.GL;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.renderer.bucket.TextureBucket;
|
||||
import org.oscim.utils.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -34,6 +38,8 @@ import java.nio.IntBuffer;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class AwtBitmap implements Bitmap {
|
||||
private static final Logger log = LoggerFactory.getLogger(AwtBitmap.class);
|
||||
|
||||
BufferedImage bitmap;
|
||||
int width;
|
||||
int height;
|
||||
@ -154,13 +160,17 @@ public class AwtBitmap implements Bitmap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPngEncodedData(){
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
public byte[] getPngEncodedData() {
|
||||
ByteArrayOutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = new ByteArrayOutputStream();
|
||||
ImageIO.write(this.bitmap, "png", outputStream);
|
||||
return outputStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -189,14 +189,6 @@ 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
|
||||
*
|
||||
@ -228,4 +220,11 @@ public class IosBitmap implements Bitmap {
|
||||
Color.r(color))
|
||||
.getCGColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPngEncodedData() {
|
||||
UIImage uiImage = new UIImage(cgBitmapContext.toImage());
|
||||
NSData data = uiImage.toPNGData();
|
||||
return data.getBytes();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -99,4 +100,9 @@ public class GwtBitmap implements Bitmap {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPngEncodedData() {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public class GwtGdxGraphics extends CanvasAdapter {
|
||||
|
||||
@Override
|
||||
public Bitmap decodeSvgBitmapImpl(InputStream in) {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user