????? ??? ??? .gif ?? ???? ??? ???? ???????? GDI +

?????? ????????? ?????? ?????????
???? ???????: 315780 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

?????? ??? ????? Microsoft Visual C# .NET ?? ??? ???????? ???? 319061.
?????? ??? ????? Microsoft Visual Basic .NET ?? ??? ???????? ???? 319591.
?? ????? ?? CompuServe ????? ????? ???????? (GIF) ??? ???? 256 ????? ????? ?? ???? ?????. ?????? ??????? ??????? ??? ??? ???? .gif ??? ????? ???? ??? ????. ??? ???? ??? GDI + ????? ???? ???? ??? ??????? ??? ??? ??? ?????? ?? ???? ????? GIF ? ??? .gif ?????? ????? ??? ???? ????? ?????.

???? ???? ?? ???? ??? ???? ???????? ???? ????? GIF ??? ????? ?? ???? 256 ??? ?? ???? ???? GDI + ?? ?????.

??????? ????

???? ?? ??? ???? .gif 256 ????? ??? ????. ??? ????? ??? ???? scarce ?? ??? .gif ?????? ??? ??????? ???? ???????? ???? ????. ???? ??? ???? ????? ??????, ??? ?? ????? ?? ????? ?? ???? ??????? ??? ???? ?? ??? .gif.

???? GDI + ????? ???? ?? ???? ???? ??? ??? ???????? ???? ????? GIF ?? GDI + ???? ????? ???????? ??? ??????? ????? ?? ????? ????? ???? ?? ???? "??????". GDI + ????? ????? ?? 32 ?? ???- ???? (BPP 32) ???? ??? ??? ?????? ?????? ??? ????? ???? ??? ????? ???? ????????? ??? ?????? ?? ???? ???????? BPP 32 GDI +.

??? ????? ?? GDI + ????? ????? ??? ???? ????? ?? ????????? ???????? ???? ? ???????? ???? ????? ???? .gif ? necessitates ??????? ????? ???????? BPP 32 ??????? ??? BPP 32 ??? ????? ?????? GDI +. ??? ???? ???? "??" ?????? ??????? ???? ??? ?? ???? ??????? ?????? GDI + ????? ????? ?????? ?????? ??? ?? ???? ??????? ??? ??? ???????? ????? "??? ?? ???? ????? ????????. ??? ??????? ?????? ??? ????? ???? ??? ?????? ??? ??? .gif ?? ???? ??? ????.

????? ????? ????? ?? ???? ????? GIF ? ?????? ??? ????? ?????? ??? ?????? ???????; ????? ????? ??????? ??? ??????? ???? ??? .gif ?? ???? ??? ????.

???? ??????? ??? ?????? ?????? ?? ???? ?????? ??????? ??? ???? ???? ????? ????. ??? ????? ??? ??????? ????? ??? BPP 8 ????? ????? ??????? ??? ????? ?????? ????????? ?? ??? ??? .gif. ????? ???? ??? ?????? ??????? ???????? ????? SetPalette ?? ?? ??? ??? ????? ?????? ??? ??????? ?????. ??? ????? ??????? ????? ?? ????? ???? "? ????? ??????? ??????? ??? ??? ?? ???? ????? GIF ???? ????? ???? ??????? BPP 8.

?????? ???? .gif ??? ?? ???? ??? ???? "? ???? ??????? ???????:
  1. ????? ???? ???? ????? ????? ?? ??? ????? ????? ??????.
  2. ????? ???? ??? ???? ???? ???? ????? ??? ???? ????? ???????.
  3. ??????? ????? LockBits ?????? ??? ?? ?????? ??????? ??? ?? ?????? ?? ??????.
  4. ????? ????? ???? ??? ?? ?????? ??????? ????? ????? ??? ??????? ???? ?? ?????? ????? ?? LockBits ????? ????? ?????? ?? ?????? ???????.
  5. ?????? UnLockBits ?????? ?? ??????.
  6. ??????? ???? ????? ?? ???? ??? ???? ???? ?????? ??? ??? ???????? "???" ? "???? ????? GIF.
  7. ????? ???? ?????????.

???????? ????? ??????? ??????

