Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.NullReferenceException when cloning a bitmap #21

Open
AndrewKaplanovsky opened this issue Jul 8, 2016 · 3 comments
Open

System.NullReferenceException when cloning a bitmap #21

AndrewKaplanovsky opened this issue Jul 8, 2016 · 3 comments
Assignees
Labels

Comments

@AndrewKaplanovsky
Copy link

Hi Anders,

Sorry for my annoyance, but when I try to clone a Bitmap, from time to time I get a System.NullReferenceException exception:

at (wrapper unknown) ImagePixelEnumerator.Helpers.Pixels.NonIndexed.PixelDataPArgb8888:PtrToStructure (intptr,object)
at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:PtrToStructure (intptr,System.Type)
at ImagePixelEnumerator.Helpers.Pixel.ReadRawData (IntPtr imagePointer) [0x00000] in d:\Users\Anders\Documents\Visual Studio 2013\Projects\aforge\Sources\System.Drawing\Helpers\Pixel.cs:272
at ImagePixelEnumerator.Helpers.ImageBuffer.ReadPixel (ImagePixelEnumerator.Helpers.Pixel pixel, System.Byte[] buffer) [0x0001f] in d:\Users\Anders\Documents\Visual Studio 2013\Projects\aforge\Sources\System.Drawing\Helpers\ImageBuffer.cs:211
at ImagePixelEnumerator.Helpers.ImageBuffer+<>c__DisplayClass5.b__4 (ImagePixelEnumerator.Helpers.LineTask lineTask) [0x00075] in d:\Users\Anders\Documents\Visual Studio 2013\Projects\aforge\Sources\System.Drawing\Helpers\ImageBuffer.cs:492
at System.Threading.Tasks.Parallel+c__AnonStorey52[TSource,TLocal].<>m__0 (Int32 i) [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Parallel.cs:2318 at System.Threading.Tasks.Parallel+<ForWorker>c__AnonStorey31[TLocal].<>m__1 () [0x000ed] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Parallel.cs:1204

The code is following:

public Bitmap ProcessImage(Bitmap src)
{
if (src == null)
{
return null;
}

 Bitmap image = null;

 try
 {
     image = src.Clone(pixelFormat: PixelFormat.Format24bppRgb); <---- the code fails here
 }
 catch (Exception ex) {
            return null;
 }
...

}

The project is a portable library, I get this error when using it in Droid project. First time when I call this code everything works fine, but then is I call it subsequently, at one step the code just crashes with the exception.

Thank you,
Andrew

@AndrewKaplanovsky
Copy link
Author

Hmm.. It seems like it depends on the speed with which I call this function. If there are delays between calls, everything works without any errors.

@anders9ustafsson
Copy link
Contributor

@AndrewKaplanovsky Strange. I will look into this as soon as I have time, but I will be away for a few weeks now. Please note that I just now have published updates on NuGet which I hope will solve the issue with Image.Save on Windows Universal.

@AndrewKaplanovsky
Copy link
Author

@anders9ustafsson Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants