Click here to Skip to main content
15,890,123 members
Home / Discussions / C#
   

C#

 
AnswerRe: ICloneable class with strings Pin
DaveAuld8-May-16 5:37
professionalDaveAuld8-May-16 5:37 
GeneralRe: ICloneable class with strings Pin
WorkOnlineClick2Wealth8-May-16 5:46
WorkOnlineClick2Wealth8-May-16 5:46 
QuestionC# chart library with interactive elements drawing Pin
WallaceCheshire7-May-16 3:41
WallaceCheshire7-May-16 3:41 
AnswerRe: C# chart library with interactive elements drawing Pin
Ravi Bhavnani7-May-16 18:30
professionalRavi Bhavnani7-May-16 18:30 
AnswerRe: C# chart library with interactive elements drawing Pin
Kenneth Haugland7-May-16 18:31
mvaKenneth Haugland7-May-16 18:31 
QuestionWinForms issues: (partial rant, partial sharing, totally a request for opinions, comments) Pin
BillWoodruff7-May-16 2:21
professionalBillWoodruff7-May-16 2:21 
AnswerRe: WinForms issues: (partial rant, partial sharing, totally a request for opinions, comments) Pin
CHill607-May-16 4:45
mveCHill607-May-16 4:45 
QuestionWhat does Bitmap.LockBits() do? Pin
Bernhard Hiller5-May-16 21:04
Bernhard Hiller5-May-16 21:04 
I got a little confused with the Bitmap.LockBits() function. Though I can see that my code achieves what I want it to do with good performance, I do not fully understand how it works...
C#
public unsafe ushort[,] GetDataFromBitmap(Bitmap source, Rectangle rect)
{
    ushort[,] result = new ushort[rect.Width, rect.Height];
    BitmapData bmpData = source.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    byte* scan0 = (byte*)bmpData.Scan0.ToPointer();
    int bytesPerPixel = 3;
    int stride = bmpData.Stride;

    for (int y = 0; y < rect.Height; y++)
    {
        for (int x = 0; x < rect.Width; x++)
        {
            byte* bluePointer = scan0 + y*stride + x*bytesPerPixel;
            byte blue = *bluePointer;

source is a bitmap of 2736x3648 pixels of 24bit RGB, and rect has a size of 240x320, positioned somewhere within the source image.
The value of stride is 10944 - that is 4*2736. That is source.Width, not rect.Width. Also ...bluePointer = scan0 + y*stride... somehow indicates that the locked bytes do not represent the "new" image defined by the rectangle, but that scan0 just points to a position in the original image corresponding to the top left corner of the rectangle. Why do I need a Rectangle, when a Point could do so also?
bytesPerPixel is 3 (corresponding to 1 byte RGB each), while stride/source.Width is 4 (i.e. alignment to 32=2^5 bits), but it is ...bluePointer = x*bytesPerPixel + ....
Now I am confused. Can someone explain those strange parameters and values?
AnswerRe: What does Bitmap.LockBits() do? PinPopular
OriginalGriff5-May-16 21:54
mveOriginalGriff5-May-16 21:54 
GeneralRe: What does Bitmap.LockBits() do? Pin
Bernhard Hiller5-May-16 23:22
Bernhard Hiller5-May-16 23:22 
GeneralRe: What does Bitmap.LockBits() do? Pin
OriginalGriff5-May-16 23:45
mveOriginalGriff5-May-16 23:45 
GeneralRe: What does Bitmap.LockBits() do? Pin
Rob Philpott6-May-16 5:49
Rob Philpott6-May-16 5:49 
GeneralRe: What does Bitmap.LockBits() do? Pin
OriginalGriff6-May-16 6:12
mveOriginalGriff6-May-16 6:12 
Questionenvt Pin
Member 125041034-May-16 23:52
Member 125041034-May-16 23:52 
AnswerRe: envt Pin
Eddy Vluggen5-May-16 0:06
professionalEddy Vluggen5-May-16 0:06 
AnswerRe: envt Pin
Pete O'Hanlon5-May-16 0:08
mvePete O'Hanlon5-May-16 0:08 
AnswerRe: envt Pin
Richard MacCutchan5-May-16 0:28
mveRichard MacCutchan5-May-16 0:28 
AnswerRe: envt Pin
Sascha Lefèvre5-May-16 0:44
professionalSascha Lefèvre5-May-16 0:44 
AnswerRe: envt Pin
Patrice T5-May-16 0:54
mvePatrice T5-May-16 0:54 
AnswerRe: envt Pin
koolprasad20035-May-16 18:58
professionalkoolprasad20035-May-16 18:58 
Questionc# Pin
Member 125041034-May-16 22:03
Member 125041034-May-16 22:03 
AnswerRe: c# Pin
Richard MacCutchan4-May-16 22:56
mveRichard MacCutchan4-May-16 22:56 
QuestionRe: c# Pin
Member 122800337-May-16 4:42
Member 122800337-May-16 4:42 
AnswerRe: c# Pin
Richard MacCutchan7-May-16 5:08
mveRichard MacCutchan7-May-16 5:08 
Questionc# Pin
Member 125041034-May-16 21:59
Member 125041034-May-16 21:59 

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.