exergist
exergist
CC#
Created by exergist on 3/18/2023 in #help
✅ Sequentially Queueing and Processing Async Messages
what is the right way to close this thread?
7 replies
CC#
Created by exergist on 3/18/2023 in #help
✅ Sequentially Queueing and Processing Async Messages
!done
7 replies
CC#
Created by exergist on 3/18/2023 in #help
✅ Sequentially Queueing and Processing Async Messages
Thanks again @Doombox! I found these resources quite helpful on the subject: https://dotnetpattern.com/csharp-concurrentqueue https://github.com/YounesCheikh/ObservableConcurrentQueue
7 replies
CC#
Created by exergist on 3/18/2023 in #help
✅ Sequentially Queueing and Processing Async Messages
Ooo I'll give that a try!
7 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
Well @Jester what you've provided has proven to be super helpful. Thank you very much!!
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
I previously encountered the access violation depending on how I attempted to use the bitmap after it was created (I only explored this at 3440p). I was able to work around it via trial and error but I never figured out the root cause.
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
I also noticed I'm way more likely to get a black image if my mouse cursor is moving at the time of screen capture
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
Doing an "is the bitmap all black" check costs about 30-40 ms, which I might be willing to pay if the occasional black images are not avoidable (https://stackoverflow.com/questions/2556447/whats-an-efficient-way-to-tell-if-a-bitmap-is-entirely-black/2556571#2556571)
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
BUT I do still receive black screens occasionally
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
Also I found that the memory error I mentioned previously only occurs when I hit the mat = BitmapConverter.ToMat(screenshot) line while debugging
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
Though I will say that I do still occasionally get a black screen
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
@Jester well.....it's working now. Not sure what did it but i'm no longer getting errors O_o
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
private static Mat GetTargetMatFromScreen(int targetScreen, int targetAdapter = 0, Rectangle cropRegion = default)
{
Mat mat = null; // Initialize mat
using (Bitmap screenshot = GetDuplicationScreenshot(0, 0)) // Obtain screenshot of target display (via DesktopDuplication)
{
/// screenshot.Save("test.png"); // debug
if (cropRegion != default) // Check if a cropRegion was provided
{
using (Bitmap croppedScreenshot = CropImage(screenshot, cropRegion)) // Crop screenshot based on cropRegion and store in croppedScreenshot
{
if (croppedScreenshot != null) // Check if croppedScreenshot is NOT null
mat = BitmapConverter.ToMat(croppedScreenshot); // Create Mat converted from croppedScreenshot
}
}
else
{
mat = BitmapConverter.ToMat(screenshot); // Create Mat converted from screenshot Bitmap
if (mat == null) // Check if mat is null
Console.WriteLine("Could not create haystack Mat from screenshot. Image search canceled."); // Output info to log
}
}
return mat; // Return mat
}
private static Mat GetTargetMatFromScreen(int targetScreen, int targetAdapter = 0, Rectangle cropRegion = default)
{
Mat mat = null; // Initialize mat
using (Bitmap screenshot = GetDuplicationScreenshot(0, 0)) // Obtain screenshot of target display (via DesktopDuplication)
{
/// screenshot.Save("test.png"); // debug
if (cropRegion != default) // Check if a cropRegion was provided
{
using (Bitmap croppedScreenshot = CropImage(screenshot, cropRegion)) // Crop screenshot based on cropRegion and store in croppedScreenshot
{
if (croppedScreenshot != null) // Check if croppedScreenshot is NOT null
mat = BitmapConverter.ToMat(croppedScreenshot); // Create Mat converted from croppedScreenshot
}
}
else
{
mat = BitmapConverter.ToMat(screenshot); // Create Mat converted from screenshot Bitmap
if (mat == null) // Check if mat is null
Console.WriteLine("Could not create haystack Mat from screenshot. Image search canceled."); // Output info to log
}
}
return mat; // Return mat
}
GetDuplicationScreenshot calls your snippet. The error occurs at mat = BitmapConverter.ToMat(screenshot). I AM able to save test.png.
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
I can share later tonight
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
It can handle a saved 3440p bitmap fine, but not one from the screenshot repo you shared
207 replies
CC#
Created by exergist on 1/16/2023 in #help
✅ Quicker Screenshot
Doing some opencvsharp Mat processing
207 replies