Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
AnswerRe: switch statement Pin
PIEBALDconsult30-Aug-11 8:48
mvePIEBALDconsult30-Aug-11 8:48 
AnswerRe: switch statement PinPopular
OriginalGriff30-Aug-11 9:48
mveOriginalGriff30-Aug-11 9:48 
AnswerRe: switch statement Pin
Dylan Morley1-Sep-11 1:25
Dylan Morley1-Sep-11 1:25 
QuestionC# and USB IR camera Pin
sandy630-Aug-11 2:39
sandy630-Aug-11 2:39 
AnswerRe: C# and USB IR camera Pin
BobJanova30-Aug-11 4:48
BobJanova30-Aug-11 4:48 
SuggestionRe: C# and USB IR camera Pin
DaveAuld30-Aug-11 6:34
professionalDaveAuld30-Aug-11 6:34 
QuestionPer Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 2:17
Thomas.D Williams30-Aug-11 2:17 
AnswerRe: Per Pixel Access in C# winforms Pin
lukeer30-Aug-11 4:28
lukeer30-Aug-11 4:28 
Search for the use of LockBits().

It converts bitmap images to and from byte arrays. You have to keep track of which byte means what colour component (Alpha, Red, Green, Blue, order may be mangled). Byte array operations are a lot faster than SetPixel().

Some code I wrote after searching the web for the same thing:
C#
//
// Image format: B G R A B G ...
//               0 1 2 3 4 5 ...

Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
System.Drawing.Imaging.BitmapData imageData = image.LockBits(
    rectangle,
    System.Drawing.Imaging.ImageLockMode.ReadWrite,
    image.PixelFormat
);

IntPtr ptr = imageData.Scan0;

int byteCount = Math.Abs(imageData.Stride) * image.Height;
byte[] rgbValues = new byte[byteCount];

System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, byteCount);

for (int rgbIndex = 3; rgbIndex < rgbValues.Length; rgbIndex += 4)
{
    // Do something with
    //rgbValues[rgbIndex - 3], // (Blue)
    //rgbValues[rgbIndex - 2], // (Green)
    //rgbValues[rgbIndex - 1], // (Red)
    //rgbValues[rgbIndex - 0], // (Alpha)
}

System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, byteCount);

image.UnlockBits(imageData);


Ciao,


luker

GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 5:26
Thomas.D Williams30-Aug-11 5:26 
GeneralRe: Per Pixel Access in C# winforms Pin
BobJanova30-Aug-11 7:04
BobJanova30-Aug-11 7:04 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 7:13
Thomas.D Williams30-Aug-11 7:13 
GeneralRe: Per Pixel Access in C# winforms Pin
Pete O'Hanlon30-Aug-11 7:20
mvePete O'Hanlon30-Aug-11 7:20 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 11:17
Thomas.D Williams30-Aug-11 11:17 
GeneralRe: Per Pixel Access in C# winforms Pin
BobJanova30-Aug-11 7:38
BobJanova30-Aug-11 7:38 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 11:12
Thomas.D Williams30-Aug-11 11:12 
GeneralRe: Per Pixel Access in C# winforms Pin
BobJanova30-Aug-11 23:02
BobJanova30-Aug-11 23:02 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 23:12
Thomas.D Williams30-Aug-11 23:12 
AnswerRe: Per Pixel Access in C# winforms Pin
BobJanova30-Aug-11 4:36
BobJanova30-Aug-11 4:36 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 5:30
Thomas.D Williams30-Aug-11 5:30 
QuestionThis collection already contains an address with scheme http. There can be at most one address per scheme in this collection in 3.5 Pin
nitin_ion29-Aug-11 21:33
nitin_ion29-Aug-11 21:33 
AnswerRe: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection in 3.5 Pin
dan!sh 29-Aug-11 22:56
professional dan!sh 29-Aug-11 22:56 
GeneralRe: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection in 3.5 Pin
nitin_ion29-Aug-11 23:06
nitin_ion29-Aug-11 23:06 
QuestionWCF Rest Services with JavaScript/Jquery Pin
pravin_mun29-Aug-11 15:48
pravin_mun29-Aug-11 15:48 
AnswerRe: WCF Rest Services with JavaScript/Jquery Pin
V.30-Aug-11 2:22
professionalV.30-Aug-11 2:22 
Questionc# generate a ctrl from an xml or from a DB Pin
bysystems29-Aug-11 12:45
bysystems29-Aug-11 12:45 

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.