-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update gradle version
- Loading branch information
Showing
6 changed files
with
198 additions
and
130 deletions.
There are no files selected for viewing
118 changes: 67 additions & 51 deletions
118
android/src/main/java/dev/zuzu/yuvtransform/YuvtransformPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,83 @@ | ||
package dev.zuzu.yuvtransform; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.Matrix; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import io.flutter.embedding.engine.plugins.FlutterPlugin; | ||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler; | ||
import io.flutter.plugin.common.MethodChannel.Result; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.Matrix; | ||
|
||
|
||
/** YuvtransformPlugin */ | ||
/** | ||
* YuvtransformPlugin | ||
*/ | ||
public class YuvtransformPlugin implements FlutterPlugin, MethodCallHandler { | ||
/// The MethodChannel that will the communication between Flutter and native Android | ||
/// | ||
/// This local reference serves to register the plugin with the Flutter Engine and unregister it | ||
/// when the Flutter Engine is detached from the Activity | ||
private MethodChannel channel; | ||
|
||
@Override | ||
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { | ||
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "yuvtransform"); | ||
channel.setMethodCallHandler(this); | ||
} | ||
|
||
@Override | ||
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { | ||
if (call.method.equals("yuvtransform")) { | ||
List<byte[]> bytesList = call.argument("platforms"); | ||
int[] strides = call.argument("strides"); | ||
int width = call.argument("width"); | ||
int height = call.argument("height"); | ||
int quality = call.argument("quality"); | ||
|
||
try { | ||
byte[] data = YuvConverter.NV21toJPEG(YuvConverter.YUVtoNV21(bytesList, strides, width, height), width, height, 100); | ||
Bitmap bitmapRaw = BitmapFactory.decodeByteArray(data, 0, data.length); | ||
|
||
Matrix matrix = new Matrix(); | ||
matrix.postRotate(90); | ||
Bitmap finalbitmap = Bitmap.createBitmap(bitmapRaw, 0, 0, bitmapRaw.getWidth(), bitmapRaw.getHeight(), matrix, true); | ||
ByteArrayOutputStream outputStreamCompressed = new ByteArrayOutputStream(); | ||
finalbitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStreamCompressed); | ||
|
||
result.success(outputStreamCompressed.toByteArray()); | ||
outputStreamCompressed.close(); | ||
data = null; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} else { | ||
result.notImplemented(); | ||
/// The MethodChannel that will the communication between Flutter and native Android | ||
/// | ||
/// This local reference serves to register the plugin with the Flutter Engine and unregister it | ||
/// when the Flutter Engine is detached from the Activity | ||
private MethodChannel channel; | ||
|
||
@Override | ||
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { | ||
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "yuvtransform"); | ||
channel.setMethodCallHandler(this); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { | ||
channel.setMethodCallHandler(null); | ||
} | ||
@Override | ||
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { | ||
int width = call.argument("width"); | ||
int height = call.argument("height"); | ||
int quality = call.argument("quality"); | ||
|
||
if (call.method.equals("nv21_to_jpeg")) { | ||
byte[] bytes = call.argument("bytes"); | ||
|
||
|
||
byte[] data = YuvConverter.NV21toJPEG(bytes, width, height, quality); | ||
convertToJPEG(result, quality, data); | ||
|
||
} else if (call.method.equals("yuvtransform")) { | ||
List<byte[]> bytesList = call.argument("platforms"); | ||
int[] strides = call.argument("strides"); | ||
|
||
byte[] data = YuvConverter.NV21toJPEG(YuvConverter.YUVtoNV21(bytesList, strides, width, height), width, height, quality); | ||
convertToJPEG(result, quality, data); | ||
|
||
} else { | ||
result.notImplemented(); | ||
} | ||
} | ||
|
||
private static void convertToJPEG(Result result, int quality, byte[] data) { | ||
try { | ||
Bitmap bitmapRaw = BitmapFactory.decodeByteArray(data, 0, data.length); | ||
|
||
Matrix matrix = new Matrix(); | ||
matrix.postRotate(90); | ||
Bitmap finalbitmap = Bitmap.createBitmap(bitmapRaw, 0, 0, bitmapRaw.getWidth(), bitmapRaw.getHeight(), matrix, true); | ||
ByteArrayOutputStream outputStreamCompressed = new ByteArrayOutputStream(); | ||
finalbitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStreamCompressed); | ||
|
||
result.success(outputStreamCompressed.toByteArray()); | ||
outputStreamCompressed.close(); | ||
data = null; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { | ||
channel.setMethodCallHandler(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#Fri Jun 23 08:50:38 CEST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.