|
 |
|
|
 |
|
|
the original Gif File size is 9K Use Gif.Components.GifDecoder() then Gif.Components.AnimatedGifEncoder() merge. the result Gif file size be changed to 11K
why?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I am also facing the same problem. my original image is 19k animated gif.
using the code I decoded it into frames and combined together. But the new image size varies from 67 to 77 baesd on the image quality set
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
have some problem with this ,i m currently working on same application where animated image is resized but problem is that, i have completed reading of animation , i have done resizing of static images and creating of new animated images but problem is there , wen i want to combine all together, can anyone help me , if u have any relevant info,plz reply me
-- modified at 4:16 Monday 5th November, 2007
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Need to modify two methods in GifDecoder.cs:
int [] GetPixels( Bitmap bitmap ) { int [] pixels = new int [image.Width * image.Height]; int count = 0; for (int th = 0; th < image.Height; th++) { for (int tw = 0; tw < image.Width; tw++) { Color color = bitmap.GetPixel(tw, th); pixels[count++] = color.ToArgb(); } } return pixels; }
protected void SetPixels() { // expose destination image's pixels as int array // int[] dest = // (( int ) image.getRaster().getDataBuffer()).getData(); //int[] dest = GetPixels( bitmap );
int[] dest = null;
// fill in starting image contents based on last image's dispose code if (lastDispose > 0) { if (lastDispose == 3) { // use image before last int n = frameCount - 2; if (n > 0) { lastImage = GetFrame(n - 1); } else { lastImage = null; } } if (lastImage != null) { if (lastDispose == 2) { // fill last image rect area with background color lastImage = new Bitmap(lastImage); Graphics g = Graphics.FromImage(lastImage); Color c = Color.Empty; if (transparency) { c = Color.FromArgb(255, 0, 0, 0); // assume background is transparent } else { c = Color.FromArgb( lastBgColor ) ; // c = new Color(lastBgColor); // use given background color } Brush brush = new SolidBrush( c ); g.FillRectangle( brush, lastRect ); brush.Dispose(); g.Dispose(); } dest = GetPixels((Bitmap)lastImage); } }
if (dest == null) dest = new int[bitmap.Width * bitmap.Height];
// copy each source line to the appropriate place in the destination int pass = 1; int inc = 8; int iline = 0; for (int i = 0; i < ih; i++) { int line = i; if (interlace) { if (iline >= ih) { pass++; switch (pass) { case 2 : iline = 4; break; case 3 : iline = 2; inc = 4; break; case 4 : iline = 1; inc = 2; break; } } line = iline; iline += inc; } line += iy; if (line < height) { int k = line * width; int dx = k + ix; // start of line in dest int dlim = dx + iw; // end of dest line if ((k + width) < dlim) { dlim = k + width; // past dest edge } int sx = i * iw; // start of line in source while (dx < dlim) { // map color and insert in destination int index = ((int) pixels[sx++]) & 0xff; int c = act[index]; if (c != 0) { dest[dx] = c; } dx++; } } } SetPixels( dest ); }
I am also try to use LockBits in GetPixels and SetPixels, without using unsafe code. I have found a way, but need some time to finish it.
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
Could you please send me your latest copy of this project? I'm in great need of it now, thanks a lot~ My e-mail is cmhienng1983@hotmail.com
cmhienng
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I've tried settign a value for the transparency but no matter what I do it doesn't work. I noticed that the FindClosest function called in Save() was beign called before the Analyze function. I updated the code so that FindClosest now returns what looks like an accurate index as far as I can tell but when I look at th eGif in IE then the transparency is not showing (excuse the 'pun') and in a Gif editor the transparency is not set.
Has anyone else tried using the transparency in this? I really want to avoid sitting down and reading the enitre Gif Spec to understand this!
Thanks in advance
Jim
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
I have found this problem. To fix it:
edit file AnimatedGifEncoder.cs, at the end of the method AnalyzePixels(), comment Findcloasest, instead, using nq.Map: // transIndex = FindClosest(transparent); transIndex = nq.Map(transparent.B, transparent.G, transparent.R);
It will work.
I also fixed a number of other bugs in GifDecoder.cs. I want to post the whole package up, but don't know how.
Adam
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Hi Chuanchu:
Could you please also send me a copy of your bug-fixing copy. I will appreciate it very much!
Jeff Tan x.tan@hotmail.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
i tried this. I am facing problem with transparent images in decoding itself(while splitting) I am geting the first frame with transparent background but the rest is geting a black background
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have use the code on the Net CF 1.0. and Found it does not pharse the gif file well. When I fixed the follow code, it work well now. I just modify the function GetPixels in the file GifDecoder int [] GetPixels( Bitmap bitmap ) { //int [] pixels = new int [ 3 * image.Width * image.Height ]; //Orginal int[] pixels = new int[3 * image.Width * image.Height]; //Modified int count = 0; for (int th = 0; th < image.Height; th++) { for (int tw = 0; tw < image.Width; tw++) { Color color = bitmap.GetPixel(tw, th); // pixels[count] = color.R; //Orginal // count++; //Orginal // pixels[count] = color.G;//Orginal // count++;//Orginal // pixels[count] = color.B;//Orginal pixels[count] = color.ToArgb(); //Added count++; } } return pixels;
Would anyone please confirm it?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Good work. However this line should be //int[] pixels = new int[3 * image.Width * image.Height]; //Modified int[] pixels = new int[image.Width * image.Height]; // New Modified

|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I looked all over the NET. This by far is the only good enough solution I see (even in April 2007) -- full 2 years after this article was written.
The only thing I would want to change in this code would be to optimize for speed and size; nothing else!
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
I have been able to optimize the GifDecoder quiet a bit, but at the expense of compatability. The realy slow code which runs a lot (realy A LOT) of times is the GetPixel() and SetPixel() functions. I have rewritten the code to avoid the use of those, but this have to be done in "usafe" context. This means that you have to compile with the compiler option "unsafe", and that the executable will only run on the processor type you compiled it on (afair). You can just replace the two functions below in the GifDecoder.cs file. Here is the code for the GetPixels function
int [] GetPixels( Bitmap bitmap ) { int [] pixels = new int [ 3 * image.Width * image.Height ]; int count = 0; int tw, th;
BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); int scanwidth = data.Stride; System.IntPtr Scan = data.Scan0; int width = bitmap.Width; int height = bitmap.Height;
unsafe { int offset; // excess pixels at each row, to counter word alignment if (bitmap.PixelFormat == PixelFormat.Format32bppArgb || bitmap.PixelFormat == PixelFormat.Format32bppPArgb || bitmap.PixelFormat == PixelFormat.Format32bppRgb) { offset = scanwidth - bitmap.Width * 4; } else // assume 24 bits per pixel offset = scanwidth - bitmap.Width * 3; int x, y; byte colr, colg, colb; byte* p = (byte*)(void*)Scan; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { pixels[count++] = (int)*(p++); pixels[count++] = (int)*(p++); pixels[count++] = (int)*(p++); } p += offset; } } // End of unsafe bitmap.UnlockBits(data); return pixels; } Here is the code for the SetPixels function
void SetPixels( int [] pixels ) { int count = 0;
BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); int scanwidth = data.Stride; System.IntPtr Scan = data.Scan0; int width = image.Width; int height = image.Height; unsafe { bool fourBytePerPixel = false; int offset; // excess pixels at each row, to counter word alignment if (bitmap.PixelFormat == PixelFormat.Format32bppArgb || bitmap.PixelFormat == PixelFormat.Format32bppPArgb || bitmap.PixelFormat == PixelFormat.Format32bppRgb) { offset = scanwidth - bitmap.Width * 4; fourBytePerPixel = true; } else // assume 24 bits per pixel offset = scanwidth - bitmap.Width * 3; int x, y; byte* p = (byte*)(void*)Scan; Int32 pixeldata; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { pixeldata = pixels[count++];
*(p++) = (byte)(pixeldata); *(p++) = (byte)(pixeldata >> 8); *(p++) = (byte)(pixeldata >> 16); if (fourBytePerPixel) *(p++) = (byte)(pixeldata >> 24); } p += offset; } } // End of unsafe bitmap.UnlockBits(data); }
You must have me excused if the code is a bit cluttered, but it should be usefull anyway. Actually I have not gone into details to see whether it is necessary to test for 24 or 32 bit images, as the code might use purly 32 bit images.
- Lothver
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Has anyone been able to optimize this code for the encoder?
I have 15 frames which amount to 82kb, however if I use a animated gif application its only 38kb, something isn't right?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
Do you know how I can play a gif in a Form?
_____________________________
...and justice for all
APe
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Just FYI
This will violate LZW Patent No. 4,558,302 by Unisys.
Compuserve hold copyright on the GIF89a but the compression used for the images internaly is LZW.
Schneider
Schneider
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |