首页 > 编程语言 > AAuto > 动态变化背景验证码的处理
2014
12-04

动态变化背景验证码的处理

AAuto:

import console; 
import gdip

bmp = gdip.bitmap( "\12.gif" );
console.varDump(bmp.getFrameDelays())
bmp.selectActiveFrame(10);

bmp.save("\nn.jpg",80)
console.log(bmp.width)
h = bmp.copyHandle( 100,30 );

bmp2 = gdip.bitmap(h)
bmp2.save("\kk.jpg",80)

index
C++:

int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
    UINT  num = 0;          // number of image encoders
    UINT  size = 0;         // size of the image encoder array in bytes
    ImageCodecInfo* pImageCodecInfo = NULL;

    GetImageEncodersSize(&num, &size);
    if(size == 0)
        return -1;  // Failure
    pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
    if(pImageCodecInfo == NULL)
        return -1;  // Failure

    GetImageEncoders(num, size, pImageCodecInfo);

    for(UINT j = 0; j < num; ++j)
    {
        if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
        {
            *pClsid = pImageCodecInfo[j].Clsid;
            free(pImageCodecInfo);
            return j;  // Success
        }
    }

    free(pImageCodecInfo);
    return -1;  // Failure
}

void SplitTrueFrame(BYTE* pImageData,int nSize,BYTE* out,int outSize)
{
    //create bitmap from byte array
    HGLOBAL hGlobal = GlobalAlloc( GMEM_MOVEABLE, nSize );
    LPVOID pvData = NULL;
    pvData = GlobalLock( hGlobal );
    memcpy( pvData, pImageData, nSize );
    GlobalUnlock( hGlobal );

    IStream *pStream = NULL;
    HRESULT hr = CreateStreamOnHGlobal( hGlobal,  TRUE,  &pStream );

    Bitmap bmp( pStream );
    if(bmp.GetLastStatus()!=Ok)
        return;
    //get and select the max long delay frame
    UINT count = 0;
    count = bmp.GetFrameDimensionsCount();
    GUID *pDimensionIDs=(GUID*)new GUID[count];
    bmp.GetFrameDimensionsList(pDimensionIDs, count);
    WCHAR strGuid[39];
    StringFromGUID2(pDimensionIDs[0], strGuid, 39);
    UINT frameCount=bmp.GetFrameCount(&pDimensionIDs[0]);
    delete []pDimensionIDs;

    UINT itemSize;
    itemSize = bmp.GetPropertyItemSize(PropertyTagFrameDelay);
    PropertyItem* pItem = NULL;
    pItem = (PropertyItem*)malloc(itemSize);
    bmp.GetPropertyItem(PropertyTagFrameDelay,itemSize,pItem);
    GUID    Guid = FrameDimensionTime;
    long tmp = 0;
    int index = 0;
    for(UINT i=0;i<frameCount;i++)
    {
        bmp.SelectActiveFrame(&Guid,i);
        long lPause = ((long*)pItem->value)[i]*10;
        if(lPause>tmp)
        {
            tmp = lPause;
            index = i;
        }
    }
    bmp.SelectActiveFrame(&Guid,index);
    int width = bmp.GetWidth();
    int height = bmp.GetHeight();

    //copy to a new bitmap by handle
    HBITMAP Hbitmap = NULL;
    bmp.GetHBITMAP(NULL,&Hbitmap);
    HANDLE newHandle = CopyImage(Hbitmap, IMAGE_BITMAP, width, height, LR_COPYRETURNORG | LR_COPYDELETEORG );
    Bitmap *bmp2 = new Bitmap((HBITMAP)newHandle,0);

    //new bitmap convert to byte array
    HGLOBAL hMemImage = GlobalAlloc(GMEM_MOVEABLE, outSize);
    IStream* pStmImage = NULL;
    CreateStreamOnHGlobal(hMemImage, TRUE, &pStmImage);

    int m_BufferSize = GlobalSize(hMemImage);
    CLSID imgClsid;
    GetEncoderClsid(L"image/jpeg",&imgClsid);
    bmp2->Save(pStmImage ,&imgClsid,NULL);
    bmp2->Save(L"D:\\main2.jpg",&imgClsid,NULL);

    BYTE* pbyImage = (BYTE *)GlobalLock(hMemImage);
    memcpy((void*)out,(void*)pbyImage,m_BufferSize);
    //gc
    GlobalUnlock(hMemImage);
    delete bmp2;
    GlobalFree( hGlobal );
    GlobalFree( hMemImage );
}

易语言:
分离gif(易语言插件)

最后编辑:
作者:NINE
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。