Ejemplo n.º 1
0
/**
 * 从profile中读取大头像, 如果本地没有则进行下载
 *
 * \param pApp
 * \param ResponseInfoPhoto
 *
 * \return 
 */
Boolean TPhotosGetAlbumsForm::_UpdateProfilePhoto(TApplication* pApp, tResponseUsersGetInfo* ResponseInfoPhoto)
{

	if(ResponseInfoPhoto == NULL)
		return FALSE;
	
	if(ResponseInfoPhoto->nArraySize > 0)
	{
		TBitmap* pDownLoadBitmap = NULL;
		pDownLoadBitmap = LoadImgByUrl(ResponseInfoPhoto->Array[0].headurl);						
		if(pDownLoadBitmap == NULL)
		{
			RenRenAPICommon_DownloadPhoto(ResponseInfoPhoto->Array[0].headurl, this->GetWindowHwndId(), FEED_PROFILE_IMAGE_INDEX);	
		}
		else
		{
			TMaskButton* pLogo = NULL;
			pLogo = static_cast<TMaskButton*>(GetControlPtr(m_ProfileImageID));
			if(pLogo)
			{
				TRectangle rc;
				TBitmap * pProfileImageTmp = NULL;	//Profile的头像

				pLogo->GetBounds(&rc);
				
				pProfileImageTmp = TBitmap::Create(RR_HEAD_W, RR_HEAD_W, pDownLoadBitmap->GetDepth());
				pProfileImageTmp->QuickZoom(pDownLoadBitmap, TRUE, TRUE,RGBA(0,0,0,255));
				pLogo->SetCaption(TUSTR_Re_NULL,0,0);
				pLogo->SetImage(pProfileImageTmp, (rc.Width()-pProfileImageTmp->GetWidth())/2, (rc.Height()-pProfileImageTmp->GetHeight())/2);
				pLogo->Draw();

				//如果先Desroy,则会崩溃,很奇怪,原因不明,暂时这么处理
				if( pProfileImage != NULL)
				{
					pProfileImage->Destroy();
					pProfileImage = NULL; 							
				}
				pProfileImage = pProfileImageTmp;
				
			}

			//释放图片
			pDownLoadBitmap->Destroy();
			pDownLoadBitmap = NULL; 	
		}
	}

	return TRUE;
}
Ejemplo n.º 2
0
bool CCImage::initWithString(
                               const char *    pText, 
                               int             nWidth/* = 0*/, 
                               int             nHeight/* = 0*/,
                               ETextAlign      eAlignMask/* = kAlignCenter*/,
                               const char *    pFontName/* = nil*/,
                               int             nSize/* = 0*/)
{
    bool bRet = false;
    TUChar* pWText = NULL;
    do 
    {
        CC_BREAK_IF(! pText);
        int nLen = strlen(pText) + 1;
        CC_BREAK_IF(! (pWText = new TUChar[nLen]));
        TUString::StrGBToUnicode(pWText, (Char*)pText);

        BitmapDC& dc = sharedBitmapDC();

        dc.setFont(pFontName, nSize);

        TSize size(nWidth, nHeight);
        dc.getTextExtentPoint(pWText, nLen, size);
        CC_BREAK_IF(! size.Width() || ! size.Height());

        // set style
        UInt32 styles = GUI_API_STYLE_SPECIFY_FORE_COLOR |  GUI_API_STYLE_ROP_MODE_TRANSPARENT |
            GUI_API_STYLE_CLIP_WORDWRAP | GUI_API_STYLE_SPECIFY_BACK_COLOR | GUI_API_STYLE_SPECIFY_FONT;

        switch (eAlignMask)
        {
        case kAlignCenter:
            styles |= GUI_API_STYLE_ALIGNMENT_CENTER | GUI_API_STYLE_ALIGNMENT_MIDDLE;
            break;
        case kAlignTop:
            styles |= GUI_API_STYLE_ALIGNMENT_CENTER | GUI_API_STYLE_ALIGNMENT_TOP;
            break;
        case kAlignTopRight:
            styles |= GUI_API_STYLE_ALIGNMENT_RIGHT | GUI_API_STYLE_ALIGNMENT_TOP;
            break;
        case kAlignRight:
            styles |= GUI_API_STYLE_ALIGNMENT_RIGHT | GUI_API_STYLE_ALIGNMENT_MIDDLE;
            break;
        case kAlignBottomRight:
            styles |= GUI_API_STYLE_ALIGNMENT_RIGHT | GUI_API_STYLE_ALIGNMENT_BOTTOM;
            break;
        case kAlignBottom:
            styles |= GUI_API_STYLE_ALIGNMENT_CENTER | GUI_API_STYLE_ALIGNMENT_BOTTOM;
            break;
        case kAlignBottomLeft:
            styles |= GUI_API_STYLE_ALIGNMENT_LEFT | GUI_API_STYLE_ALIGNMENT_BOTTOM;
            break;
        case kAlignLeft:
            styles |= GUI_API_STYLE_ALIGNMENT_LEFT | GUI_API_STYLE_ALIGNMENT_MIDDLE;
            break;
        case kAlignTopLeft:
            styles |= GUI_API_STYLE_ALIGNMENT_LEFT | GUI_API_STYLE_ALIGNMENT_TOP;
        }

        CC_BREAK_IF(! dc.drawText(pWText, nLen, size, styles));

        // init image information
        TBitmap * pBitmap = dc.getBitmap();
        CC_BREAK_IF(! pBitmap);

        INT32 nWidth	= pBitmap->GetWidth();
        INT32 nHeight	= pBitmap->GetHeight();
        CC_BREAK_IF(nWidth <= 0 || nHeight <= 0);

        INT32 nDataLen = pBitmap->GetRowBytes() * nHeight;
        m_pData.reset(new ccxByte[nDataLen]);
        CC_BREAK_IF(! m_pData.get());
        memcpy((void*) m_pData.get(), pBitmap->GetDataPtr(), nDataLen);

        m_nWidth    = (ccxInt16)nWidth;
        m_nHeight   = (ccxInt16)nHeight;
        m_bHasAlpha = true;
        m_bPreMulti = true;
        m_nBitsPerComponent = pBitmap->GetDepth() / 4;

        bRet = true;
    } while (0);

    if (pWText)
    {
        delete [] pWText;
        pWText = NULL;
    }

    return bRet;
}