void CID3v2Page3::OnPaste() { if( OpenClipboard() ) { HANDLE hDib = GetClipboardData( CF_DIB ); if( hDib ) { // Save the DIB in a tempory file CString strTempFile; char tempdir[MAX_PATH]; ::GetTempPath( MAX_PATH, tempdir ); ::GetTempFileName( tempdir, "bmp", 0 , strTempFile.GetBuffer(MAX_PATH) ); strTempFile.ReleaseBuffer(); if( SaveDIB( hDib, strTempFile)) { // If saved delete the actual tempory file if exists if( m_strPictureFile == "" ) { DeleteFile( m_strPictureFile ); } LoadPicture( strTempFile ); } } CloseClipboard(); } }
void _tmain() { int z; HBITMAP hbmp = LoadPicture("c:\\pic.bmp",0,0,z,0,0); char *answer=""; answer = ImageSearch(0,0,1024,768,"c:\\pic.bmp"); return; }
CachedPicture *CachePicture( char *aFilespec ) { FileDebug( "Started caching image" ); int ExistingCacheIndex = GetCacheIndex( aFilespec ); if( ExistingCacheIndex != -1 ) { FileDebug( "Skipped caching image as it's already cached" ); return &PictureCache[ExistingCacheIndex]; } if( NrPicturesCached >= MAX_PICTURE_CACHE_COUNT ) { FileDebug( "Skipped caching image as no more cache slots available" ); return NULL; } HDC hdc = GetDC(NULL); if (!hdc) { FileDebug( "Skipped caching image as failed to lock DC" ); return NULL; } strcpy_s( PictureCache[NrPicturesCached].FileName, DEFAULT_STR_BUFFER_SIZE, aFilespec ); PictureCache[NrPicturesCached].NameHash = GetStrHash( aFilespec ); int ImgType; PictureCache[NrPicturesCached].LoadedPicture = LoadPicture( aFilespec, 0, 0, ImgType, 0, false ); if( PictureCache[NrPicturesCached].LoadedPicture == NULL ) { FileDebug( "Skipped caching image as it could not be loaded" ); ReleaseDC(NULL, hdc); return NULL; } bool image_is_16bit; LONG image_width, image_height; PictureCache[NrPicturesCached].Pixels = getbits( PictureCache[NrPicturesCached].LoadedPicture, hdc, image_width, image_height, image_is_16bit ); if( PictureCache[NrPicturesCached].Pixels == NULL ) { FileDebug( "Skipped caching image as it could not be converted to pixel map" ); ReleaseDC(NULL, hdc); return NULL; } PictureCache[NrPicturesCached].Width = image_width; PictureCache[NrPicturesCached].Height = image_height; PictureCache[NrPicturesCached].NeedsPSCache = true; PictureCache[NrPicturesCached].NeedsSSCache = true; NrPicturesCached++; ReleaseDC(NULL, hdc); FileDebug( "\tFinished caching image" ); return &PictureCache[NrPicturesCached-1]; }
void CID3v2Page3::OnButtonSelect() { CFileDialog dlgFile( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Bitmap (*.bmp)|*.bmp" ); CString strTitle = theApp.LoadTranslatedString( "IdsChoosePicture" ); dlgFile.m_ofn.lpstrTitle = strTitle; dlgFile.m_ofn.lpstrInitialDir = ".\\"; if( dlgFile.DoModal() == IDOK ) { LoadPicture( dlgFile.GetPathName() ); } }
static int LoadPicture (lua_State * L) { Picture_h picture; if (LoadPicture(S(L, 1), F(L, 2), F(L, 3), F(L, 4), F(L, 5), picture) != 0) { PushUserType(L, picture, "Picture"); return 1; } return 0; }
FvwmPicture *GetPicture(Display *dpy,Window Root,char *IconPath, char *PixmapPath, char *name, int color_limit) { char *path; FvwmPicture *p; if(!(path=findIconFile(name,PixmapPath,R_OK))) if(!(path=findIconFile(name,IconPath,R_OK))) return NULL; p = LoadPicture(dpy,Root,path, color_limit); if (!p) free(path); return p; }
void COFSNcDlg2::LoadPicture(IXMLDOMNode *pXmlRoot, LPCTSTR szName, CPictureObj **ppPictureObj) { CComPtr<IXMLDOMNode> pPicture = NULL; CComBSTR bs; bs = L"Picture[@Name=\""; bs += szName; bs += L"\"]"; pXmlRoot->selectSingleNode(bs, &pPicture); if(pPicture) { LoadPicture(pPicture, ppPictureObj); //pPicture->Release(); } }
static int LoadPicture (lua_State * L) { char const * name = lua_tostring(L, 1); float fS0 = static_cast<float>(lua_tonumber(L, 2)); float fT0 = static_cast<float>(lua_tonumber(L, 3)); float fS1 = static_cast<float>(lua_tonumber(L, 4)); float fT1 = static_cast<float>(lua_tonumber(L, 5)); Picture_h picture; if (LoadPicture(name, fS0, fT0, fS1, fT1, &picture) == 0) lua_pushnil(L); else lua_pushlightuserdata(L, picture); return 1; }
FvwmPicture *CachePicture(Display *dpy,Window Root,char *IconPath,char *PixmapPath, char *name, int color_limit) { char *path; FvwmPicture *p=PictureList; /* First find the full pathname */ #ifdef XPM if(!(path=findIconFile(name,PixmapPath,R_OK))) if(!(path=findIconFile(name,IconPath,R_OK))) return NULL; #else /* Ignore the given pixmap path when compiled without XPM support */ if(!(path=findIconFile(name,IconPath,R_OK))) return NULL; #endif /* See if the picture is already cached */ while(p) { register char *p1, *p2; for (p1=path, p2=p->name; *p1 && *p2; ++p1, ++p2) if (*p1 != *p2) break; if(!*p1 && !*p2) /* We have found a picture with the wanted name */ { p->count++; /* Put another weight on the picture */ free(path); return p; } p=p->next; } /* Not previously cached, have to load it ourself. Put it first in list */ p=LoadPicture(dpy,Root,path, color_limit); if(p) { p->next=PictureList; PictureList=p; } else free(path); return p; }
SOM_Scope bool SOMLINK VRIconButtonInstance_vrSet_PicturePath(VRIconButton *somSelf, PSZ str) { VRIconButtonData *somThis = VRIconButtonGetData(somSelf); VRIconButtonMethodDebug("VRIconButton","VRIconButtonInstance_vrSet_PicturePath"); if ( !str ) return FALSE; if ( _pszImg ) VRMemFree( _pszImg ); _pszImg = VRMemAlloc( strlen( str ) + 1 ); if ( !_pszImg ) return FALSE; strcpy( _pszImg, str ); LoadPicture( somSelf ); WinInvalidateRect( _vrGetWindowHandle( somSelf ), NULL, TRUE ); if ( _fAutosize ) SetAutoSize( somSelf ); return TRUE; }
void CAnim::Load(UINT AnimName) { BOOL Found=FALSE; for(int i=0;i<MAX_ANIM_GIFS && !Found;i++) { if (m_aPictName[i]==0) { BITMAP mybm; LoadPicture(AnimName); m_aPictName[i]=AnimName; m_aBitmaps[i]=m_pBitmap; Found=TRUE; m_aPictUsageCount[i]=10000; m_pBitmap->GetObject(sizeof(BITMAP),&mybm); m_aBitmapSize[i].cx=mybm.bmWidth; m_aBitmapSize[i].cy=mybm.bmHeight; m_aMaskBitmaps[i]=NULL; } } }
long COFSNcDlg2::LoadPictures(IXMLDOMNode *pXmlRoot) { long nPictures = 0; CComPtr<IXMLDOMNodeList> pList = NULL; CComPtr<IXMLDOMNode> pPicture = NULL; pXmlRoot->selectNodes(CComBSTR(L"Picture"), &pList); if(pList) { pList->get_length(&nPictures); pList->nextNode(&pPicture); while(pPicture) { LoadPicture(pPicture); pPicture = NULL; pList->nextNode(&pPicture); } //pList->Release(); } return nPictures; }
//************************************************************************************************************* GLuint LoadTexture(const std::wstring& file) { GLuint texid = 0; Gdiplus::Bitmap* bitmap = LoadPicture(file); if( bitmap ) { if( bitmap->GetLastStatus() == Gdiplus::Ok ) { Gdiplus::BitmapData data; unsigned char* tmpbuff; bitmap->LockBits(0, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &data); tmpbuff = new unsigned char[data.Width * data.Height * 4]; memcpy(tmpbuff, data.Scan0, data.Width * data.Height * 4); for( UINT i = 0; i < data.Height; ++i ) { // swap red and blue for( UINT j = 0; j < data.Width; ++j ) { UINT index = (i * data.Width + j) * 4; std::swap<unsigned char>(tmpbuff[index + 0], tmpbuff[index + 2]); } // flip on X for( UINT j = 0; j < data.Width / 2; ++j ) { UINT index1 = (i * data.Width + j) * 4; UINT index2 = (i * data.Width + (data.Width - j - 1)) * 4; std::swap<unsigned int>(*((unsigned int*)(tmpbuff + index1)), *((unsigned int*)(tmpbuff + index2))); } } glGenTextures(1, &texid); glBindTexture(GL_TEXTURE_2D, texid); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glBindTexture(GL_TEXTURE_2D, texid); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data.Width, data.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpbuff); glBindTexture(GL_TEXTURE_2D, 0); GLenum err = glGetError(); if( err != GL_NO_ERROR ) MYERROR("Could not create texture") else std::cout << "Created texture " << data.Width << "x" << data.Height << "\n"; bitmap->UnlockBits(&data); delete[] tmpbuff; } delete bitmap; }
int _tmain(int argc, _TCHAR* argv[]) { if( argc < 2 ) { _tprintf(_T("converts a picture to a tank map\n")); _tprintf(_T("supported formats: bmp, gif, jpg, wmf, ico\n")); _tprintf(_T("using: mkmap bmpfile.bmp [mapfile]\n")); return 0; } _tprintf(_T("input file: \n %s\n"), argv[1]); IPicture *pPicture = LoadPicture(argv[1]); if( NULL == pPicture ) { _tprintf(_T("Loading FAILED!\n")); return -1; } HDC hdc = GetDC(NULL); long height, width; pPicture->get_Height(&height); pPicture->get_Width(&width); long height_ = MulDiv(height, GetDeviceCaps(hdc, LOGPIXELSY), HIMETRIC_INCH); long width_ = MulDiv(width, GetDeviceCaps(hdc, LOGPIXELSX), HIMETRIC_INCH); _tprintf(_T("width %d px\n"), width_); _tprintf(_T("height %d px\n"), height_); HDC hdc_tmp = CreateCompatibleDC(hdc); HBITMAP bmp = CreateCompatibleBitmap(hdc, width_, height_); ReleaseDC(NULL, hdc); HBITMAP old = (HBITMAP) SelectObject(hdc_tmp, bmp); pPicture->Render(hdc_tmp, 0, 0, width_, height_, 0, height, width, -height, NULL); _TCHAR outfn[MAX_PATH]; if( argc > 2 ) _tcscpy(outfn, argv[2]); else _stprintf(outfn, _T("%s.tankmap"), argv[1]); FILE *file = _tfopen(outfn, _T("wt")); if( NULL != file ) { _tprintf(_T("writing map to '%s'\n"), outfn); try { fwassert(_ftprintf(file, _T("<tank map>\n"))); fwassert(_ftprintf(file, _T("width %d\n"), width_)); fwassert(_ftprintf(file, _T("height %d\n"), height_)); _TCHAR name[MAX_OBJNAME]; int objcount = 0; for( int y = 0; y < height_; y++ ) for( int x = 0; x < width_; x++ ) { if( ObjectFromColor(name, GetPixel(hdc_tmp, x, y)) ) { fwassert(_ftprintf(file, _T("%s %d %d\n"), name, 16 + x * 32, 16 + y * 32)); objcount++; } } _tprintf(_T("%d objects written\n"), objcount); _tprintf(_T("done.\n"), objcount); } catch(const _TCHAR *msg) { fclose(file); _tprintf(msg); } } else { _tprintf(_T("can't open file '%s' for writing\n"), outfn); } SelectObject(hdc_tmp, old); DeleteObject(bmp); DeleteDC(hdc_tmp); SAFE_RELEASE(pPicture); return 0; }
void CAnim::Play(UINT AnimName,CRect rect,BOOL Static,int Loop,BOOL Transparent,int Rate, CPoint Dest,short FuncIndex,BYTE* CBParam,int ParamSize,CRect BackAnim, int LoopStartFrame, int Frames) { if (Rate != 6 && Rate != 12) { //the animation can play only in 6.25 and 12.5 fps ASSERT(0); } m_nRate = Rate; m_bSkipFrame = TRUE; if (m_bPlaying) { Close (TRUE,TRUE); } m_bPlaying=TRUE; //load the bitmap from gif m_pBitmap=NULL; int PictNum=FindPicture(AnimName); if (PictNum!=-1) { m_pBitmap=m_aBitmaps[PictNum]; m_nBMWidth =m_aBitmapSize[PictNum].cx; m_nBMHeight=m_aBitmapSize[PictNum].cy; m_aPictUsageCount[PictNum]++; } else { BITMAP mybm; LoadPicture(AnimName); m_pBitmap->GetObject(sizeof(BITMAP),&mybm); m_nBMWidth=mybm.bmWidth; m_nBMHeight=mybm.bmHeight; } ASSERT(m_pBitmap); //if transparent make the mask bitmap if (Transparent) { if (PictNum == -1 || m_aMaskBitmaps[PictNum]==NULL) { CDC BmpDC; CDC MaskDC; BmpDC.CreateCompatibleDC(NULL); COLORREF BgColor=BmpDC.SetBkColor(RGB(0,0,0)); CBitmap * pOldBmp=BmpDC.SelectObject(m_pBitmap); m_pMaskBitmap=new(CBitmap); m_pMaskBitmap->CreateBitmap(((m_nBMWidth+7)/8)*8, ((m_nBMHeight+7)/8)*8, 1,1,NULL); MaskDC.CreateCompatibleDC(NULL); CBitmap * pOldmask=MaskDC.SelectObject(m_pMaskBitmap); BOOL ret5=MaskDC.BitBlt(0,0, m_nBMWidth, m_nBMHeight, &BmpDC,0,0,SRCCOPY); MaskDC.SelectObject(pOldmask); BmpDC.SetBkColor(BgColor); BmpDC.SelectObject(pOldBmp); } else { ASSERT(m_aMaskBitmaps[PictNum]); m_pMaskBitmap=m_aMaskBitmaps[PictNum]; } if (Static) { CDC* pDC; CDC BackgroundDC; CDC BackImageDC; CBitmap* pBackImage; CUbqGamePiece* p; CUbqMultImage* m; CObject* o; pDC=m_pWnd->GetDC(); CPalette* OldPal= pDC->SelectPalette(&(CBmp::m_cPalette),FALSE); pDC->RealizePalette(); BackgroundDC.CreateCompatibleDC(pDC); BackImageDC.CreateCompatibleDC(pDC); m_pBackgroundBitmap=new(CBitmap); m_pBackgroundBitmap->CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()); CBitmap* pOldBg =BackgroundDC.SelectObject(m_pBackgroundBitmap); //copying the background image pBackImage=&((CUbqGameBoard*)m_pWnd)->m_cBoardBmp; //pBackImage=((CUbqGameBoard*)m_pWnd)->m_pImageBoard->m_picture.GetBitmap(); CBitmap* pOldBg2=BackImageDC.SelectObject(pBackImage); BOOL ret=BackgroundDC.BitBlt(0,0, rect.Width(), rect.Height(), &BackImageDC, rect.left, rect.top, SRCCOPY); BackImageDC.SelectObject(pOldBg2); //copying the pieces int size = ((CUbqGameBoard*)m_pWnd)->m_vecPieces.GetSize(); for (int i=0; i<size; i++) // bottom to top to preserve Z order { o = ((CUbqGameBoard*)m_pWnd)->m_vecPieces.GetAt(i); p = (CUbqGamePiece*) o; if ((p->GetAttribute() & PA_INVISIBLE) == 0 && ( p != ((CUbqGameBoard*)m_pWnd)->m_pDraggedPiece )) { CRect rIntersect; if (rIntersect.IntersectRect(rect,p->m_rArea)) { CPoint ap=p->m_rArea.TopLeft(); #ifdef WIN32 ap-=rect.TopLeft(); #else ap.x-=rect.TopLeft().x; ap.y-=rect.TopLeft().y; #endif (((CUbqGameBoard*)m_pWnd)->m_pApplet)->DrawImage(p->m_pImage,ap,BackgroundDC); } } } //copying the multi images size = ((CUbqGameBoard*)m_pWnd)->m_vecMultipleImages.GetSize(); for (i=0; i<size; i++) // bottom to top to preserve Z order { o = ((CUbqGameBoard*)m_pWnd)->m_vecMultipleImages.GetAt(i); m = (CUbqMultImage*) o; CRect rIntersect; if (rIntersect.IntersectRect(rect,m->m_rArea)) { CPoint ap=m->m_rArea.TopLeft(); #ifdef WIN32 ap-=rect.TopLeft(); #else ap.x-=rect.TopLeft().x; ap.y-=rect.TopLeft().y; #endif (((CUbqGameBoard*)m_pWnd)->m_pApplet)->DrawImage(m->GetCurrImage(),ap,BackgroundDC); } } BackgroundDC.SelectObject(pOldBg); pDC->SelectPalette(OldPal,FALSE); pDC->RealizePalette(); m_pWnd->ReleaseDC(pDC); } } //save parameters m_rArea=rect; m_cEndPoint=Dest; m_cCurrPoint=m_cStartPoint=rect.TopLeft(); m_bStatic=Static; m_nLoopStartFrame = LoopStartFrame; m_nLoops=Loop; if (m_nLoops==0) //loops 0 is realy 1 m_nLoops++; if (m_nLoops!=1 && !m_bStatic) ASSERT(0); m_nFuncIndex = FuncIndex; m_bTransparent=Transparent; if (ParamSize>0) { m_nCBParamSize=ParamSize; m_pCBParam=new BYTE[ParamSize]; if (!m_pCBParam) ASSERT(0); memcpy(m_pCBParam,CBParam,ParamSize); } else m_pCBParam=NULL; m_rBackAnim=BackAnim; //add to list of gifs if (PictNum == -1) { BOOL Found=FALSE; for(int i=0;i<MAX_ANIM_GIFS && !Found;i++) { if (m_aPictName[i]==0) { m_aPictName[i]=AnimName; Found=TRUE; m_aPictUsageCount[i]=1; m_aBitmaps[i]=m_pBitmap; PictNum=i; } } } if (m_aMaskBitmaps[PictNum] == NULL && m_pMaskBitmap != NULL) //this is done here due to preloaded bitmaps m_aMaskBitmaps[PictNum]=m_pMaskBitmap; //do some calculations ... if (Frames) { m_nLastFrame=Frames; m_bOneFrame=TRUE; } else { m_nLastFrame=m_nBMHeight/m_rArea.Height(); m_bOneFrame=FALSE; } m_nFrame=0; m_bClosing=FALSE; // draw the first frame NextFrame(); //register the animation vector AnimTimer.AddAnim((CObject *)this,BackAnim!=CRect(0,0,0,0)); }