|
Luc Pattyn wrote: a little Google action
Haven't had any of that for a while
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Luc Pattyn wrote: so you are creating one million pens and wondering why it is sooo slow?
Not only that, he's not Disposing them either. Well, from the limited code sample he provided anyway.
|
|
|
|
|
Using SetPixel is dog slow. If more than a few pixels are modified, it's next to worthless. I know of two efficient ways to modify a bitmap on a pixel-by-pixel basis. Both methods have advantages.
First, lock the bitmap, access it with pointers in unsafe mode, then unlock it. Here's a link to a very nice article using this approach:
Code Project Article
Second, lock the bitmap, copy it to a regular array, and unlock it. Modify the data in the array, and when done, lock the bitmap, copy the data back, then unlock the bitmap. If you only want to initialize the bitmap, you can simplify the process, since there's no need to copy from the bitmap. Just write the regular array and copy it to the (locked) bitmap. This idea is also useful if you only want to individually modify pixels, and don't need to use any of the bitmap features, such as line drawing. Use the pixel array as the "master" version, and copy it into the bitmap to display it. Here's an example of this method:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Runtime.InteropServices;<br />
using System.Drawing.Imaging;<br />
<br />
const int bmB = 0;<br />
const int bmG = 1;<br />
const int bmR = 2;<br />
const int bmA = 3;<br />
<br />
int bitsPerPixel;<br />
bool hasAlpha;<br />
switch (bitmap.PixelFormat)<br />
{<br />
case PixelFormat.Format24bppRgb:<br />
bitsPerPixel = 24;<br />
hasAlpha = false;<br />
break;<br />
case PixelFormat.Format32bppRgb:<br />
bitsPerPixel = 32;<br />
hasAlpha = false;<br />
case PixelFormat.Format32bppArgb:<br />
case PixelFormat.Format32bppPArgb:<br />
bitsPerPixel = 32;<br />
hasAlpha = true;<br />
break;<br />
default:<br />
throw new ArgumentException("Unsupported pixel format.");<br />
}<br />
<br />
int bytesPerPixel = bitsPerPixel >> 3;<br />
int stride = ((bitmap.Width * bitsPerPixel + 31) & ~31) >> 3;<br />
int bitmapBytes = stride * bitmap.Height;<br />
byte[] pixels = new byte[bitmapBytes];<br />
<br />
...<br />
<br />
BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);<br />
<br />
Marshal.Copy(bmpData.Scan0, pixels, 0, bitmapBytes);<br />
<br />
bitmap.UnlockBits(bmpData);<br />
<br />
...<br />
<br />
BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);<br />
<br />
Marshal.Copy(pixels, 0, bmpData.Scan0, bitmapBytes);<br />
<br />
bitmap.UnlockBits(bmpData);<br />
<br />
Note this only works for direct (non-indexed) bitmaps. For 24 bit pixels, the pixels are stored in B, G, R order; for 32 bit pixels, the order is B, G, R, A. For example, to access the green component of a 24 bit pixel at (x, y), use pixels[(bytesPerPixel * x + stride * y) + bmG].
modified on Tuesday, December 16, 2008 6:20 PM
|
|
|
|
|
Is this going to be a game? If yes, you may want to take a look at the XNA Framework[^].
Drawing a million rectangles per frame is going to be very slow. With XNA you could take advantage of your GPU - additionally XNA would put the the million objects into one batch and draw them at once as one large triangle list, which would only take a few milliseconds utilizing the GPU.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
good day people
so i want to get the location for every file type (both dll and index) and i tried using SHGetFileInfo api (ICONLOCATION flag) but for some reason it only works for either the desktop or a folder, regular fyletipes like .txt, .pdf, .xml dont work
is there another way i can get the dll and index for every file type?? i tried searching in the registry and it works for me but two specific file types still give me problems (cant find their icon's dll and index) when i run my program in another computer (my OS is windows vista x32, i have problems running it in vista (x86)
i'll repeat my main question: How can i get the dll and index for every file type??
thanks in advance for your help
|
|
|
|
|
|
actually i tried that already, that example gets the handle for the icon with SHGetFileInfo api, i need the dll path and the index, you know like for .exe files the dll is shell32.dll and the index is 2?
i tried using that same api with the flag ICONLOCATION and it did get the dll and index, but only for the desktop and folders, regular file types like .pdf or . txt wouldnt work
thanks anyway for your help
|
|
|
|
|
Unable to cast object of type 'System.DateTime' to type 'System.String'.
private void StudentsDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
// Although we could have the SQL statement return a formatted date,
// this is really a User Interface issue and should be handled here.
//
// Display only Date part of datetime
if ((this.StudentsDataGridView.Columns[e.ColumnIndex].Name == this.TeachersDataSet.Students.BirthDateColumn.ColumnName))
{
if (!(e.Value == DBNull.Value))
{
e.Value = DateTime.Parse((string)e.Value).ToLongDateString(); e.FormattingApplied = true;
}
}
}
Learning to Code
|
|
|
|
|
Mo John wrote: Unable to cast object of type 'System.DateTime' to type 'System.String'
The exception says it all. You don't say what's the problem you're having, but if it is what I suspect, use the debugger and have a look at e.Value.
|
|
|
|
|
Oh yeah! The problem: When Iinter the birthdate in the field click save it update the database. When I query the database all the data is present. When I try to access the same field on a click button to get data on the persons it will not convert the field. I get the error message.
Trying format the field so only the date will show and not the time.
Learning to Code
modified on Monday, December 15, 2008 12:54 PM
|
|
|
|
|
So have a look at the e.Value with the debugger. Especially, check the datatype.
|
|
|
|
|
System.Threading.Thread.Sleep(1000);
the System.Threading.Thread.Sleep(1000); blocks the current thread for the timeperiod in param and dont let execute the next code to it, like MessageBox. But i want current thread keep running however the code blocked.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Xmen wrote: But i want current thread keep running however the code blocked.
Huh? How would that work?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
There is no distinction between "Form moving code" and "other code" for the CPU, it's all the same.
If you have some code that needs to be paused, then you need to put it into a second thread and stop this one instead.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: There is no distinction between "Form moving code" and "other code" for the CPU, it's all the same.
dude, it was just an example
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Xmen wrote: dude, it was just an example
I know, and I also told you what you need to do instead.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
code is either running or your thread is sleeping; there is no sleepwalking in .NET
Did you have a question of some kind?
|
|
|
|
|
yes, thats why i asked for assurance
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
|
Greeeg wrote: System.Threading.Thread.Sleepwalk(int milliseconds)[^]
what is this ? a link ? or a not available reference ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Break the code block that exists before the Sleep call to another method, and execute this on another thread, like others have pointed out, is the only way to accomplish what you are asking for.
|
|
|
|
|
is there any method to check the precedence of operators
|
|
|
|
|
|
Just scope your algorithms, and you'll be fine. It's better that way anyway.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|