???? ????? ???????? ???????? ?? ??? ??????? ????? ??????? Bitmap.Save ????? ??? .gif ?? ???? ??? ???? ??? ???????. ?? ??? ????? ????????? ???????? ?????? ??? ???? ??? ????? ??? ?????? ??? ??? ?????? ???. ???? ??? ???? ?????? ??? ???????? ?? ???? ?????? ?????. GetPixel ????? ?????? ?? ????? ?????? ???? ????? remarkably. ?? ???? ????? ???????? ???????? ???? ??? ??????? LockBits ?????? ??? ????? ?????? ??????. ?????? ?????? ?? ?????? ????? GetPixel ? ????? ????? ???. ?????? ??????? ????? ????? ??????? ??????? ?? ???? ??????? ??????? ??????? ???????? ????? ?? ??????? ???????.

???? ?????? ????? ???????? ?????? ???????:
  • ?? ???? GDI + ??????.
  • ????? ???? ?????.
  • ???? ????? (CLSID) ???? ????? GIF.
  • ??? ??????? ??? .gif.
  • ????? ???? ??? ?? ??? ??? ???? ???? ??? ????.
?????? ??? ???? ?? ????????? ??? ???? GDI + GetEncoderClsid ? ?????? ????? ???????? ???????? ???? ????? ??????? MSDN ?? ???????? ??????:

?????? ??????? SDK: GDI + - Image::Save (??? ????? clsidEncoder ? encoderParams)
http://msdn.microsoft.com/en-us/library/ms533843.aspx
?????? ????? ?????? ???? ???? ????? ???? ?? ????? ?????? PixelFormat8BPPIndexed ??? ???? ??? ?? ?????? ???? ?? ???? ??? ????? ??? .gif ?? nColors ?? ??? ????? ??? ????? ?? ????? ?????. ???? ??? .gif ???? ????? ??????? ???? ??????? ????? ?? ?? ???? ???? ?????ColorPalette. ????? ????? ???????? ???????? ????? ????? ?????? ????? ???????? ??? ??? ?????????? ???? ??? ????? ??? ????? ???? ??????? ????????.

?????? ??? .gif ??? ????? ???? ???? ????? BPP 8 ?? ????? ?????? ???? ??? ????? ??? ?????. ?? ????? ???????? ???????? ?????? ?????? ?? ????? ????????? ??? ????? ??? ?????? ??????? ??? ???? ????? ??????? ??????? ????????? ????? ?????.

?????? ????? ???????? ??? ?????? ??? ????? ?????? ?????? ?????? ?? ????? GetPixel ???? ???? ????? ???? ?? ?????? ??????. ??? ????? ???? ????? ??? ????? ??? ?? ???? ??????? GetPixel.

???? ??????? ?????? ???? ?????? ??? ????? ??????, ??? ?????? ??????? ??? ?????? ???????? ????? LockBits ?? interop ?? Windows GDI DIB ???????. ??? ??????? ???? BitBlt ???? ???? ????? ?? HDC Gdi + ??? ???? ???? ???? ????? ???? DIB GDI ?????? ????? GBitBlt ????? ?????? ??? ?? GDI.

??? ????? ???? ????? ??????? ??????? ??? ?? CLSID GIF ??????? ??????? ?????? ??????? ??? ????? ?????.

????? GIF ?? ??? ?? 256 ???

?????? ????? GIF ?? GDI + ??????? 1.0 ?????? ??? GDI + ????? ???? ???? BPP 8. ??? ????? ???? ??????? ??? ???? ??? ?????. ?????? ??? ????? ????? ????? BPP 8 ?????? ????? .gif ???? ??? ?? 256 ????? ??? ?????? ????? GIF ????? BPP 8 ????? ???????? ???? ????? ??? ??? ?? 256 ????? ?????? ??????? ColorPalette.Count.

????? ?? ????????? ??? ??????? ???? ?????? ????? GIF ???? ??? "References" ?? ??? ???????.

????????? ???????? ?? ?????? ?????? ??? ??????? ???? ?????? ??? 8 BPP ????? ???? ??? ??? ??????? ??? ????????? ???????? ???? ???? ?????? ????? ????. ?????? ????? GIF ??? ??? ??? ??????? ? ?????? ????? ?????? ??? ??? ?????? ???? ?????? ?? ??? ??? ??????? (??? ???????? GIF ??? ??????) ???????? ???? ????? ????? .gif ?? ??? ?? 256 ?????.

