LEADTOOLS Support
General
General Questions
Xamarin.Android - Calling RasterCodecs.Load(stream) sets KernelExpired to true (was false)
#1
Posted
:
Monday, November 12, 2018 7:21:15 PM(UTC)
Groups: Registered
Posts: 23
Thanks: 2 times
Hi,
After getting a preview frame from the Android camera I try to convert that image data to a RasterImage, but doing so causes RasterSupport.KernelExpired to become true and throw an exception (see the detailed exception below). The call to SetLicense works and RasterSupport.KernelExpired is false afterwards. I've tried setting it outside an activity and inside the activity where i'm trying to access the libraries.
I'm doing the below in order to initialize everything:
Platform.RuntimePlatform = Platform.DROID;
Leadtools.Core.Assembly.Use();
Leadtools.Svg.Assembly.Use();
RasterSupport.Initialize(this);
RasterSupport.SetLicense(Encoding.UTF8.GetBytes(License), AppKey);
I'm using the same license and app key on Android as on iOS, it works on iOS.
I've tried RasterImage.CreateFromYUVData and RasterCodecs.Load but they all result in the following:
Leadtools.RasterException: No runtime license was set.\nYou must set a LEADTOOLS runtime license. For more information see:
https://www.leadtools.co...g-a-runtime-license.html\nContact LEAD to obtain a runtime license file.\nSee:
https://www.leadtools.co...ownloads/evaluation-form\n at Leadtools.RasterException.CheckErrorCode (System.Int32 code) [0x0000d] in <ce48660f6f6249648a190cbe778266ad>:0 \n at Leadtools.Codecs.RasterCodecs.u7HsCbASb (System.Int32 ) [0x00069] in <96653551d3944652b3b1e934ec341afc>:0 \n at Leadtools.Codecs.RasterCodecs.PbeomYPIB (Leadtools.Codecs.Internal.LoadParams ) [0x00538] in <96653551d3944652b3b1e934ec341afc>:0 \n at Leadtools.Codecs.RasterCodecs.Load (System.IO.Stream stream) [0x00023] in <96653551d3944652b3b1e934ec341afc>.....
#2
Posted
:
Tuesday, November 13, 2018 9:45:49 AM(UTC)
Groups: Registered
Posts: 23
Thanks: 2 times
I got it working, but not my colleague and that was after we discovered that you HAVE to call RasterCodecs from the main/ui thread.
The thing is, I don't want to lock the main/ui thread while while processing the image and passing it to the BarcodeEngine to scan for barcodes.
Basically, if I call RasterCodecs.Load from inside a Task.Run(() => ...); It'll throw the above mentioned exception about not finding the runtime license.
I've tried using Application.Context in RasterSupport.Initialize but then it doesn't even work when called from the main/ui thread.
How can I do all the image processing from a background thread on Xamarin Android?
#3
Posted
:
Tuesday, November 13, 2018 10:56:27 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 199
Was thanked: 28 time(s) in 28 post(s)
Hello Mikael,
I'm not able to reproduce your error. For testing I took the standard single page Xamarin Android app template, and made the following changes:
- Added a test image (cannon.jpg) to the Assets folder
- Added the Leadtools.Pdf NuGet package (I believe in previous emails you mentioned loading PDFs)
- Added a RasterSupport.SetLicense call at the bottom of the MainActivity.OnCreate method.
Note: I followed the instructions for embedding a license here: https://www.leadtools.com/support/forum/posts/t12341-HOW-TO--Embed-LEADTOOLS-License-and-Key-in-your-application
- Replaced the code of the FabOnClick button with the following:
Code:
private void FabOnClick(object sender, EventArgs eventArgs)
{
View view = (View) sender;
Task.Run(() =>
{
string message = "Loading image...";
try
{
using (RasterCodecs codecs = new RasterCodecs())
using (Stream stream = Assets.Open("cannon.jpg"))
using (RasterImage image = codecs.Load(stream))
message = $"Image size: {image.Width} by {image.Height}";
}
catch (Exception ex)
{
message = $"Error: {ex.Message}";
}
Snackbar.Make(view, message, Snackbar.LengthLong)
.SetAction("Action", (View.IOnClickListener)null)
.Show();
});
}
- Ran the project, then clicked the button in the lower left
- In a few moments a snackbar message appeared with the following text: Image size: 500 by 328
Could you test my steps above and let me know if you're still running into issues? Calling your image I/O on the main thread is not required, so I'm not certain why you are having issues.
Thanks,
Anthony Northrup
Developer Support Engineer
LEAD Technologies, Inc.
#4
Posted
:
Tuesday, November 13, 2018 4:12:17 PM(UTC)
Groups: Registered
Posts: 23
Thanks: 2 times
Hi,
I'll prepare a sample for you tomorrow.
My theory is that the code that shows the dialog informing the user that the app is using an evaluation license fails to check if it's on the UI thread or not, causing an exception/error that gets treated as a bad license.
When you did your test, were you using an eval license or a real one?
#5
Posted
:
Wednesday, November 14, 2018 5:37:31 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 199
Was thanked: 28 time(s) in 28 post(s)
Hello Mikael,
After some testing, and discussing this with our engineering team, it appears that you must show the nag message first on the main UI thread. Once you have done so, all background thread operations will function properly, it is only the initial operation that must occur on the main thread so the nag message can be displayed properly.
The easiest method for displaying the nag message is to perform a simple license check with the
RasterSupport.IsLocked method:
Code:
RasterSupport.IsLocked(RasterSupportType.Basic);
I tested this myself and everything functions perfectly.
If you are still facing any issues after adding this line, please let me know.
Thanks,
Anthony Northrup
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
General
General Questions
Xamarin.Android - Calling RasterCodecs.Load(stream) sets KernelExpired to true (was false)
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.