|
i think you mean Format16bppArgb1555?
you could hack it an store the byte[] data from the image in an array, and then only create the bitmap when you need it..
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
I've made some further testing, and discovered it comes from the format.
With two similar picture, 256 colors,one is png the other is gif
Bitmap bitmap = new Bitmap("Myfile.png");
-> bitmap.PixelFormat = PixelFormat.Format32bppArgb
Bitmap bitmap = new Bitmap("Myfile.gif");
-> bitmap.PixelFormat = PixelFormat.Format8bppIndexed
Conclusion :
The png codec is "buggy" and if you use the standard constructor, the bitmap ignore the file attributes and is always 32bppp.
The gif coded works OK, and the bitmap keeps the file attributes.
With this, I've reduced my application memory usage by 60%
|
|
|
|
|
I want to convert a text based protocol into XML, using C#, how do I do that in the best maner ?
Can I use XSLT in any way ? or do I have to make an parser that converts the file manually ?
An example of the text file:
BORN ANTAL AXLAR = 220
VARMGÅNG
TJUVBROMS
TEST EFTER TÅG !!
FELKODER
W00 T02
VARMGÅNGS MÄTVÄRDEN ANTAL AXLAR = 220 TÅGRIKTNING = U
LH097 023 029 030 029 026 031 017 030 022 029 033 027 032 027 025 020 033 034 029 024 031 028 027 024 031 027 020 024 033 037 031 019 027 026 022 022 032 024 022 019 032 026 024 029 029 028 029 024 032 031 028 027 032 031 021 026 031 029 023 027 030 032 025 022 025 031 027 024 039 032 023 025 032 029 023 027 029 038 025 028 028 027 024 024 034 025 020 029 028 037 025 028 035 031 023 025 024 026 023 023 030 032 025 021 039 033 022 027 035 026 020 028 031 029 023 024 035 027 027 024 027 026 024 022 033 027 027 025 030 029 030 028 032 028 027 025 030 024 034 026 025 023 024 025 028 029 023 029 036 032 022 027 030 029 028 025 028 027 022 024 035 027 034 028 033 023 022 025 030 025 028 027 032 028 022 027 030 026 020 029 029 028 025 024 016 017 013 012 018 012 011 015 016 012 014 013 019 012 013 013 014 011 011 013 036 027 032 029 028 022 024 024 023 017 017 021 032 026 018 025 LV097 028 026 027 033 039 027 031 032 024 025 027 023 037 026 028 023 031 028 025 022 030 028 023 024 028 025 025 026 032 029 024 021 033 022 020 022 034 023 022 021 028 029 026 023 030 027 025 026 033 028 023 019 032 028 023 026 030 023 024 032 030 026 022 024 028 022 020 029 036 032 022 021 038 025 026 025 032 033 026 027 030 020 027 025 038 024 024 029 027 027 019 027 035 021 025 023 034 026 028 026 032 030 028 018 035 031 027 026 029 031 022 024 029 022 023 020 028 031 023 037 028 022 024 020 032 024 021 031 031 028 029 020 032 025 029 022 032 024 032 026 025 025 026 020 031 026 024 026 034 030 022 022 033 026 021 024 034 023 022 020 034 029 025 035 034 021 027 027 032 029 024 024 023 027 028 028 025 023 023 021 032 032 023 023 013 013 008 012 014 013 008 010 013 012 011 010 016 013 009 016 014 010 008 011 046 032 027 027 029 025 024 019 028 010 024 010 033 020 021 022
TJUVBROMS MÄTVÄRDEN
LÅGNIVÅ HS = 047
LÅGNIVÅ VS = 047
ANTAL AXLAR HS = 220
ANTAL AXLAR VS = 220 TÅGRIKTNING = U
TH 002 002 001 001 002 002 002 002 002 002 002 002 001 002 002 001 001 001 001 001 001 001 001 001 002 001 001 001 002 002 002 002 001 001 001 002 001 001 001 001 001 001 002 001 001 001 002 001 001 001 002 002 001 001 001 001 002 001 002 001 002 001 002 001 001 001 002 001 001 001 002 002 001 001 001 001 002 001 002 001 001 002 001 002 001 001 002 001 001 001 002 001 001 001 001 002 001 001 002 001 001 001 001 001 001 001 001 001 001 001 001 001 002 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 002 001 001 001 002 001 001 001 001 002 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 002 002 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 002 001 001 001 001 001 001 001 001 001 001 002 001 001 001 001 001 001 002 001 001 001 002 001 001 001 002 001 002 001 001 001 001 001 001 001 002 001 001 001 TV 001 001 002 001 002 001 003 002 002 002 003 001 003 003 002 001 001 001 003 003 001 001 001 002 003 002 001 001 001 003 003 002 001 001 002 003 002 001 001 001 002 002 002 001 001 002 003 002 001 001 001 002 002 001 001 001 003 002 001 001 002 002 002 001 001 001 003 002 001 001 002 003 001 001 001 001 003 001 001 001 003 003 002 001 002 003 002 001 001 001 002 002 001 001 003 003 001 001 002 003 001 001 001 002 002 001 002 001 002 001 001 001 003 002 001 001 002 003 001 001 001 002 002 001 001 002 003 001 001 001 003 002 001 001 003 003 001 001 002 003 001 001 002 002 001 001 002 003 001 001 002 002 001 001 002 003 001 001 001 003 002 001 002 002 002 001 001 002 002 001 001 001 002 001 002 001 002 001 001 001 002 001 001 001 002 002 002 002 002 001 002 003 001 001 002 003 001 001 002 002 001 001 002 002 001 001 003 002 001 002 002 002 001 001 002 001 002 002 001 001 <.
.
|
|
|
|
|
well of course you could use xslt, it can even be user to create excel files
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
hi evey one,
I have a problem with RichTextBox in System.Windows.Forms.
the function SuspendLayout() and ResumeLayout() doesn't work!!!
Did I do something wrong?
And what is the solution when I want to cancle the drawing of this control?
Thank you in advanced,
Eran.
|
|
|
|
|
Don't know much about the RichTextBox, but you can hide the control instead of suspending layout, and show it again instead of resuming layout. This even works on COM controls, so I think it shouldt do for all other controls, too.
|
|
|
|
|
hi
can we fill the list directly with help of data set if yes plz do let me know ji
Thx
Work Hard and Test your Luck
|
|
|
|
|
Which kind of "list" ?
you can get the Rows of a Table as an Array, and you can make an "for each row"...
but not sure what do you mean by "list", "list box" ?.
Greetings
Braulio
|
|
|
|
|
Is it possible to do drawing somewhere on our Fome with Managed DirectX , for example on a Panel or PictureBox control? If so, is there any quick tutorial anywhere?
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Yes there is.
See the examples supplied with the DirectX9 SDK
|
|
|
|
|
But there, all drawing is done on whole the Form , but not on smaller areas such as a Panel .
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
at C# of environment use DateDiff() function
|
|
|
|
|
C# does not need a DateDiff() function.
You can add and substract DateTime objects, which results in a TimeSpan object:
TimeSpan ts = DateTime.Now - dtAnytime;
|
|
|
|
|
Hi, I am trying to get my head around safe thread synchronization.
I think the code below is not thread safe as the Start() method may be called several times which would cause the event to be fired asynchronously.
Any comments?
public class ThreadTest1
{
public void Start()
{
Thread thread = new Thread( new ThreadStart(ThreadMethod));
thread.Start();
}
private void ThreadMethod()
{
while (true)
{
Thread.Sleep(1000);
OnEvent(EventArgs.Empty);
}
}
public event EventHandler Event;
protected virtual void OnEvent(EventArgs e)
{
if (Event != null)
{
Event(this, e);
}
}
}
Would the code below be safe?
I have wrapped the event code in a locked block.
public class ThreadTest2
{
public void Start()
{
Thread thread = new Thread( new ThreadStart(ThreadMethod));
thread.Start();
}
private void ThreadMethod()
{
while (true)
{
Thread.Sleep(1000);
DoEvent();
}
}
private void DoEvent()
{
lock (this)
{
OnEvent(EventArgs.Empty);
}
}
public event EventHandler Event;
protected virtual void OnEvent(EventArgs e)
{
if (Event != null)
{
Event(this, e);
}
}
}
Any comments would be appreciated
|
|
|
|
|
I don't see anything shared between threads here. So there is no need to use Lock statement here, as I understand.
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
I think that the problem is that the event code is called by many threads. I want the event code to be executed by only one thread at a time.
If I had replaced the code:
OnEvent(EventArgs.Empty);
in the first example with the following:
MyForm.Text = "A Caption";
then the rules for safe thread practices would clearly be broken.
|
|
|
|
|
Here, if you have only one CPU, it's impossible for two events be invoked simultaneously! It seems you have misunderstood the usage of lock statement? or am I wrong?!
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Well you cant write code assuming only one CPU. I have dual CPUs.
Perhaps I have not put my question clearly enougth.
I have a method that is called from many threads. I want to ensure that only one thread has access to the method at any one time.
Heres another example:
public class ThreadTest1
{
public void Start()
{
for (int i = 0; i < 100; i++)
{
Thread thread = new Thread( new ThreadStart(ThreadMethod));
thread.Start();
}
}
private void ThreadMethod()
{
for (int i = 0; i < 100; i++)
{
Testing();
}
}
private void Testing()
{
Console.WriteLine("Enter");
Thread.Sleep(10);
Console.WriteLine("Exit");
}
}
The console output ... or part of it at least, looks like this:
Enter
Exit
Enter
Enter
Exit
Exit
The output I want is this:
Enter
Exit
Enter
Exit
Enter
Exit
How would I modify the code above to do this?
|
|
|
|
|
Although the execution of multiple events cannot be performed simultaneously on a single CPU, they can certainly be interlaced since they are executing on separate threads. The usage of synchronization techniques still applies. Furthermore, making assumptions about the hardware and how it relates to thread synchronization is a dangerous road to go down.
Brian
|
|
|
|
|
Thanks for these comments.
From the comments made earlier I was starting to think that my understanding of the need for synchronization was completely wrong. Your comments have really cleared things up for me.
|
|
|
|
|
I would intentionally leave the ThreadTest class unsafe for multithreading. Inform the subscribers of this class' event that it is executed on another thread. Let the subscribers handle their own synchronization. Remember, the ThreadTest class is not safe for multithreading so that means subscribing and unsubscribing to the event is also not safe multithreading. Here's how the code might look...
public class ThreadTest
{
public event EventHandler MyEvent;
public void Start()
{
Thread thread = new Thread(new ThreadStart(this.ThreadMethod));
thread.Start();
}
private void ThreadMethod()
{
while (true)
{
Thread.Sleep(1000);
if (MyEvent != null) MyEvent(this, EventArgs.Empty);
}
}
}
public class Subscriber
{
public void Run()
{
ThreadTest test = new ThreadTest();
test.MyEvent += new EventHandler(this.OnEvent);
test.Start();
test.Start();
test.Start();
}
public void OnEvent(object source, EventArgs e)
{
lock (this)
{
}
}
}
|
|
|
|
|
Thanks for the suggestions Brian. This is just the sort of help I was after.
|
|
|
|
|
Hummmm, but because of one reason, you may need to use lock in your first example.
Consider below situation:
A thread(say thread_A ) reaches here:
if (<code>Event </code>!= null){
<code>Event</code>(<code>this</code>, <code>e</code>);
}
thread_A checks and sees that Event is not null , and goes to fire Event (this, e). But before calling it, its time slice terminates. Now suppose that in our main application, by using -= operator the Event gets null. Now it's thread_A 's turn to continue. But an exception will be fired by calling Event (this, e). This will not happen be using below code:
lock(this){
if (<code>Event </code>!= null){
<code>Event</code>(this, e);
}
}
I am wondered why below code doesn't lock the Event and the exception would occur:
lock(<code>Event</code>){
if (<code>Event </code>!= null){
<code>Event</code>(this, e);
}
}
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Your example is interesting but I think that your suggested solution is flawed. Placing the lock around the event raising code e.g.
lock(this) {
if (Event != null) {
Event(this, e);
}
}
will not stop our main application from using -= operator on the Event. The lock places the event raising code in a critical section. It does not stop other threads accessing the Event property.
What do you think?
|
|
|
|
|
I don't think;), I tried it and it worked seamlessly!
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|