???????? GIF

?? ????? ????????? ???????? ? ????? ????? ????? ColorPalette ??????? ????? ?? ????? ?????? GIF ????????? ???? ????????. ????????? ???????? ???? ?? ???? ????? ?????? Alpha ????? ??????? ??? ???. ????? ???????? ???????? ?? ??? ??????? ?????? ????? ???????? ??? ? ?????? ??? ???????? ????? ?????? ??????? ?? ???? ????? ??? ?????? ???? ????? ??? ???? ?????? ???????.

????? ???? ????? GIF ????? ????? ?? ColorPalette ???? ????? ??? ???? ???? ??? ???? ????. ???? ???? ?? ????? ?????? ???? ?? ??????? ?? ???? ??????? ????? ?? ColorPalette. ???? ?? ???? ??? ?? ?????? 256 ??? ?? ??? on condition ?? ????? ???? ????????? ??????? ??? ?????? Alpha ??? ????? ??? ???????. ??? ????? ??? ??????? ???? ???? ???? Alpha ?? ???. ????? ???? ????????? ???? ????? ??? ?????? Alpha ??? ???? ??? ????.

??????: ??? ??????? ??? ???????? ???????? ??? ??????? ??? ??? ????? ?? ????? ????? ?? ??? ????? ??????. ???? ??? ????? ????? ??? ?? GDI + ??????? 1.0 ?? ?????? ?????.

????? ?? ????????? ??? ????? ????? ??? ???? ??? "References" ?? ??? ???????. ??? ????? ?? ?? ?????? ??????? ?????? ???? ???? ??????? ??? ????? ?? ????? ????? System.Drawing ?? .NET Framework ? ??????? ????? GDI + ???? ??? ????? System.Drawing ?????? GDI +.

GIF/LZW ????? ???????

??? ?? Microsoft ?????? ??? ????? ?? Unisys ??????? ????? ??? .gif ??????? ???? LZW ???? ?????? ???? Unisys ???????? ??????? ? ?????? ??????? ?? ??? ?? ?????? Microsoft. ??? ????? ?? ???? ??? ??????? ?? ???? ?????? ??? ??? ?????? ???????? ????? ???????? ?????? ??????? Microsoft ?? toolkits ?????? ?????????. ?? ????? ???? ???? ????? ??? ????? ?? ??? ??? ??? ?????? ??? ????? ?? Unisys ??????? ????? GIF ?? ?????? LZW.

?????? ??? ??????? ?????? ??? ???????? LZW ? GIF ???? ??? ??? ??????? ????? ?????? ?? "????? ??????? ?? Microsoft:
193543INFO: Unisys GIF ?????????? LZW ????? ???????

??? ?????

