|
could you please send the code snippet for this and Is this the only solution? I mean, Is there any direct write method or something for the conversion from bmp to jpg? Please excuse if I'm wrong.
|
|
|
|
|
you can save the bitmap to a memory stream to convert it without writing to disc if you want
<br />
System.Drawing.Imaging.EncoderParameters encoding = new System.Drawing.Imaging.EncoderParameters();<br />
encoding.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Quality);<br />
MemoryStream ms = new MemoryStream();<br />
_Image.Save(ms, System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[1], encoding);<br />
_reformattedImage = ms.FromStream(ms);<br />
HTH
Russ
|
|
|
|
|
This IS how you directly convert, you read from disc in one format, and save back to disc in another. There's a block of standard code you need that is in some MS samples, from memory, I don't thnk naming the file .jpg is enough. Check MSDN for a sample.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I am facing problem of matching an expression in a text file using C# in ASP.NET. The expression used will look like: ((apple AND orange) OR (car OR lorry)). A text file will be use to search for those keyword matching with the expression given. Do any one has any idea of how to perform the matching for expression mentioned above?
|
|
|
|
|
Looks like you've been asked to write a parser. Is this for the entire file, or just a line ? Either way, you need to do your own code to break the expression into sections, then you can evaluate each easy enough.
I'd say you need to build a tree of expressons that you can then walk to see if you end up with a true result.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hello all,
I'm looking for a "CheckedListBox" type control with two checkboxes for each item. I've seen one on another site for C++ but I'm not good enough to convert it or to write my own control. Does anyone have one or know where I can get one? I'm using Visual C# 2005 Express if it matters.
-Keith
|
|
|
|
|
I'm currently writting an application and I need to load all images from a directory and display their thumbnails after. I'd need to change the preview list when the user click on another directory in the tree view, so I need to load those thumbnail fast. Currently I'm loading all those images one by one and I store them into an ImageList. I know this is not efficient and that the images stay open until the file handle is close. I'm worried about the possibility to run out of memory or of file handle if the garbage collector don't free those ressources soon enough. Do anybody have any idea how to handle efficiently images preview and loading in .Net 2.0? I've googled a lot, but didn't find anything doing it. In fast, I need an image viewer as fast as possible as I'm loading from memory card and other slow disk drive.
Any idea? Let's discuss about .Net image capabilties.
|
|
|
|
|
Ignore the garbage collector, you need to call Dispose on any image that you're throwing away.
I believe it's possible to ask for a thumbnail when you call Bitmap.FromFile, or the constructor that takes a filename.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Two comments:
- there is at least one other thread (by RajeshGuptha) concerning a large app with many
images; Rajesh ended up creating separate thumbnail files, so I guess he does not open a
full image unless it is really needed.
- I had some trouble with Image.FromFile keeping the file open (although the entire image
has been loaded in memory). So I decided to immediately copy the image and dispose of
the one returned by FromFile.
And, of course, please make sure to dispose of everything that has a Dispose() method !
Cheers,
Luc Pattyn
|
|
|
|
|
Luc Pattyn wrote: - I had some trouble with Image.FromFile keeping the file open (although the entire image
has been loaded in memory). So I decided to immediately copy the image and dispose of
the one returned by FromFile.
Yes, this is a known issue, a wrapper method that copies and closes the original is a good idea, if you may want to save over an image you've loaded and edited.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I have the following code in SQL
set @newdate = datediff(second , '1970/01/01',@date) - datediff(second,getutcdate(),getdate())
Is there any way I can achieve the same result in C# at code level,,
ANy help would be much appreciated.
imran
|
|
|
|
|
DateTime date1 = DateTime.Now;
DateTime date2 = new DateTime(1970, 1, 1);
TimeSpan span = date1 - date2
Console.WriteLine(span);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
but where do I put my date ,, notice @date is the input parameter which I input as any date ,.,,
and I also need to convert that to utcdate??
I am sorry,, I think I havent understood the code completely or you may have missed something,,,
|
|
|
|
|
Use the Subtract method of the DateTime structure to get a TimeSpan that represents the difference from 1970-01-01:
TimeSpan integral = someDate.Subtract(new DateTime(1970,1,1));
Similarly, you can get the difference between local time and UTC time:
TimeSpan diff = DateTime.UtcNow - DateTime.Now;
You can add and subtract TimeSpan values. Use the TotalSeconds property to get the number of seconds that a TimeSpan value represents.
---
Year happy = new Year(2007);
|
|
|
|
|
Many Thanks
It worked
Imran
|
|
|
|
|
Ever heard of Google[^] or CodeProject?
I have no idea what I just said. But my intentions were sincere.
|
|
|
|
|
it returns to me only that ĂĂ@Ĺ•‡@˘—…““‰•‡@„‰ƒŁßœGŽśEUQŢT.
first what i doing is convert string to byte[]:
byte[] data = Encoding.GetEncoding("IBM870").GetBytes(text);
second step is your code ...
byte[] converted = Encoding.UTF8.GetBytes(Encoding.GetEncoding("latin2").GetString(data));
and now i need a string in utf ...
string newtext = Encoding.UTF8.GetString(converted);
what is wrong???
-----------------------------
Computer is my hell on earth
|
|
|
|
|
Your mistake is wuite clear. First you changed the string to bytes using the IBM870 encoding. Then you changed that bytes to a string again using the Latin2 encoding. Here is the problem.
After that when you used the UTF8 encoding to convert the bytes to string, for sure it'll screw up.
What are you tying to do anyway converting strings to bytes back and forth?
Regards
|
|
|
|
|
Continue in the same thread instead of starting a new one.
---
Year happy = new Year(2007);
|
|
|
|
|
|
If I find that I have made a mistake in a posted message how can I remove it.
|
|
|
|
|
After opening your message, click Remove to delete it or modify to update it. (on the right bottom of the message)
|
|
|
|
|
I want to write a list of all the MP3's on a drive. In this form it finds 16940 files
void DirSearch(string sDir)
{
//FileInfo t = new FileInfo(Environment.CurrentDirectory + "\\all.lst");
//StreamWriter Tex = t.CreateText();
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d, "*.mp3"))
{
listBox1.Items.Add(f); // All files are found
//Tex.WriteLine(f);
}
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
//Tex.Close();
}
When I switch to this form it only finds 590 files
void DirSearch(string sDir)
{
FileInfo t = new FileInfo(Environment.CurrentDirectory + "\\all.lst");
StreamWriter Tex = t.CreateText();
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d, "*.mp3"))
{
//listBox1.Items.Add(f);
Tex.WriteLine(f);
}
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
Tex.Close();
}
|
|
|
|
|
FileInfo.CreateText Method
Creates a StreamWriter that writes a new text file.
Do you want to create a new text file on every call to DirSearch(d)?
|
|
|
|
|
Your right! Thats the problem. Tnx.
|
|
|
|