A few days ago I set about trying to accomplish (what I thought would be) a simple task, namely to find an image that could be located anywhere in the screen (not within my winform application) using Emug CV rather than Aforge.
Bitmap sShot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format24bppRgb);
Creates a 24bbpRgb image as required....
// Create a graphics object from the bitmap.
Graphics gfxScreenshot = Graphics.FromImage(sShot);
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y,
0, 0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
The image is now a 32bppArgb (I assume, photoshop won't load it)
// Process the image from whatever format it starts in to 24bppRgb (hopefully)
private Bitmap convert24RGB(Image sourceImage)
{
int loopX, loopY = 0;
Bitmap sourceBMP, processedBMP;
System.Drawing.Color myPixel;
int myHeight = sourceImage.Size.Height;
int myWidth = sourceImage.Size.Width;
sourceBMP = new Bitmap(sourceImage);
processedBMP = new Bitmap(myWidth, myHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
// ----- This was just to make sure the image created actually was 24bpp
using (Graphics g = Graphics.FromImage(processedBMP))
{
g.FillRectangle(new SolidBrush(Color.Blue), 0, 0, myWidth-1, myHeight-1);
}
processedBMP.Save("blue24bpp");
// ------
for (loopY = 0; loopY < myHeight; loopY++)
for (loopX = 0; loopX < myWidth; loopX++)
{
myPixel = sourceBMP.GetPixel(loopX, loopY);
processedBMP.SetPixel(loopX, loopY, myPixel);
}
return processedBMP;
}
This is just the latest of maybe a dozen methods I have tried and yet again it got converted to 32bppArgb.
I would love to discover I have overlooked something extremely simple but it's driving me insane!
Aucun commentaire:
Enregistrer un commentaire