Status SaveGIFWithNewColorTable(
  Image *pImage,
  const WCHAR* filename,
  const CLSID* clsidEncoder,
  DWORD nColors,
  BOOL fTransparent
)
{
    Status stat = GenericError;

    // GIF codec supports 256 colors maximum.
    if (nColors > 256)
        nColors = 256;
    if (nColors < 2)
        nColors = 2;

    // Make a new 8-BPP pixel indexed bitmap that is the same size as the source image.
    DWORD   dwWidth = pImage->GetWidth();
    DWORD   dwHeight = pImage->GetHeight();

    // Always use PixelFormat8BPPIndexed, because that is the color table
    // based interface to the GIF codec.
    Bitmap  bitmap(dwWidth, dwHeight, PixelFormat8BppIndexed); 

    stat = bitmap.GetLastStatus();

    if (stat != Ok)
        return stat;        // No point in continuing.

    // Allocate the new color table.
    DWORD   dwSizeColorPalette;
    dwSizeColorPalette = sizeof(ColorPalette);      // Size of core structure.
    dwSizeColorPalette += sizeof(ARGB)*(nColors-1);   // The other entries.

    // Allocate some raw space to back the ColorPalette structure pointer.
    ColorPalette *ppal = (ColorPalette *)new BYTE[dwSizeColorPalette];
    if (ppal == NULL) return OutOfMemory;

    ZeroMemory(ppal, dwSizeColorPalette);

    // Initialize a new color table with entries that are determined by
    // some optimal palette finding algorithm; for demonstration 
    // purposes, just do a grayscale. 
    if (fTransparent)
        ppal->Flags = PaletteFlagsHasAlpha;
    else
        ppal->Flags = 0; 
    ppal->Flags |= PaletteFlagsGrayScale;
    ppal->Count = nColors;
    for (UINT i = 0; i < nColors; i++)
    {
        int Alpha = 0xFF;       // Colors are opaque by default.
        int Intensity = i*0xFF/(nColors-1); // even distribution 

        // The GIF encoder makes the first entry in the palette with a
        // zero alpha the "transparent" color in the GIF.
        // For demonstration purposes, the first one is picked arbitrarily.

        if ( i == 0 && fTransparent) // Make this color index...
            Alpha = 0;          // Transparent
        
        // Create a gray scale for demonstration purposes.
        // Otherwise, use your favorite color reduction algorithm
        // and an optimum palette for that algorithm generated here.
        // For example, a color histogram, or a median cut palette.
        ppal->Entries[i] = Color::MakeARGB( Alpha, 
                                            Intensity, 
                                            Intensity, 
                                            Intensity );
    }

    // Set the palette into the new Bitmap object.
    bitmap.SetPalette(ppal);


    // Use GetPixel below to pull out the color data of Image.
    // Because GetPixel isn't defined on an Image, make a copy in a Bitmap 
    // instead. Make a new Bitmap that is the same size of the image that
    // you want to export. Otherwise, you might try to interpret the native 
    // pixel format of the image by using a LockBits call.
    // Use PixelFormat32BppARGB so that you can wrap a Graphics around it.
    Bitmap BmpCopy(dwWidth, dwHeight, PixelFormat32BppARGB); 
    stat = BmpCopy.GetLastStatus();
    if (stat == Ok)
    {
        Graphics g(&BmpCopy);

        // Transfer the Image to the Bitmap.
        stat = g.DrawImage(pImage, 0, 0, dwWidth, dwHeight);

        // g goes out of scope here and cleans up.
    }

    if (stat != Ok)
    {
        delete [] (LPBYTE) ppal;
        ppal = NULL;
        return stat;
    }

    // Lock the whole of the bitmap for writing.
    BitmapData  bitmapData;
    Rect        rect(0, 0, dwWidth, dwHeight);

    stat = bitmap.LockBits(
      &rect,
      ImageLockModeWrite,
      PixelFormat8BppIndexed,
      &bitmapData);

    if (stat == Ok)
    {
        // Write to the temporary buffer provided by LockBits.
        // Copy the pixels from the source image in this loop.
        // Because you want an index, convert RGB to the appropriate
        // palette index here.
        BYTE *pixels;
        if (bitmapData.Stride > 0)
            pixels = (BYTE*) bitmapData.Scan0;
        else
            // If the Stride is negative, Scan0 points to the last             // scanline in the buffer.
            // To normalize the loop, obtain the start of the buffer,
            // which is located (Height-1) scanlines previous.
            pixels = (BYTE*) bitmapData.Scan0 + bitmapData.Stride*(dwHeight-1);
        UINT stride = abs(bitmapData.Stride);

        // Top-down and bottom-up is not relevant to this algorithm.

        for(UINT row = 0; row < dwHeight; ++row)
        {
          for(UINT col = 0; col < dwWidth; ++col)
          {
              // Map palette indexes for a grayscale.
              // If you use some other technique to color convert,
              // put your favorite color reduction algorithm here.
              Color     pixel;
              UINT      i8BppPixel = row * stride + col;

              BmpCopy.GetPixel(col, row, &pixel);

              // Use luminance/chrominance conversion to get grayscale.
              // Basically, turn the image into black and white TV: YCrCb.
              // You do not have to to calculate Cr or Cb because you 
              // throw away the color anyway.
              // Y = Red * 0.299 + Green * 0.587 + Blue * 0.114

              // This expression is best as integer math for performance,
              // however, because GetPixel listed earlier is the slowest 
              // part of this loop, the expression is left as 
              // floating point for clarity.
              double luminance = (pixel.GetRed() * 0.299) +
                                (pixel.GetGreen() * 0.587) +
                                (pixel.GetBlue() * 0.114);

              // Gray scale is an intensity map from black to white.
              // Compute the index to the gray scale entry that  
              // approximates the luminance, and then round the index.      
              // Also, constrain the index choices by the number of colors to do
              pixels[i8BppPixel] = (BYTE)(luminance * (nColors-1)/255 +0.5);
          }
        }
    // To commit the changes, unlock the portion of the bitmap.  
        stat = bitmap.UnlockBits(&bitmapData);
    }

    // If destination work was successful, see whether the source was successful.
    if (stat == Ok) stat = BmpCopy.GetLastStatus();

    // See whether the code has been successful to this point.
    if (stat == Ok)
    {
    // Write it out to the disk.
        stat =  bitmap.Save(filename, clsidEncoder, NULL);
    }

    // Clean up after yourself.
    delete [] (LPBYTE) ppal;
    ppal = NULL;
    // BmpCopy goes away on its own when it falls out of scope.

    return stat;
}
				

