顾海波

【修复】旋转

@@ -255,6 +255,12 @@ class IProcessingCameraImage implements ProcessingCameraImage { @@ -255,6 +255,12 @@ class IProcessingCameraImage implements ProcessingCameraImage {
255 } 255 }
256 rotationAngle ??= 0; 256 rotationAngle ??= 0;
257 257
  258 + double rad =
  259 + (rotationAngle * 3.14159265358979323846264338327950288 / 180.0);
  260 + double sinVal = sin(rad).abs();
  261 + double cosVal = cos(rad).abs();
  262 + int newImgWidth = (sinVal * height + cosVal * width).toInt();
  263 + int newImgHeight = (sinVal * width + cosVal * height).toInt();
258 264
259 Pointer<Uint8> p = ffi.malloc.allocate(plane0.length); 265 Pointer<Uint8> p = ffi.malloc.allocate(plane0.length);
260 266
@@ -263,19 +269,19 @@ class IProcessingCameraImage implements ProcessingCameraImage { @@ -263,19 +269,19 @@ class IProcessingCameraImage implements ProcessingCameraImage {
263 269
264 Pointer<Uint32> imgP = _convertImageNV21ToRGB( 270 Pointer<Uint32> imgP = _convertImageNV21ToRGB(
265 p, 271 p,
266 - width,  
267 - height, 272 + newImgWidth,
  273 + newImgHeight,
268 rotationAngle, 274 rotationAngle,
269 backGroundColor, 275 backGroundColor,
270 isFlipVectical, 276 isFlipVectical,
271 isFlipHoriozntal, 277 isFlipHoriozntal,
272 ); 278 );
273 279
274 - final imgData = imgP.asTypedList(width * height); 280 + final imgData = imgP.asTypedList(newImgWidth * newImgHeight);
275 imglib.Image img = imglib.Image.fromBytes( 281 imglib.Image img = imglib.Image.fromBytes(
276 bytes: imgData.buffer, 282 bytes: imgData.buffer,
277 - width: width,  
278 - height: height, 283 + width: newImgWidth,
  284 + height: newImgHeight,
279 order: imglib.ChannelOrder.rgba); 285 order: imglib.ChannelOrder.rgba);
280 286
281 ffi.malloc.free(p); 287 ffi.malloc.free(p);