|
|
|
I'm trying to maje an animation using gif.
I have several frames that I want to save inmy gif file, using the SaveAdd function.
But I cannot find anywhere example or documentation about the gif encoder.
Can someone give my an example of how to do it, or direct me to some example?
I have found only info for Tiff.
|
|
|
|
|
All the classes involved are an abstract implementation, meaning what works for one works for another (the classes used themselves, that is). If you want to know what EncoderParameter s are supported, see this simple console app that I threw together quick:
using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
public class Test
{
static void Main(string[] args)
{
string fe = "gif";
if (args.Length > 0) fe = args[0];
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo codec = null;
foreach (ImageCodecInfo ci in codecs)
{
if (ci.FilenameExtension.ToLower().IndexOf(fe.ToLower()) >= 0)
{
codec = ci;
break;
}
}
if (codec == null)
{
Console.Error.WriteLine("No image codec found for extension " + fe);
return;
}
Image img = new Bitmap(1, 1);
EncoderParameters encparams = null;
try
{
encparams = img.GetEncoderParameterList(codec.Clsid);
}
catch (NotImplementedException)
{
Console.Error.WriteLine("No encoder parameters supported for extension " + fe);
return;
}
foreach (EncoderParameter encparam in encparams.Param)
{
string encname = GetEncoderName(encparam.Encoder.Guid);
Console.WriteLine("{0}: {1}", encname, encparam.Type);
}
}
static Hashtable encnames;
static string GetEncoderName(Guid g)
{
if (encnames == null)
{
encnames = new Hashtable();
Type t = typeof(Encoder);
FieldInfo[] fields = t.GetFields(BindingFlags.Public | BindingFlags.Static);
foreach (FieldInfo field in fields)
{
Encoder enc = (Encoder)field.GetValue(null);
encnames[enc.Guid] = field.Name;
}
}
return encnames[g] as string;
}
} If you run this, you'll see that the GIF image encoder doesn't even support any EncoderParameters , so you can just pass null .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It doesn't work.
preview.Save(fileName, myImageCodecInfo, myEncoderParameters); // OK
preview.SaveAdd(frame,null); // Wrong parameters used (sorry, the exact error message is in French).
I've tried to use null for myEncoderParameters in the Save, same result
Also same result if I don't use the CodecInfo at all.
The code works with TIFF. Not with gif. Any idea?
|
|
|
|
|
Of course passing null or a null reference results in the same problem - it's the same exact thing!
As I said before, the whole thing is pretty abstract, so you take use the concepts for the TIFF example (wherever you got that) and apply it to saving a frame with a GIF image. The documentation has more information about the EncoderParameter s that are supported by GDI+. The Encoder class has several static fields with various pre-defined Encoder s that you can use in the EncoderParameter s. See the documentation for them in the .NET Framework SDK.
The code I posted shows that the GIF image encoder doesn't support any Encoder s, so i don't know why passing null doesn't work. Google should find some examples if you use the right keywords.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
http://www.dotnet247.com/247reference/msgs/28/140380.aspx
it seems only the TIFF encoder supports multipages...
|
|
|
|
|
I have written the following code that is called from a component's paint method. The problem is, that nothing happens.
THe error codes returned from the drawthemebackground is 0, and the Rectangle method returns 1. Yet nothing happens.
However, when i draw something from the graphics object, retrieved from the same CreateGraphics method of the parent object, it draws ok.
pTHEME = ThemeAPI.OpenThemeData(this.Handle,"Window");<br />
<br />
Graphics clientDC = this.Parent.CreateGraphics(); <br />
IntPtr hdc = clientDC.GetHdc(); <br />
pDC = ThemeAPI.CreateCompatibleDC(hdc);<br />
<br />
Rectangle borderRect = new Rectangle(this.Location, this.Size);<br />
<br />
ThemeAPI.Rect rect = new ThemeAPI.Rect();<br />
rect.left = borderRect.Left - 20;<br />
rect.top = borderRect.Top - 20;<br />
rect.right = borderRect.Right + 20;<br />
rect.bottom = borderRect.Bottom + 20;<br />
<br />
ThemeAPI.Rect clipRect = new ThemeAPI.Rect();<br />
rect.left = 0;<br />
rect.top = 0;<br />
rect.right = 0;<br />
rect.bottom = 0;<br />
<br />
int result;<br />
int state = 1;<br />
for (int part=0; part<20; part++)<br />
{<br />
result = ThemeAPI.DrawThemeBackground(pTHEME,hdc,part,state,ref rect,ref clipRect);<br />
}<br />
<br />
result = ThemeAPI.Rectangle(pDC, borderRect.Left-5,<br />
borderRect.Top-5, borderRect.Right+5, borderRect.Bottom+5);<br />
<br />
<br />
Graphics clientDC2 = this.Parent.CreateGraphics();<br />
Pen RedPen = new Pen(Color.Red, 10);<br />
clientDC2.DrawRectangle(RedPen,borderRect);<br />
Pen GreenPen = new Pen(Color.Green, 5);<br />
clientDC2.DrawEllipse(GreenPen,borderRect);<br />
clientDC2.Dispose();<br />
<br />
clientDC.ReleaseHdc(hdc);
Can anyone tell me why it does not like my device handle? I've tried creating a compatible version, but it still does nothing.
I've followed the instructions to the letter, so i'm baffled. If anyone has any thoughts, they would be appreciated.
Cheers
Cata
|
|
|
|
|
Why are you creating a Graphics object from the parent? Each control when painted has its own device context, so you're actually trying to paint in the parent's device context which probably wouldn't do anything. Get the HDC from the Graphics object in the PaintEventArgs passed to you in OnPaint (or the Paint event if not in a derivative class).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I know the parents device context works. I can draw stuff with it. Just not with P/Invoke.
I've tried using the controls getgraphics, and the event graphics to generate a DC, but the only one that works is the parents.
I've experimented painting with the parents device context. And that works ok for non P/Invoke methods like drawing rectangles.
I can't seem to draw inside the control at all. I've made it, and all it's components transparent as well, to see what happened, and still got nothing.
|
|
|
|
|
When you use the Graphics object from any control, it will work, yes. This is because you're using GDI+. When you start painting with device contexts (which is NOT the same as a Graphics object!), things work a bit differently because you're using the older GDI library. You can read more about these in the Platform SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
your cliprect is empty, hence nothing will be exposed, the behaviour will be different depending whether u use double buffering or not.
top secret
|
|
|
|
|
How can we ShutDown Windows using APIs ? I am sure its possible with APIs. If there is another way to ShutDown Windows using C# code. Then please do tell me.
Cheers
|
|
|
|
|
You can P/Invoke either ExitWindowsEx or InitiateSystemShutdownEx. You can look them both up on MSDN. http://msdn.microsoft.com[^]
RageInTheMachine9532
|
|
|
|
|
İs there anybody can help me about this,i want to open and edit dicom images with c# codes,please help me.
|
|
|
|
|
;P
http://sourceforge.net/projects/dicom-cs/
|
|
|
|
|
Much information and links on DICOM can be found here[^].
If your going to be editing images, you might want to consider downloading the DICOM spec (in PDF form) from that same site.
RageInTheMachine9532
|
|
|
|
|
I am doing my final year project on remote desktop control.So I want to control remotely keyboard and mouse.How can i do this in C#.I know for mouse we can use Cursor.position.x or Cursor.position.y but how to get or set keyboard events?please help me in any way.
mughalali
|
|
|
|
|
mughalali wrote:
I know for mouse we can use Cursor.position.x or Cursor.position.y...
Actually, no you can't. Cursor.Position is defined as a Point , which is a value type. If you set the X and Y properties, you won't change anything because you're changing it on a copy of the Position . You would actually have to do something like this:
Cursor.Position = new Point(x, y); To send key strokes, you can use the SendKeys class, which sends keys to the active window. It's pretty limited, so if you want more control you should P/Invoke native APIs like PostMessage . See the Platform SDK documentation for more details.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I know that all the algorithms provided in the .net framework have a default block size and key size. For example, DES is 8 bytes for the block size and key size, Rijndael is 32 bytes and 16 bytes.
Is it possible for us to change the default block size and key size to cater to our needs ?
|
|
|
|
|
Any algorithm that derives from SymmetricAlgorithm has a read/write BlockSize property. Change that before using the algorithm.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I'm pretty new to C#, so forgive me if this is an overly simple question.
I'm trying to write an event handler that can be used for multiple different controls. Each time the event is fired, I need to make changes to several different controls at once.
My controls are named as such:
avail0Add
avail0
daily0 ...
avail1Add
avail1
daily1 ... and so on
The way I've been trying to do this (which hasn't worked) is by building the reference to the control using a substring of the name of the sender (namely the "0" or the "1" in the name. So conceptually, I want to do something like this:
private void availAdd_Click(object sender, System.EventArgs e)
{
string i = ((Button)sender).Name.ToString().Substring(5,1);
foreach(Person person in ("avail" + i).SelectedItems)
{
("daily" + i).Items.Add(person);
}
}
I don't know if there is syntax for this is C# that I just don't know, or if this isn't possible. I know the equivalent in VB would look something like:
Me.Controls("daily" & i).[rest of the code]
I would prefer it to do it this way if possible, but am open to other solutions as well.
thanks,
Eric.
|
|
|
|
|
mironos wrote:
("daily" + i).Items.Add(person);
That won't work.
You'll have to use the Controls collection on the Form to refer to the controls your after, such as
If( this.Controls[ index ].Name == 'something' )
or something close to this. You'll also probably look into checking the type of control too.
RageInTheMachine9532
|
|
|
|
|
i searched alot for free source code for router configuration commands simulator and i didn't find any thing could you help me to find it as soon as possiple ....
:|i need a code running under windows not any OS else
Thanks
mbd
|
|
|
|
|
route add .. .. ..
how about you ask relevant questions for C#?
Do yourself a favor and install linux and you will have all the source code you ever need.
top secret
|
|
|
|