Revision: 2477
http://sourceforge.net/p/swingme/code/2477
Author: yuranet
Date: 2021-06-25 12:09:34 +0000 (Fri, 25 Jun 2021)
Log Message:
-----------
create image from bytes
Modified Paths:
--------------
iOSME/src/javax/microedition/lcdui/Image.java
Modified: iOSME/src/javax/microedition/lcdui/Image.java
===================================================================
--- iOSME/src/javax/microedition/lcdui/Image.java 2021-06-25 11:43:53 UTC (rev 2476)
+++ iOSME/src/javax/microedition/lcdui/Image.java 2021-06-25 12:09:34 UTC (rev 2477)
@@ -8,6 +8,8 @@
import android.graphics.ColorMatrix;
import org.moe.natj.general.ptr.BytePtr;
import org.moe.natj.general.ptr.impl.PtrFactory;
+
+import apple.corefoundation.c.CoreFoundation;
import apple.coregraphics.opaque.CGContextRef;
import apple.coregraphics.opaque.CGImageRef;
import apple.coregraphics.struct.CGPoint;
@@ -77,21 +79,25 @@
//byte[] bytes = stream.readAllBytes?(); // added in java 9
byte[] bytes = Streams.readFullyNoClose(buffInput);
+ return createImage(bytes, 0, bytes.length);
+ }
+
+ public static Image createImage(byte[] imgData, int offset, int length) {
+
// https://discuss.multi-os-engine.org/t/stream-to-nsdata-and-moe-pointer-magic/306
- BytePtr ptr = PtrFactory.newByteArray(bytes);
- NSData data = NSData.dataWithBytesLength(ptr, bytes.length);
+ BytePtr ptr;
+ if (offset == 0 && length == imgData.length) {
+ ptr = PtrFactory.newByteArray(imgData);
+ }
+ else {
+ ptr = PtrFactory.newByteArray(length);
+ ptr.copyFrom(imgData, offset, 0, length);
+ }
+ NSData data = NSData.dataWithBytesLength(ptr, length);
UIImage image = UIImage.imageWithData(data);
return new Image(image);
}
- public UIImage getUIImage(int xSrc, int ySrc, int width, int height, int transform) {
- CGRect srcRect = new CGRect(new CGPoint(xSrc, ySrc), new CGSize(width, height));
- CGImageRef cropped = CoreGraphics.CGImageCreateWithImageInRect(getUIImage().CGImage(), srcRect);
- UIImage transformed = UIImage.imageWithCGImageScaleOrientation(cropped, getUIImage().scale(), Graphics.getUIImageOrientation(transform));
- CoreGraphics.CGImageRelease(cropped);
- return transformed;
- }
-
public static Image createImage(Image image, int x, int y, int width, int height, int transform) {
if (x + width > image.getWidth() || y + height > image.getHeight() || width <= 0 || height <= 0 || x < 0 || y < 0) {
throw new IllegalArgumentException("Area out of Image: "+image.getWidth()+"x"+image.getHeight()+" area: "+x+","+y+" "+width+"x"+height);
@@ -169,31 +175,6 @@
throw new UnsupportedOperationException();
}
- public static Image createImage(byte[] imgData, int offset, int length) {
-/*
- BitmapFactory.Options opts = new BitmapFactory.Options();
- try {
- BitmapFactory.Options.class.getField("inPurgeable").set(opts, true);
- } catch (Exception e) {
- // inPurgeable not supported
- // http://www.droidnova.com/2d-sprite-animation-in-android-addendum,505.html
- }
-
- Bitmap uiImage;
- try {
- uiImage = BitmapFactory.decodeByteArray(imgData, offset, length, opts);
- } catch (OutOfMemoryError e) {
- cleanMem();
- uiImage = BitmapFactory.decodeByteArray(imgData, offset, length, opts);
- }
- if (uiImage==null) {
- return null;
- }
- return new Image(uiImage);
-*/
- throw new UnsupportedOperationException();
- }
-
public static final Image createRGBImage(int[] rgb, int width, int height, boolean processAlpha) {
/*
Bitmap.Config config = (processAlpha) ? Bitmap.Config.ARGB_4444 : Bitmap.Config.RGB_565;
@@ -221,6 +202,14 @@
return uiImage;
}
+ public UIImage getUIImage(int xSrc, int ySrc, int width, int height, int transform) {
+ CGRect srcRect = new CGRect(new CGPoint(xSrc, ySrc), new CGSize(width, height));
+ CGImageRef cropped = CoreGraphics.CGImageCreateWithImageInRect(getUIImage().CGImage(), srcRect);
+ UIImage transformed = UIImage.imageWithCGImageScaleOrientation(cropped, getUIImage().scale(), Graphics.getUIImageOrientation(transform));
+ CoreGraphics.CGImageRelease(cropped);
+ return transformed;
+ }
+
public int getWidth() {
return (int) uiImage.size().width();
}
@@ -268,7 +257,7 @@
}
public static void filter(Image source, Image bm, ColorMatrix cm) {
- /*
+/*
android.graphics.Paint paint = new android.graphics.Paint();
paint.setColorFilter(new android.graphics.ColorMatrixColorFilter(cm));
new Canvas(bm.uiImage).drawBitmap(source.uiImage, 0, 0, paint);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|