image
image copied to clipboard
Index out of range
When I use the encodePng(image) it returns with the error.
RangeError (index): Index out of range: index should be less than 57088: 57088
It says that the index should be less than 57088. However, my index is 5088 which is the image size.
Yes, I, too am experiencing a similar issue:
Another exception was thrown: RangeError (index): Index out of range: index should be less than 41935171: 41935171
I, too, am using encodePng, however, I am first using decodeTiff.
FWIW, it will work ONCE, but subsequent times (i.e. additional Tiff/Image files) it fails.
me too
I/flutter (22921): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════ I/flutter (22921): The following IndexError was thrown while handling a gesture: I/flutter (22921): RangeError (index): Index out of range: index should be less than 43331: 43452 I/flutter (22921): When the exception was thrown, this was the stack: I/flutter (22921): #0 _Uint32ArrayView.[] (dart:typed_data-patch/typed_data_patch.dart:3997:7) I/flutter (22921): #1 Image.getPixelSafe (package:image/src/image.dart:406:60) I/flutter (22921): #2 Image.getPixelInterpolate (package:image/src/image.dart:417:12) I/flutter (22921): #3 copyRotate (package:image/src/transform/copy_rotate.dart:68:19) I/flutter (22921): #4 _SignOnPageState._rotatefileImage (package:AlMAKTAB/View/Service/SignOnPage.dart:1033:5) I/flutter (22921): #5 _SignOnPageState.build.<anonymous closure> (package:AlMAKTAB/View/Service/SignOnPage.dart:166:21) I/flutter (22921): #6 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14) I/flutter (22921): #7 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:729:32) I/flutter (22921): #8 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) I/flutter (22921): #9 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11) I/flutter (22921): #10 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7) I/flutter (22921): #11 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9) I/flutter (22921): #12 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13) I/flutter (22921): #13 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
Guess this issue slipped under my radar, I never got to looking into it. @mhmoudsabry, in your case, copyRotate is the function causing the index error?
can we get more specific error message
getting the same out-of-range index error using IMAGE.copyCrop...
my issue on stackoverflow
https://stackoverflow.com/questions/59674212/flutter-drawimage-in-packageimage-image-dart-throws-error
full example to repreduce the error
https://github.com/mhmoudsabry/Flutter_drawImage_FullExample_Error
my flutter doctor:
flutter doctor
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 6.1.7601], locale ar-EG) [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [√] Android Studio (version 3.5) [√] VS Code, 64-bit edition [√] Connected device (1 available)
• No issues found!
Thanks for the example. I'll take a look soon.
I didn't try your example yet, but I did find a way to call drawImage and get the index error.
final dst = Image(4608, 3456);
fill(dst, getColor(0, 255, 0));
final src = Image(344, 643);
fill(src, getColor(255, 0, 0));
drawImage(src, dst, blend: false);
If blend is false, then it's trying to be optimized and doesn't do any range checking, resulting in Dart throwing the index exception. I'll add some boundary checks to that code path, in a way to not affect performance.
Turns out I was doing range checking in that case, I just had a typo. It's been fixed. I'll publish the new version soon, but was working on a couple other things before I do.
Turns out I was doing range checking in that case, I just had a typo. It's been fixed. I'll publish the new version soon, but was working on a couple other things before I do.
still get the error with flutter
flutter doctor -v
[√] Flutter (Channel stable, v1.12.13+hotfix.7, on Microsoft Windows [Version 6.1.7601], locale ar-EG)
• Flutter version 1.12.13+hotfix.7 at E:\mhmoud\react\khaled_flutter\flutter
• Framework revision 9f5ff2306b (9 days ago), 2020-01-26 22:38:26 -0800
• Engine revision a67792536c
• Dart version 2.7.0
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\El Shamel Tech\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: E:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.
[√] Android Studio (version 3.5)
• Android Studio at E:\Program Files\Android\Android Studio
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
[√] VS Code, 64-bit edition
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 2.21.1
[√] Connected device (1 available)
• STK LX1 • SYKNW19B06000455 • android-arm64 • Android 9 (API 28)
• No issues found!
Turns out I was doing range checking in that case, I just had a typo. It's been fixed. I'll publish the new version soon, but was working on a couple other things before I do.
any news????
Without more specifics, like an actual test I can run and see fail, any fixes would be purely speculative. If you can send me a repo example, then I'd be happy to fix it, otherwise I'll never know if I fix your problem or not.
my issue on stackoverflow https://stackoverflow.com/questions/59674212/flutter-drawimage-in-packageimage-image-dart-throws-error full example to repreduce the error https://github.com/mhmoudsabry/Flutter_drawImage_FullExample_Error my flutter doctor:
flutter doctor
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 6.1.7601], locale ar-EG) [√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [√] Android Studio (version 3.5) [√] VS Code, 64-bit edition [√] Connected device (1 available) • No issues found!
this is an example
Without more specifics, like an actual test I can run and see fail, any fixes would be purely speculative. If you can send me a repo example, then I'd be happy to fix it, otherwise I'll never know if I fix your problem or not. https://github.com/mhmoudsabry/Flutter_drawImage_FullExample_Error/
I didn't try your example yet, but I did find a way to call drawImage and get the index error.
final dst = Image(4608, 3456); fill(dst, getColor(0, 255, 0)); final src = Image(344, 643); fill(src, getColor(255, 0, 0)); drawImage(src, dst, blend: false);
If blend is false, then it's trying to be optimized and doesn't do any range checking, resulting in Dart throwing the index exception. I'll add some boundary checks to that code path, in a way to not affect performance.
final dst = Image(4608, 3456);
fill(dst, getColor(0, 255, 0));
final src = Image(344, 643);
fill(src, getColor(255, 0, 0));
drawImage(src, dst, blend: false);
How do i convert the src Image to asUint8List()? Is it possible? Please help.
I didn't try your example yet, but I did find a way to call drawImage and get the index error.
final dst = Image(4608, 3456); fill(dst, getColor(0, 255, 0)); final src = Image(344, 643); fill(src, getColor(255, 0, 0)); drawImage(src, dst, blend: false);
If blend is false, then it's trying to be optimized and doesn't do any range checking, resulting in Dart throwing the index exception. I'll add some boundary checks to that code path, in a way to not affect performance.
final dst = Image(4608, 3456); fill(dst, getColor(0, 255, 0)); final src = Image(344, 643); fill(src, getColor(255, 0, 0)); drawImage(src, dst, blend: false);
How do i convert the src Image to asUint8List()? Is it possible? Please help.
image1.data.buffer.asUint8List();
If anyone comes across this, check the format of your .toByteData() wherever that is. I know this is a random stab at what must be a varied problem set, but for what it's worth, I found that rawRRGB works toward either png or jpg conversions down the road, whereas a specific format can lead to this range issue when you jump over to the Image (pub dev) package.
I had this because I used dart native to load the image bytes from a png, and afterwards tried to use Image.fromBytes()
. Instead loading my bytes into decodePng()
resolved the issue.
I had this because I used dart native to load the image bytes from a png, and afterwards tried to use
Image.fromBytes()
. Instead loading my bytes intodecodePng()
resolved the issue.
This also resolved this issue for my use case.
Perhaps Image.fromBytes should be a wrapper around decodeImage?