Click here to Skip to main content
15,891,567 members
Home / Discussions / C#
   

C#

 
Questiondebugging mode behaves differently than final build Pin
kruegs353-Nov-10 6:02
kruegs353-Nov-10 6:02 
AnswerRe: debugging mode behaves differently than final build Pin
_Erik_3-Nov-10 6:14
_Erik_3-Nov-10 6:14 
GeneralRe: debugging mode behaves differently than final build Pin
kruegs353-Nov-10 6:41
kruegs353-Nov-10 6:41 
GeneralRe: debugging mode behaves differently than final build Pin
_Erik_3-Nov-10 6:49
_Erik_3-Nov-10 6:49 
AnswerRe: debugging mode behaves differently than final build Pin
Eddy Vluggen3-Nov-10 22:35
professionalEddy Vluggen3-Nov-10 22:35 
QuestionHow to set pixel into bitmap with Pixel format of Format8bppIndexed ? [modified] Pin
Yanshof3-Nov-10 4:14
Yanshof3-Nov-10 4:14 
AnswerRe: Hot to set pixel into bitmap with Pixel format of Format8bppIndexed ? Pin
Covean3-Nov-10 4:27
Covean3-Nov-10 4:27 
AnswerRe: How to set pixel into bitmap with Pixel format of Format8bppIndexed ? [modified] Pin
_Erik_3-Nov-10 5:02
_Erik_3-Nov-10 5:02 
You cannot use SetPixel if your bitmap pixel format is indexed, so you will have to use the BitmapData object returned by LockBits[^] method.

Edit

Ok, this is a little tricky, so I will give a little sample on how to do this before you have to ask again:

unsafe Bitmap ToGrayScale(Bitmap bmp)
{
    Bitmap grayBmp = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format8bppIndexed);

    // Prepare the palette
    ColorPalette pal = grayBmp.Palette;
    for (int i = 0; i < 256; i++)
        pal.Entries[i] = Color.FromArgb(i, i, i);

    grayBmp.Palette = pal;

    // Get BitmapData
    BitmapData bd = grayBmp.LockBits(
        new Rectangle(0, 0, bmp.Width, bmp.Height),
        ImageLockMode.ReadWrite,
        PixelFormat.Format8bppIndexed);

    byte* ptr = (byte*)bd.Scan0.ToPointer();

    for (int i = 0; i < bmp.Width; i++)
    {
        for (int j = 0; j < bmp.Height; j++)
        {
            Color c = bmp.GetPixel(i, j);

            // Offset must be Y*Stride + X*BytesPerPixel. In this case,
            // BytesPerPixel is 1
            ptr[j * bd.Stride + i] = (byte)((c.R + c.G + c.B) / 3);
        }
    }

    // Unlock
    grayBmp.UnlockBits(bd);

    return grayBmp;
}


Sure I should have locked bits also for bmp, becouse GetPixel performance is really bad but, hey, I feel a little lazy today...

modified on Wednesday, November 3, 2010 12:01 PM

Questionscreen capture help Pin
ramsayra3-Nov-10 3:38
ramsayra3-Nov-10 3:38 
AnswerRe: screen capture help Pin
Richard MacCutchan3-Nov-10 4:50
mveRichard MacCutchan3-Nov-10 4:50 
AnswerRe: screen capture help Pin
Dave Kreskowiak3-Nov-10 5:16
mveDave Kreskowiak3-Nov-10 5:16 
Questionhow to convert ToolStripButton to control? Pin
Tridip Bhattacharjee3-Nov-10 3:17
professionalTridip Bhattacharjee3-Nov-10 3:17 
AnswerRe: how to convert ToolStripButton to control? Pin
Not Active3-Nov-10 3:34
mentorNot Active3-Nov-10 3:34 
AnswerRe: how to convert ToolStripButton to control? Pin
Alan N3-Nov-10 6:10
Alan N3-Nov-10 6:10 
Questionsend record from the datagridview to next page Pin
annie_bel3-Nov-10 1:40
annie_bel3-Nov-10 1:40 
AnswerRe: send record from the datagridview to next page Pin
Calla3-Nov-10 1:48
Calla3-Nov-10 1:48 
QuestionUnable to cast object from webservice Pin
il_manti3-Nov-10 1:24
il_manti3-Nov-10 1:24 
AnswerRe: Unable to cast object from webservice [modified] Pin
Keith Barrow3-Nov-10 2:01
professionalKeith Barrow3-Nov-10 2:01 
AnswerRe: Unable to cast object from webservice Pin
Pete O'Hanlon3-Nov-10 2:03
mvePete O'Hanlon3-Nov-10 2:03 
AnswerRe: Unable to cast object from webservice Pin
OriginalGriff3-Nov-10 2:04
mveOriginalGriff3-Nov-10 2:04 
AnswerRe: Unable to cast object from webservice Pin
il_manti3-Nov-10 2:08
il_manti3-Nov-10 2:08 
AnswerRe: Unable to cast object from webservice Pin
Bernhard Hiller3-Nov-10 22:56
Bernhard Hiller3-Nov-10 22:56 
Questionhow to compose a content with php Pin
zendprince2-Nov-10 19:44
zendprince2-Nov-10 19:44 
AnswerMy Vote of 1 Pin
Keith Barrow2-Nov-10 20:56
professionalKeith Barrow2-Nov-10 20:56 
AnswerRe: how to compose a content with php Pin
Smithers-Jones2-Nov-10 21:49
Smithers-Jones2-Nov-10 21:49 

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.