Click here to Skip to main content
15,918,041 members
Home / Discussions / C#
   

C#

 
QuestionCrystal Report Sort by Date Formula Pin
Amr Muhammed23-Jul-14 13:28
Amr Muhammed23-Jul-14 13:28 
AnswerRe: Crystal Report Sort by Date Formula Pin
thatraja24-Jul-14 2:30
professionalthatraja24-Jul-14 2:30 
AnswerRe: Crystal Report Sort by Date Formula Pin
jschell24-Jul-14 11:39
jschell24-Jul-14 11:39 
QuestionUsing a proxy server in c# Pin
Member 1052179323-Jul-14 13:03
Member 1052179323-Jul-14 13:03 
AnswerRe: Using a proxy server in c# Pin
Bernhard Hiller23-Jul-14 20:23
Bernhard Hiller23-Jul-14 20:23 
GeneralRe: Using a proxy server in c# Pin
Member 1052179324-Jul-14 0:53
Member 1052179324-Jul-14 0:53 
GeneralRe: Using a proxy server in c# Pin
Bernhard Hiller24-Jul-14 2:58
Bernhard Hiller24-Jul-14 2:58 
QuestionKurti dev to uni code and uni code yo kurti dev convert by script Pin
Member 1096585923-Jul-14 1:36
Member 1096585923-Jul-14 1:36 
AnswerRe: Kurti dev to uni code and uni code yo kurti dev convert by script Pin
thatraja23-Jul-14 1:57
professionalthatraja23-Jul-14 1:57 
GeneralRe: Kurti dev to uni code and uni code yo kurti dev convert by script Pin
Member 1096585923-Jul-14 2:03
Member 1096585923-Jul-14 2:03 
GeneralRe: Kurti dev to uni code and uni code yo kurti dev convert by script Pin
thatraja23-Jul-14 21:07
professionalthatraja23-Jul-14 21:07 
QuestioniTextSharp PDF Overlay Pin
michPla1223-Jul-14 1:16
michPla1223-Jul-14 1:16 
Questionadd multiple passengers Pin
Jassim Rahma22-Jul-14 11:41
Jassim Rahma22-Jul-14 11:41 
GeneralRe: add multiple passengers Pin
PIEBALDconsult22-Jul-14 18:58
mvePIEBALDconsult22-Jul-14 18:58 
AnswerRe: add multiple passengers Pin
OriginalGriff22-Jul-14 19:47
mveOriginalGriff22-Jul-14 19:47 
QuestionHELP Pin
Member 1094467922-Jul-14 3:20
Member 1094467922-Jul-14 3:20 
AnswerRe: HELP Pin
Ravi Bhavnani22-Jul-14 3:57
professionalRavi Bhavnani22-Jul-14 3:57 
GeneralRe: HELP Pin
Member 1094467922-Jul-14 4:07
Member 1094467922-Jul-14 4:07 
GeneralRe: HELP Pin
Ravi Bhavnani22-Jul-14 4:16
professionalRavi Bhavnani22-Jul-14 4:16 
AnswerRe: HELP Pin
Ron Nicholson22-Jul-14 4:08
professionalRon Nicholson22-Jul-14 4:08 
GeneralRe: HELP Pin
Richard MacCutchan22-Jul-14 5:04
mveRichard MacCutchan22-Jul-14 5:04 
GeneralRe: HELP Pin
OriginalGriff22-Jul-14 6:19
mveOriginalGriff22-Jul-14 6:19 
AnswerRe: HELP Pin
Rob Philpott22-Jul-14 5:25
Rob Philpott22-Jul-14 5:25 
GeneralRe: HELP Pin
Eddy Vluggen22-Jul-14 5:53
professionalEddy Vluggen22-Jul-14 5:53 
Questionbitmap lockbits/unlockbits Pin
V.22-Jul-14 2:48
professionalV.22-Jul-14 2:48 
I have a small prototype that allows a user to highlight a rectangle on an image. The program will analyze this highlighted portion and change the pixels properties of the pixels. Above a certain treshold it will set it to white, below the treshold the pixel is set to orange.

This stuff works using the SetPixel/GetPixel method, but I read that performance is better with the LockBits/UnlockBits method.
So I tried the following:
C#
System.Drawing.Imaging.BitmapData bmpdata = tmpbmp.LockBits(tmprect, System.Drawing.Imaging.ImageLockMode.ReadWrite, tmpbmp.PixelFormat);
IntPtr pointer = bmpdata.Scan0;
//int nrofbytes = Math.Abs(bmpdata.Stride) * bmpdata.Height;  //stride = scan width
int nrofbytes = bmpdata.Width * bmpdata.Height;  //stride = scan width
byte [] bytes = new byte[nrofbytes];
	
System.Runtime.InteropServices.Marshal.Copy(pointer, bytes, 0, nrofbytes);
System.Drawing.Color color_white = System.Drawing.Color.White;
System.Drawing.Color color_orange = System.Drawing.Color.Orange;
long count = 0;
for(int i = 0; i < bytes.Length-3; i+=3){
	if(bytes[i] > 235 && bytes[i+1] > 235 && bytes[i+2] > 235){
		bytes[i] = color_white.R;
		bytes[i+1] = color_white.G;
		bytes[i+2] = color_white.B;
	}											//end if
	else{
		count++;
		bytes[i] = color_orange.R;
		bytes[i+1] = color_orange.G;
		bytes[i+2] = color_orange.B;
	}											//end else
}												//end for
System.Runtime.InteropServices.Marshal.Copy(bytes, 0, pointer, nrofbytes);
tmpbmp.UnlockBits(bmpdata);


This doesn't work in the sense that the highlighted part is:
1. not white/orange, but rather white/gray
2. it changes entire rows of the image instead of the rectangle portion I passed.

for 1. it might be some sort of index offset, I guess.
I'm pretty sure the culprit for 2. is this line:
C#
System.Runtime.InteropServices.Marshal.Copy(bytes, 0, pointer, nrofbytes);


but I'm not sure why or how to solve it.
Anyone have any experience with this?

Many thanks.
V.

(MQOTD rules and previous solutions)

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.