You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement Bitmap.compress()
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package android.graphics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.Buffer;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
@@ -27,6 +29,11 @@ public final class Bitmap {
|
||||
}
|
||||
}
|
||||
|
||||
public enum CompressFormat {
|
||||
JPEG,
|
||||
PNG,
|
||||
}
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private int stride;
|
||||
@@ -190,6 +197,16 @@ public final class Bitmap {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean compress(Bitmap.CompressFormat format, int quality, OutputStream stream) throws IOException {
|
||||
if (format == CompressFormat.PNG) {
|
||||
stream.write(native_save_to_png(getTexture()));
|
||||
return true;
|
||||
} else {
|
||||
stream.write(("fixme Bitmap.compress " + format.name()).getBytes());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
@@ -209,4 +226,5 @@ public final class Bitmap {
|
||||
private static native long native_ref_texture(long texture);
|
||||
private static native void native_get_pixels(long texture, int[] pixels, int offset, int stride, int x, int y, int width, int height);
|
||||
private static native void native_copy_to_buffer(long texture, Buffer buffer, int memory_format, int stride);
|
||||
private static native byte[] native_save_to_png(long texture);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user