Click here to Skip to main content
15,913,773 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem with 2 forms Pin
Luc Pattyn4-Jul-07 0:29
sitebuilderLuc Pattyn4-Jul-07 0:29 
AnswerRe: Problem with 2 forms Pin
thrakazog3-Jul-07 7:37
thrakazog3-Jul-07 7:37 
QuestionContrast solutions for drawing text and lines onto an image Pin
Jon Hulatt3-Jul-07 5:07
Jon Hulatt3-Jul-07 5:07 
AnswerRe: Contrast solutions for drawing text and lines onto an image Pin
Dario Solera3-Jul-07 7:16
Dario Solera3-Jul-07 7:16 
AnswerRe: Contrast solutions for drawing text and lines onto an image Pin
Luc Pattyn3-Jul-07 7:31
sitebuilderLuc Pattyn3-Jul-07 7:31 
QuestionSuppress "CAPS Lock is ON" warning in Windows XP Pin
Subrahmanyam K3-Jul-07 4:52
Subrahmanyam K3-Jul-07 4:52 
AnswerRe: Suppress "CAPS Lock is ON" warning in Windows XP Pin
Dario Solera3-Jul-07 7:08
Dario Solera3-Jul-07 7:08 
QuestionReading a Bitmap in Unsafe vs InteropServices.Marshall Pin
PhilDanger3-Jul-07 4:40
PhilDanger3-Jul-07 4:40 
Hi,

I've got the following code which reads from an image that has information encoded in as pixels. My job is to scan through the image, and set the value of an array to true if a pixel is black, and false if it is any other color. I have the following bit of unsafe code that performs it:

            BitmapData bmpdata = AOIImg.LockBits(new Rectangle(0, 0, WIDTH, HEIGHT), ImageLockMode.ReadOnly, AOIImg.PixelFormat);
            IntPtr scan0 = bmpdata.Scan0;
            int stride = bmpdata.Stride;
            int imgOffs;
            try
            {
                //loop through the image and set the main AOI mask
                unsafe
                {
                    byte* imgPtr;
                    for (int y = 0; y < HEIGHT; ++y)
                    {
                        imgOffs = y * stride;
                        imgPtr = &((byte*)scan0)[imgOffs];
                        for (int x = 0; x < WIDTH; ++x)
                        {
                            //checks the blue, green, and red values of the pixel to see if it's black
                            if (imgPtr[0] == 0 && imgPtr[1] == 0 && imgPtr[2] == 0)
                            { //pixel is black -- exclude from aoi mask
                                AOIMask[y * WIDTH + x] = true;
                            }
                            else //no feature
                            {
                                AOIMask[y * WIDTH + x] = false;
                            }
                            imgPtr += 3; //advance ptr by 3 bytes (one pixel)
                        }

                    }
                }
            }
            finally 
            {
                AOIImg.UnlockBits(bmpdata);
#if DEBUG
                //TODO -- remove
                AOIImg.Save(@"C:\temp.png", ImageFormat.Png);
#endif
                AOIImg.Dispose();
            }


However, I was wondering if I could turn this into managed code using InteropsServices.Marshall to copy the pixel data to an array and read through it in a safe context. I was wondering if anyone had any warnings about using this method, such as the stride not being correctly accounted for in the marshalled array (I'm not sure if I have to do this manually or not at all!).

Thanks in advance,

Phil
AnswerRe: Reading a Bitmap in Unsafe vs InteropServices.Marshall Pin
Jon Hulatt3-Jul-07 5:31
Jon Hulatt3-Jul-07 5:31 
GeneralRe: Reading a Bitmap in Unsafe vs InteropServices.Marshall Pin
PhilDanger3-Jul-07 5:53
PhilDanger3-Jul-07 5:53 
GeneralRe: Reading a Bitmap in Unsafe vs InteropServices.Marshall Pin
Luc Pattyn3-Jul-07 6:35
sitebuilderLuc Pattyn3-Jul-07 6:35 
QuestionReading a remote mp3 file for file size and length Pin
mfmaneef3-Jul-07 4:25
mfmaneef3-Jul-07 4:25 
AnswerRe: Reading a remote mp3 file for file size and length Pin
Judah Gabriel Himango3-Jul-07 5:20
sponsorJudah Gabriel Himango3-Jul-07 5:20 
GeneralRe: Reading a remote mp3 file for file size and length Pin
mfmaneef3-Jul-07 5:31
mfmaneef3-Jul-07 5:31 
GeneralRe: Reading a remote mp3 file for file size and length Pin
Judah Gabriel Himango3-Jul-07 5:47
sponsorJudah Gabriel Himango3-Jul-07 5:47 
GeneralRe: Reading a remote mp3 file for file size and length Pin
mfmaneef3-Jul-07 6:28
mfmaneef3-Jul-07 6:28 
GeneralRe: Reading a remote mp3 file for file size and length Pin
Judah Gabriel Himango3-Jul-07 9:05
sponsorJudah Gabriel Himango3-Jul-07 9:05 
QuestionCompilation Error with Resource strings Pin
jayart3-Jul-07 3:46
jayart3-Jul-07 3:46 
AnswerRe: Compilation Error with Resource strings Pin
Judah Gabriel Himango3-Jul-07 4:33
sponsorJudah Gabriel Himango3-Jul-07 4:33 
GeneralRe: Compilation Error with Resource strings Pin
jayart3-Jul-07 4:40
jayart3-Jul-07 4:40 
GeneralRe: Compilation Error with Resource strings Pin
Judah Gabriel Himango3-Jul-07 5:19
sponsorJudah Gabriel Himango3-Jul-07 5:19 
GeneralRe: Compilation Error with Resource strings Pin
jayart3-Jul-07 5:29
jayart3-Jul-07 5:29 
GeneralRe: Compilation Error with Resource strings Pin
Judah Gabriel Himango3-Jul-07 5:48
sponsorJudah Gabriel Himango3-Jul-07 5:48 
QuestionCan I create a continoues database form Pin
Muhammad Gouda3-Jul-07 3:39
Muhammad Gouda3-Jul-07 3:39 
QuestionC# Threading Gurus input needed (FileSystemWatcher ) Pin
mejax3-Jul-07 3:38
mejax3-Jul-07 3:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.