??? ????? ??????? ??????

???? Microsoft ??????? ???????? ??? ??? ?? ???? ??????? ?? ?? ????? ? ? ?? ????? ??? ?????? ???????? ??????? ?/?? ???????? ???? ????. ????? ??? ??????? ??? ????? ??? ??? ??????? ???? ?? ????? ???????? ????????? ?????? ????????? ????????. ???? ?? ????? ??????? ????? Microsoft ??? ????? ????? ???? ???? ?? ?????? ?????? ??? ??????? ?????? ????? ?????? ?? ????? ??????? ?????? ????????? ???????.
??? ??? ??? ?? ???? ???? ???? ?????? ?? ???? ???????? ?? ????? ??? ??????? ????? Microsoft ?? ????? ???????. ????? ?? ?????????? ?? ?????? ????? ??? Microsoft ???:

Microsoft ????????? Partners ? https://partner.microsoft.com/global/30000104

????? Microsoft ??????? ???? ???? ??????? - http://support.microsoft.com/gp/advisoryservice

?????? ??? ???? ?? ????????? ??? ?????? ????? ???????? ???? ????? ??????? ????? Microsoft ?? ?????? ???? Microsoft ?????? ??? ?????: http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

?????

?????? ??? ??????? ?????? ??? ??????? ???? ?????? ????? GIF ???? ??? ??? ??????? ????? ?????? ?? "????? ??????? ?? Microsoft:
318343INFO: ??????? ????? BPP 8 ???????? ????? GIF GDI +
?????? ??? ??????? ?????? ??? ????? ????? ????? ???? ??? ??? ??????? ????? ?????? ?? "????? ??????? ?? Microsoft:
312119PRB: ????? ??? ??? ????? ??? ?????? ??? ?????
??? ????? ?? ?? ?????? ??????? ?????? ????? ?? ??? ???????? ??????? ??? ????? ?? ????? ????? System.Drawing ?? .NET Framework ? ??????? ????? GDI + ???? ??? ????? System.Drawing ?????? GDI +.

????? ?????????

BPP
?? ??? ???? - ??? ????? ???? ???? ?????? ?????? ???? ????? ??? ???? ?? ???? ???????; ??? ????? ??????? ??? ???? ????? ??????? ?? ????. ????? ????????? ???? ??????? ? ?????? ???? ??? BPP 32 ?? 24 BPP ? BPP 16, BPP 8 ? BPP 4 ?? BPP 1.
BPP 8
????? ???? ?????? ???? ??? ??????? ?? ?????? ???? ?? ???? ????. ??? ??????? ???? ???? ??? ???? ?? ???? ????? ????? ??? ??????? ??? (RGB) ???? - ???? - ???? ??????. ??? ?????? ??? ???? ???? ?? ??? ????? ???? ??????? ??? 256 ?????.
GIF
????? ????? ???????? - ????? ??? ???? streamable ?? ?????? ?? ??? CompuServe.
RGB
???? ? ???? ? ???? - ?? ????? ?????? ???? ???? ? ???? ???????? ???? 3 ???.

???????

???? ???????: 315780 - ????? ??? ??????: 24/????/1428 - ??????: 3.5
????? ???
  • Microsoft GDI+ 1.0
  • Microsoft Windows XP Professional
  • the operating system: Microsoft Windows XP 64-Bit Edition
????? ??????: 
kbmt kbdswgdi2003swept kbbitmap kbgdiplus kbhowto KB315780 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????315780

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com