bool ImagesEngine::RenderPage(HDC hDC, RectI screenRect, int pageNo, float zoom, int rotation, RectD *pageRect, RenderTarget target, AbortCookie **cookie_out) { Bitmap *bmp = LoadImage(pageNo); if (!bmp) return false; RectD pageRc = pageRect ? *pageRect : PageMediabox(pageNo); RectI screen = Transform(pageRc, pageNo, zoom, rotation).Round(); Graphics g(hDC); g.SetCompositingQuality(CompositingQualityHighQuality); g.SetSmoothingMode(SmoothingModeAntiAlias); g.SetPageUnit(UnitPixel); Color white(0xFF, 0xFF, 0xFF); Rect screenR(screenRect.x, screenRect.y, screenRect.dx, screenRect.dy); g.SetClip(screenR); g.FillRectangle(&SolidBrush(white), screenR); Matrix m; GetTransform(m, pageNo, zoom, rotation); m.Translate((REAL)(screenRect.x - screen.x), (REAL)(screenRect.y - screen.y), MatrixOrderAppend); g.SetTransform(&m); RectI pageRcI = PageMediabox(pageNo).Round(); ImageAttributes imgAttrs; imgAttrs.SetWrapMode(WrapModeTileFlipXY); Status ok = g.DrawImage(bmp, Rect(0, 0, pageRcI.dx, pageRcI.dy), 0, 0, pageRcI.dx, pageRcI.dy, UnitPixel, &imgAttrs); return ok == Ok; }
void CSkinButton2::DrawImage(Gdiplus::Graphics& gdi,BTN_DRAW_HUE hue) { if(hue == DRAW_NORMAL) { if( m_pPngImage && m_pPngImage->m_pBitmap ) { RectF grect; grect.X=0, grect.Y=0; grect.Width = m_pPngImage->m_pBitmap->GetWidth(); grect.Height = m_pPngImage->m_pBitmap->GetHeight(); gdi.DrawImage(*m_pPngImage,grect ); } } else if(hue == DRAW_LIGHT) { if( m_pPngImage && m_pPngImage->m_pBitmap ) { ImageAttributes ia; ia.SetColorMatrix(&m_LightMat); RectF grect; grect.X=0, grect.Y=0; grect.Width = m_pPngImage->m_pBitmap->GetWidth(); grect.Height = m_pPngImage->m_pBitmap->GetHeight(); gdi.DrawImage(*m_pPngImage, grect, 0, 0, grect.Width, grect.Height, UnitPixel, &ia); } } else if(hue == DRAW_GRAY ) { if( m_pPngImage && m_pPngImage->m_pBitmap ) { ImageAttributes ia; ia.SetColorMatrix(&m_GrayMat); RectF grect; grect.X=0, grect.Y=0; grect.Width = m_pPngImage->m_pBitmap->GetWidth(); grect.Height = m_pPngImage->m_pBitmap->GetHeight(); gdi.DrawImage(*m_pPngImage, grect, 0, 0, grect.Width, grect.Height, UnitPixel, &ia); } } }
// Different requests, compatible resource int UtcDaliImageFactoryCompatibleResource03(void) { TestApplication application; tet_infoline( "UtcDaliImageFactoryCompatibleResource03 - Two requests mapping to same resource" ); ImageFactory& imageFactory = Internal::ThreadLocalStorage::Get().GetImageFactory(); Vector2 testSize(80.0f, 80.0f); application.GetPlatform().SetClosestImageSize(testSize); // this time use defined attributes, nut just NULL ImageAttributes attr = ImageAttributes::New(); attr.SetSize( 120, 120 ); // request with default attributes ( size is 0,0 ) RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, &attr ); ResourceTicketPtr ticket = imageFactory.Load( *req.Get() ); application.SendNotification(); application.Render(); application.SendNotification(); application.Render(); // emulate load success EmulateImageLoaded( application, 80, 80 ); ImageAttributes attr2 = ImageAttributes::New(); attr2.SetSize( 80, 80 ); RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr2 ); ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() ); DALI_TEST_CHECK( req != req2 ); // different requests DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource END_TEST; }
// Different requests, incompatible resource, so two loads result: int UtcDaliImageFactoryInCompatibleResource(void) { TestApplication application; tet_infoline( "UtcDaliImageFactoryCompatibleResource02 - Two requests mapping to same resource." ); ImageFactory& imageFactory = Internal::ThreadLocalStorage::Get().GetImageFactory(); Vector2 testSize(2048.0f, 2048.0f); application.GetPlatform().SetClosestImageSize(testSize); // request with default attributes ( size is 0,0 ) RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL ); ResourceTicketPtr ticket = imageFactory.Load( *req.Get() ); application.SendNotification(); application.Render(); application.SendNotification(); application.Render(); // emulate load success EmulateImageLoaded( application, testSize.x, testSize.y ); // Request substantially different size than actual image. // This will issue a second resource load as difference in sizes is greater than // the small fudge factor used in the ImageFactory cache. ImageAttributes attr = ImageAttributes::New(); attr.SetSize( testSize.x - 16, testSize.y - 16 ); RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr ); ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() ); DALI_TEST_CHECK( req != req2 ); // different requests DALI_TEST_CHECK( ticket->GetId() != ticket2->GetId() ); // differnet resources END_TEST; }
// Different requests, compatible resource int UtcDaliImageFactoryCompatibleResource02(void) { TestApplication application; tet_infoline( "UtcDaliImageFactoryCompatibleResource02 - Two requests mapping to same resource." ); ImageFactory& imageFactory = Internal::ThreadLocalStorage::Get().GetImageFactory(); Vector2 testSize( 2048.0f, 2048.0f ); application.GetPlatform().SetClosestImageSize( testSize ); // request with default attributes ( size is 0,0 ) RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL ); ResourceTicketPtr ticket = imageFactory.Load( *req.Get() ); application.SendNotification(); application.Render(); application.SendNotification(); application.Render(); // emulate load success EmulateImageLoaded( application, testSize.x, testSize.y ); // Request slightly bigger size than actual image. // This will load the same resource as the ImageFactory cache uses a small fudge factor in matching. // See UtcDaliImageFactoryReload06 ImageAttributes attr = ImageAttributes::New(); attr.SetSize( testSize.x + 1, testSize.y + 1 ); RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr ); ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() ); DALI_TEST_CHECK( req != req2 ); // different requests DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource END_TEST; }
VOID Balls::draw(Graphics *graphics, Image *images[]) const { ImageAttributes imAttr; imAttr.SetColorKey(COLOR_KEY, COLOR_KEY); for(size_t i = 0; i < NUMBER_OF_BALLS; i++) graphics->DrawImage(images[i], Rect(static_cast<INT>(points_[i].getX()) - RShari, static_cast<INT>(points_[i].getY()) - RShari, 2 * RShari, 2 * RShari), 0, 0, 2 * RShari, 2 * RShari, Unit::UnitPixel, &imAttr, 0); }
/* * Called by SysStats when the Overlay should render itself */ STDMETHODIMP CAnimatorOverlay::Render(LONG _hdc) { // Get state of animation meter IMeter *iMeter = 0; framecount = 1; currentframe = 0; get_meter(&iMeter); if (iMeter) { iMeter->GetAsLong(L"framecount", &framecount); iMeter->GetAsLong(L"currentframe", ¤tframe); } if (alphaEnd == alpha) CompositeOverlayImpl<IAnimatorOverlay>::Render(_hdc); else { // Create a private HDC to draw into so that we can mask it. long width = 128; long height = 128; model->get_Width(&width); model->get_Height(&height); HDCImage hdc((HDC)_hdc, width, height); // Render the composite CompositeOverlayImpl<IAnimatorOverlay>::Render(hdc); // Copy private HDC into the passed HDC Graphics g((HDC)_hdc); g.SetInterpolationMode(InterpolationModeHighQuality); g.SetSmoothingMode(SmoothingModeAntiAlias); float delta = framecount <= 1 ? 0.0 : ((float)currentframe)/(framecount-1.0); ColorMatrix colorMatrix = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, ((float)alpha+(alphaEnd-alpha)*delta)/255.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; // Create an ImageAttributes object and set its color matrix. ImageAttributes imageAtt; imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); g.DrawImage( &hdc.GetImage(), Rect(0, 0, width, height), // Destination rectangle 0, // Source rectangle X 0, // Source rectangle Y width, // Source rectangle width height, // Source rectangle height UnitPixel, &imageAtt); } return S_OK; }
BOOL CGif::DrawImage(CDC * pDC, POINT * pPoint, int srcx, int srcy, int srcwidth, int srcheight, float * pfClrAttr) { ASSERT(NULL != m_pImage); if (NULL == m_pImage) return 1; if (IsNull()) return 2; Graphics graph(pDC->GetSafeHdc()); Gdiplus::Point points[3]; memset(points, 0, sizeof (points)); if (NULL == pPoint) { points[1].X = m_nWidth; points[2].Y = m_nHeight; } else { for (BYTE i = 0;i < 3;i++) { points[i].X = pPoint[i].x; points[i].Y = pPoint[i].y; } } if ((0 == srcwidth)||(0 == srcheight)) { srcwidth = m_nWidth; srcheight = m_nHeight; } if (NULL == pfClrAttr) { graph.DrawImage(m_pImage, points, 3, srcx, srcy, srcwidth, srcheight, UnitPixel); } else { #ifdef _DEBUG for (BYTE i = 0;i < 25;i++) { ASSERT(0 <= pfClrAttr[i]); } #endif ColorMatrix colorMatrix; memcpy(&colorMatrix, pfClrAttr, sizeof (colorMatrix)); ImageAttributes imageAttr; imageAttr.SetColorMatrix(&colorMatrix); graph.DrawImage(m_pImage, points, 3, srcx, srcy, srcwidth, srcheight, UnitPixel, &imageAttr); } graph.ReleaseHDC(pDC->GetSafeHdc()); return TRUE; }
void ImageView::SetImageDistanceField(const std::string& filename) { ImageAttributes attributes = Dali::ImageAttributes::NewDistanceField(1.0f, 1); const Vector3 size = Self().GetCurrentSize(); attributes.SetSize( size.x, size.y ); Image image = Image::NewDistanceField(filename, attributes); mImageActor.SetImage( image ); DistanceFieldEffect effect = DistanceFieldEffect::New(); Self().SetShaderEffect( effect ); }
//╩Л╨о╩Ф╩╜ bool CPngImageEx::AlphaDrawImage(CDC * pDestDC, INT xDest, INT yDest, INT cxDest, INT cyDest, INT xSrc, INT ySrc, INT cxSrc, INT cySrc, BYTE cbAlphaDepth) { //WIN 7 ж╢пп if ( CD2DEngine::GetD2DEngine() ) { CD2DEngine::GetD2DEngine()->DrawImage(m_pWnd, m_strImageName, xDest, yDest, cxDest, cyDest, xSrc, ySrc, cxSrc, cySrc, cbAlphaDepth ); return true; } //╢╢╫╗╩╨ЁЕ if ((cxDest!=cxSrc)||(cyDest!=cySrc)) { //╪стьеп╤о ASSERT(m_pImage!=NULL); if (m_pImage==NULL) return false; //╢╢╫╗фад╩ ASSERT(pDestDC!=NULL); Graphics graphics(pDestDC->GetSafeHdc()); //╧╧тЛн╩жц RectF rcDrawRect; rcDrawRect.X=(REAL)xDest; rcDrawRect.Y=(REAL)yDest; rcDrawRect.Width=(REAL)cxDest; rcDrawRect.Height=(REAL)cyDest; //м╦цВ╬ьуС ColorMatrix Matrix= { 1.0f,0.0f,0.0f,0.0f,0.0f, 0.0f,1.0f,0.0f,0.0f,0.0f, 0.0f,0.0f,1.0f,0.0f,0.0f, 0.0f,0.0f,0.0f,cbAlphaDepth/255.0f,0.0f, 0.0f,0.0f,0.0f,0.0f,1.0f }; //иХжцйТпт ImageAttributes Attributes; Attributes.SetColorMatrix(&Matrix,ColorMatrixFlagsDefault,ColorAdjustTypeBitmap); //╩Ф╩╜м╪оЯ graphics.DrawImage(m_pImage,rcDrawRect,(REAL)xSrc,(REAL)ySrc,(REAL)cxSrc,(REAL)cySrc,UnitPixel,&Attributes); } else { //фум╗╣Всц AlphaDrawImage(pDestDC,xDest,yDest,cxDest,cyDest,xSrc,ySrc,cbAlphaDepth); } return true; }
int UtcDaliImageActorGetCurrentImageSize03(void) { TestApplication application; tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load"); Vector2 closestImageSize( 80, 45); application.GetPlatform().SetClosestImageSize(closestImageSize); ImageAttributes attrs; attrs.SetSize(40, 30); Image image = Image::New("image.jpg", attrs); ImageActor actor = ImageActor::New( image ); Stage::GetCurrent().Add(actor); application.SendNotification(); // Flush update messages application.Render(); // Process resource request application.SendNotification(); // Flush update messages application.Render(); // Process resource request DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION ); // Now complete the image load Integration::ResourceRequest* req = application.GetPlatform().GetRequest(); Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height ); Integration::ResourcePointer resourcePtr(bitmap); // reference it application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr); application.Render(); // Process LoadComplete application.SendNotification(); // Process event messages application.GetPlatform().DiscardRequest(); // Ensure load request is discarded application.GetPlatform().ClearReadyResources(); // DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION ); // Test that setting a size on the actor can be 'undone' with SetNaturalSize() Vector2 size(200.0f, 200.0f); actor.SetSize(size); // flush the queue and render once application.SendNotification(); application.Render(); DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION ); actor.SetToNaturalSize(); application.SendNotification(); application.Render(); DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION ); END_TEST; }
/* ** Turns the image greyscale by applying a greyscale color matrix. ** Note that the returned bitmap image must be freed by caller. ** */ Bitmap* TintedImage::TurnGreyscale(Bitmap* source) { ImageAttributes ImgAttr; ImgAttr.SetColorMatrix(&c_GreyScaleMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); // We need a blank bitmap to paint our greyscale to in case of alpha Rect r(0, 0, source->GetWidth(), source->GetHeight()); Bitmap* bitmap = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB); Graphics graphics(bitmap); graphics.DrawImage(source, r, 0, 0, r.Width, r.Height, UnitPixel, &ImgAttr); return bitmap; }
// Initally two different requests map to same resource. // After overwriting the file, they load different image resources. int UtcDaliImageFactoryReload06(void) { TestApplication application; tet_infoline( "UtcDaliImageFactoryReload06 - Two requests first mapping to same resource, then different resources." ); ImageFactory& imageFactory = Internal::ThreadLocalStorage::Get().GetImageFactory(); Vector2 testSize(2048.0f, 2048.0f); application.GetPlatform().SetClosestImageSize( testSize ); // request with default attributes ( size is 0,0 ) RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL ); ResourceTicketPtr ticket = imageFactory.Load( *req.Get() ); application.SendNotification(); application.Render(); application.SendNotification(); application.Render(); // emulate load success EmulateImageLoaded( application, testSize.x, testSize.y ); // Request bigger size than actual image. // This will load the same resource. // However if image size changes later on to eg. 512*512 (file is overwritten), // reissuing these two requests will load different resources. ImageAttributes attr = ImageAttributes::New(); attr.SetSize( testSize.x + 1, testSize.y + 1 ); RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr ); ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() ); DALI_TEST_CHECK( req != req2 ); // different requests DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource Vector2 newSize(512.0f, 512.0f); application.GetPlatform().SetClosestImageSize(newSize); // reload fixed size (192,192) request ticket2 = imageFactory.Reload( *req2.Get() ); // emulate load success // note: this is the only way to emulate what size is loaded by platform abstraction EmulateImageLoaded( application, testSize.x + 1, testSize.y + 1 ); // reload default size request ticket = imageFactory.Reload( *req.Get() ); DALI_TEST_CHECK( ticket->GetId() != ticket2->GetId() ); // different resources END_TEST; }
/* gamma 参数的典型值在 1.0 到 2.2 之间;但在某些情况下,0.1 到 5.0 范围内的值也很有用。 imageAttr.SetGamma 参数值越大,图像越暗,反之则越亮 */ Bitmap * HighlightBitmap(Bitmap * pSrc, float fGamma, BOOL bCreate ) { if (pSrc == NULL) return NULL; if (fGamma <= 0.0f) return NULL; RectF rc(0.0f, 0.0f, (float)pSrc->GetWidth(), (float)pSrc->GetHeight()); if ( rc.IsEmptyArea()) return NULL; Bitmap * pResult = !bCreate ? pSrc : new Bitmap( (int)rc.Width, (int)rc.Height, pSrc->GetPixelFormat() ); if( pResult == NULL ) return NULL; Graphics * g = Graphics::FromImage(pResult); if ( g == NULL) { if (bCreate) { delete pResult; pResult = NULL; } return NULL; } ImageAttributes imageAttr; ////////////////////////////////////////////////////////////////////////// #if TRUE imageAttr.SetGamma( 1/fGamma ); #else Gdiplus:: ColorMatrix HotMat = {1.05f, 0.00f, 0.00f, 0.00f,0.00f, 0.00f, 1.05f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 1.05f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 1.00f, 0.00f, 0.05f, 0.05f, 0.05f, 0.00f, 1.00f}; imageAttr.SetColorMatrix(&HotMat); #endif ////////////////////////////////////////////////////////////////////////// Status status = g->DrawImage(pSrc, rc, 0, 0, (float)pSrc->GetWidth(), (float)pSrc->GetHeight() ,Gdiplus:: UnitPixel, &imageAttr); delete g; g = NULL; if ( Ok != status ) { if (bCreate) { delete pResult; pResult = NULL; } return NULL; } return pResult; }
void CEnteringRoomDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CDialog::OnPaint() //中间 CRect rcClient ; GetClientRect( &rcClient ) ; Graphics graphics(dc); ImageAttributes imgAtt; imgAtt.SetWrapMode(WrapModeTileFlipXY);//GDI+在位伸图片时会自动加上渐变效果。但此处不需要,所以得加上此属性 //去掉边框 //左上、上中、右上 graphics.DrawImage(m_imgTopLeft,Rect(0, 0, m_imgTopLeft->GetWidth(), m_imgTopLeft->GetHeight()), 0, 0, m_imgTopLeft->GetWidth(), m_imgTopLeft->GetHeight(),UnitPixel,&imgAtt);//没拉抻 graphics.DrawImage(m_imgTopMid, Rect(m_imgTopLeft->GetWidth(), 0, rcClient.Width() - m_imgTopLeft->GetWidth() * 2, m_imgTopMid->GetHeight()), 0, 0, rcClient.Width() - m_imgTopLeft->GetWidth() * 2, m_imgTopMid->GetHeight(), UnitPixel,&imgAtt); graphics.DrawImage(m_imgTopRight, Rect(rcClient.right - m_imgTopRight->GetWidth() - 1, 0, m_imgTopRight->GetWidth(), m_imgTopRight->GetHeight()), 0, 0, m_imgTopRight->GetWidth(), m_imgTopRight->GetHeight(), UnitPixel,&imgAtt); //左中、右中 graphics.DrawImage(m_imgMidLeft, Rect(0, m_imgTopMid->GetHeight(), m_imgMidLeft->GetWidth(), rcClient.Height() - m_imgTopMid->GetHeight() * 2), 0, 0, m_imgMidLeft->GetWidth(), rcClient.Height() - m_imgTopMid->GetHeight() * 2, UnitPixel,&imgAtt); graphics.DrawImage(m_imgMidRight, Rect(rcClient.right - m_imgMidRight->GetWidth() - 1, m_imgTopMid->GetHeight(), m_imgMidRight->GetWidth(), rcClient.Height() - m_imgTopMid->GetHeight() * 2), 0, 0, m_imgMidRight->GetWidth(), rcClient.Height() - m_imgTopMid->GetHeight() * 2,UnitPixel,&imgAtt); //左下、下中、右下 graphics.DrawImage(m_imgBottomLeft,Rect(0, rcClient.bottom - m_imgBottomLeft->GetHeight() - 1, m_imgBottomLeft->GetWidth(), m_imgBottomLeft->GetHeight()), 0, 0, m_imgBottomLeft->GetWidth(), m_imgBottomLeft->GetHeight(), UnitPixel,&imgAtt); graphics.DrawImage(m_imgBottomMid, Rect(m_imgMidLeft->GetWidth(), rcClient.bottom - m_imgBottomMid->GetHeight() - 1, rcClient.Width() - m_imgMidLeft->GetWidth() * 2, m_imgBottomMid->GetHeight()), 0, 0,rcClient.Width() - m_imgMidLeft->GetWidth() * 2, m_imgBottomMid->GetHeight(), UnitPixel,&imgAtt); graphics.DrawImage(m_imgBottomRight,Rect(rcClient.right - m_imgBottomRight->GetWidth() - 1, rcClient.bottom - m_imgBottomRight->GetHeight() - 1, m_imgBottomRight->GetWidth(), m_imgBottomRight->GetHeight()), 0, 0, m_imgBottomRight->GetWidth(), m_imgBottomRight->GetHeight(), UnitPixel,&imgAtt); //中间 graphics.DrawImage( m_pPic->GetCurImage() ,Rect(m_imgMidLeft->GetWidth(), m_imgTopMid->GetHeight(), rcClient.Width() - m_imgMidLeft->GetWidth() * 2 - 1 , rcClient.Height() - m_imgTopMid->GetHeight() * 2 - 1), 0, 0, rcClient.Width() - m_imgMidLeft->GetWidth() * 2 - 1 , rcClient.Height() - m_imgTopMid->GetHeight() * 2 - 1,UnitPixel,&imgAtt) ; /*graphics.DrawImage( m_pPic->GetCurImage() ,Rect(0, 0, rcClient.Width(), rcClient.Height()), 0, 0, rcClient.Width(), rcClient.Height(),UnitPixel,&imgAtt) ;*/ }
VOID Cue::draw(Graphics *pGraphics, Pen &rPen, Image &rCue) const { auxiliaryLine_.draw((ball_ - auxiliaryLine_).getX(), (ball_ - auxiliaryLine_).getY(), pGraphics, rPen, static_cast<ARGB>(Color::Gray)); rPen.SetColor(static_cast<ARGB>(Color::Gray)); rPen.SetWidth(3); pGraphics->DrawEllipse(&rPen, static_cast<INT>(mouse_.getX() - RShari), static_cast<INT>(mouse_.getY() - RShari), RShari * 2, RShari * 2); pGraphics->TranslateTransform(static_cast<REAL>(ball_.getX()), static_cast<REAL>(ball_.getY())); pGraphics->RotateTransform(angle_); ImageAttributes imAttr; imAttr.SetColorKey(COLOR_KEY, COLOR_KEY); pGraphics->DrawImage(&rCue, Rect(static_cast<INT>(-884 - force_ * 8), static_cast<INT>(-20 / 2), 884 * 2, 20), 0, 0, 884 * 2, 20, Unit::UnitPixel, &imAttr, 0); pGraphics->ResetTransform(); }
void CRenderUtility::DrawImage( HDC hDC, Image* pImage, RECT &rctDst, RECT&rctSrc, int nAlpha /*= 255*/ ) { if(pImage == NULL || nAlpha == 0) return; float fAlpha = (float)nAlpha / 255.0f; Graphics graph(hDC); ColorMatrix colorMatrix={1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, fAlpha, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; ImageAttributes imgAtt; imgAtt.SetColorMatrix(&colorMatrix); Rect rcDst(rctDst.left, rctDst.top, RECT_WIDTH(rctDst), RECT_HEIGHT(rctDst)); graph.DrawImage(pImage, rcDst, rctSrc.left, rctSrc.top, RECT_WIDTH(rctSrc), RECT_HEIGHT(rctSrc), UnitPixel, &imgAtt); }
/* ** This will apply the Greyscale matrix and the color tinting. ** */ void TintedImage::ApplyTint() { bool useColorMatrix = !CompareColorMatrix(m_ColorMatrix, &c_IdentityMatrix); if (m_GreyScale || useColorMatrix) { Bitmap* original = GetImage(); Bitmap* tint; if (m_GreyScale && !useColorMatrix) { tint = TurnGreyscale(original); } else { ImageAttributes ImgAttr; ImgAttr.SetColorMatrix(m_ColorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); Rect r(0, 0, original->GetWidth(), original->GetHeight()); tint = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB); Graphics graphics(tint); if (m_GreyScale) { Bitmap* gray = TurnGreyscale(original); graphics.DrawImage(gray, r, 0, 0, r.Width, r.Height, UnitPixel, &ImgAttr); delete gray; } else { graphics.DrawImage(original, r, 0, 0, r.Width, r.Height, UnitPixel, &ImgAttr); } } delete m_BitmapTint; m_BitmapTint = tint; } }
/// 加入一张图片,图片横向分成几帧,带关键色 /// @param[in] const wchar_t pszFileName* 图片文件名(Unicode) /// @param[in] int nCutInHor 横向分成几帧 void CWndAnimate::AppendPNG(const wchar_t *pszFileName, COLORREF clrKey, int nCutInHor) { Image *img = NULL; img = InitImageFromPkg(pszFileName); if (NULL == img) { return; } if (img->GetWidth()<=0 || img->GetHeight()<=0) { return; } ImageAttributes ima; ima.SetColorKey(Color(0, GetRValue(clrKey), GetGValue(clrKey), GetBValue(clrKey)), Color(255, GetRValue(clrKey), GetGValue(clrKey), GetBValue(clrKey))); for (int i=0; i<nCutInHor; ++i) { CMemdc memDC; memDC.Create(GetDC()->GetSafeHdc(), img->GetWidth()/nCutInHor, img->GetHeight()); /// 绘图 Graphics grac(memDC.GetCompatibleDC()); grac.DrawImage(img, Rect(0, 0, memDC.GetWidth(), memDC.GetHeight()), img->GetWidth()/nCutInHor*i, 0, img->GetWidth()/nCutInHor, img->GetHeight(), UnitPixel, &ima); grac.ReleaseHDC(memDC.GetCompatibleDC()); m_FrameList.push_back(memDC); m_nFrameCount ++; } delete img; img = NULL; }
//输入原图片指针的指针,及新图片的新宽高 //示例:ResizeBitmap(&m_pOrignImageS,width,height); BOOL CExampleDemoDlg::ResizeBitmap(Bitmap **ppImg, int m_NewWidth, int m_NewHeight) { if (ppImg == NULL || *ppImg == NULL) { return FALSE; } Bitmap *m_NewImage = new Bitmap(m_NewWidth, m_NewHeight); ColorMatrix colorMatrix = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; ImageAttributes imageAtt; imageAtt.SetColorMatrix(&colorMatrix); imageAtt.SetWrapMode(WrapModeTileFlipXY); Graphics gs(m_NewImage); gs.SetSmoothingMode(SmoothingModeAntiAlias); gs.SetInterpolationMode(InterpolationModeHighQuality); gs.DrawImage( (*ppImg), Rect(0, 0, m_NewWidth, m_NewHeight), // Destination rectangle 0, // Source rectangle temp->x 0, // Source rectangle temp->y (*ppImg)->GetWidth(), // Source rectangle width (*ppImg)->GetHeight(), // Source rectangle height UnitPixel, &imageAtt); //交换指针 delete (*ppImg); (*ppImg) = m_NewImage; return TRUE; }
void ImageView::SetImageBitmap(const std::string& filename, float min, float max) { int minLevel = ceilf(logf(min) / logf(2.0f)); int maxLevel = ceilf(logf(max) / logf(2.0f)); ImageAttributes attributes; const Vector3 size = Self().GetCurrentSize(); if(minLevel==maxLevel) { // Single image detail level, no need for any notifications. const float detail = powf(2.0f, maxLevel); attributes.SetSize( size.x * detail, size.y * detail ); Image image = Image::New( filename, attributes); mImageActor.SetImage( image ); } else { // Multi image detail level... for( int level = minLevel; level <= maxLevel; level++) { const float minDetail = powf(2.0f, level - 1); const float maxDetail = powf(2.0f, level); ImageRequest req(filename, size.x * maxDetail, size.y * maxDetail ); if(level==minLevel) { AddImage(req, LessThanCondition(maxDetail) ); } else if(level==maxLevel) { AddImage(req, GreaterThanCondition(minDetail) ); } else { AddImage(req, InsideCondition(minDetail, maxDetail) ); } } } }
CharacterPattern::ControlType ImageReader::UpdateImageAttributes(ImageAttributes& imageAttributes, const QImage& image) { #ifdef CHARACTERGRID_DEBUG if (m_CharacterGrid.GetImage().size() != image.size()) { m_CharacterGrid.GetImage() = QImage(image.size(), image.format()); } #endif // CHARACTERGRID_DEBUG m_CharacterGrid.SetLowerRgbLimit(CHARACTERGRID_LOWER_RGB_LIMIT); const int height = image.height(); for (int x = IMAGEATTRIBUTES_CONTROL_X_START, y = 0; y < height; ++y) { if (!m_CharacterGrid.IsPartOfCharacter(image.pixel(x, y))) { continue; } m_CharacterGrid.FindCharacter(image, x, y, imageAttributes); CharacterPattern::ControlType controlType = m_Pattern.ConvertCharGridToImageAttributes(imageAttributes, m_CharacterGrid); if (controlType != CharacterPattern::InvalidControl) { // Control type valid, update image attributes and return control type imageAttributes.SetLastLineY(m_CharacterGrid.GetYOffset() - imageAttributes.GetLastLineControlYOffset()); return controlType; } y = qMax(y, m_CharacterGrid.GetYOffset() + m_CharacterGrid.GetUsedHeight() - 1); } imageAttributes.SetLastLineY(-1); #ifdef CHARACTERGRID_DEBUG m_CharacterGrid.GetImage().save("../Images/debugImage.png"); #endif // CHARACTERGRID_DEBUG return CharacterPattern::InvalidControl; }
void DrawAvatarImageWithGDIp(HDC hDestDC, int x, int y, DWORD width, DWORD height, HBITMAP hbmp, int x1, int y1, DWORD width1, DWORD height1, DWORD flag, BYTE alpha) { BITMAP bmp; Bitmap *bm; BYTE * bmbits = nullptr; GetObject(hbmp, sizeof(BITMAP), &bmp); Graphics g(hDestDC); if (bmp.bmBitsPixel == 32 && (flag&AVS_PREMULTIPLIED)) { bmbits = (BYTE*)bmp.bmBits; if (!bmbits) { bmbits = (BYTE*)malloc(bmp.bmHeight*bmp.bmWidthBytes); GetBitmapBits(hbmp, bmp.bmHeight*bmp.bmWidthBytes, bmbits); } bm = new Bitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmWidthBytes, PixelFormat32bppPARGB, bmbits); bm->RotateFlip(RotateNoneFlipY); if (!bmp.bmBits) { bm->RotateFlip(RotateNoneFlipY); free(bmbits); } } else bm = new Bitmap(hbmp, nullptr); ImageAttributes attr; ColorMatrix Matrix = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, ((float)alpha) / 255, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; attr.SetColorMatrix(&Matrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); g.SetInterpolationMode(InterpolationModeHighQualityBicubic); RectF rect((float)x, (float)y, (float)width, (float)height); g.DrawImage(bm, rect, (float)x1, (float)y1, (float)width1, (float)height1, UnitPixel, &attr, nullptr, nullptr); delete bm; }
BOOL GDIPlus_AlphaBlend(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, BLENDFUNCTION * bf) { Graphics g(hdcDest); BITMAP bmp; HBITMAP hbmp = (HBITMAP)GetCurrentObject(hdcSrc, OBJ_BITMAP); GetObject(hbmp, sizeof(BITMAP), &bmp); Bitmap *bm; if (bmp.bmBitsPixel == 32 && bf->AlphaFormat) { bm = new Bitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmWidthBytes, PixelFormat32bppPARGB, (BYTE*)bmp.bmBits); bm->RotateFlip(RotateNoneFlipY); } else bm = new Bitmap(hbmp, nullptr); ImageAttributes attr; ColorMatrix Matrix = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, ((float)bf->SourceConstantAlpha) / 255, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; attr.SetColorMatrix(&Matrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); if (bf->BlendFlags & 128 && nWidthDest < nWidthSrc && nHeightDest < nHeightSrc) { g.SetInterpolationMode(InterpolationModeHighQualityBicubic); g.SetPixelOffsetMode(PixelOffsetModeHalf); attr.SetGamma((REAL)0.8, ColorAdjustTypeBitmap); } else g.SetInterpolationMode(InterpolationModeLowQuality); RectF rect((float)nXOriginDest, (float)nYOriginDest, (float)nWidthDest, (float)nHeightDest); g.DrawImage(bm, rect, (float)nXOriginSrc, (float)nYOriginSrc, (float)nWidthSrc, (float)nHeightSrc, UnitPixel, &attr, nullptr, nullptr); delete bm; return TRUE; }
// *************************************************************** // InitImageAttributes() // *************************************************************** void TilesDrawer::InitImageAttributes(TileManager* manager, ImageAttributes& attr) { attr.SetWrapMode(WrapModeTileFlipXY); if (!manager->IsBackground()) { Gdiplus::ColorMatrix m = ImageHelper::CreateMatrix(manager->contrast, manager->brightness, manager->saturation, manager->hue, 0.0f, RGB(255, 255, 255), false, manager->get_Alpha() / 255.0f); attr.SetColorMatrix(&m); if (manager->useTransparentColor) { Gdiplus::Color color(GetRValue(manager->transparentColor), GetGValue(manager->transparentColor), GetBValue(manager->transparentColor)); attr.SetColorKey(color, color); } } }
void DrawHighlight( Image * pImage, Graphics * pGraphics, RectF rcDraw, float fGamma /*= 2.2f */ ) { if (pGraphics == NULL) return; if (pImage == NULL) return; ImageAttributes imageAttr; ////////////////////////////////////////////////////////////////////////// #if FALSE imageAttr.SetGamma( 1/fGamma ); #else Gdiplus:: ColorMatrix HotMat = {1.05f, 0.00f, 0.00f, 0.00f,0.00f, 0.00f, 1.05f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 1.05f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 1.00f, 0.00f, 0.05f, 0.05f, 0.05f, 0.00f, 1.00f}; imageAttr.SetColorMatrix(&HotMat); #endif ////////////////////////////////////////////////////////////////////////// RectF rc (0.0f, 0.0f, (float)pImage->GetWidth(), (float)pImage->GetHeight()); pGraphics->DrawImage( pImage, rcDraw, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height , Gdiplus:: UnitPixel, &imageAttr ); }
void DrawSudoku(Image * pImage, Graphics * pGraphics, RectF& rcDraw , UINT nLeft, UINT nTop, UINT nRight, UINT nBottom ) { if (pGraphics == NULL) return; if (pImage == NULL) return; UINT cx = pImage->GetWidth(); UINT cy = pImage->GetHeight(); if ( nLeft + nRight > cx ) { nLeft = nRight = 0; } if ( nTop + nBottom > cy ) { nTop = nBottom = 0; } //左上角 if (nLeft > 0 && nTop > 0 && nTop < cy && nLeft < cx) { pGraphics->DrawImage( pImage , rcDraw.GetLeft(), rcDraw.GetTop() , 0.0f, 0.0f, (float)nLeft, (float)nTop , Gdiplus:: UnitPixel ); } //右上角 if (nRight > 0 && nTop > 0 && nTop < cy && nRight < cx) { pGraphics->DrawImage( pImage , rcDraw.GetRight() - (float)nRight, rcDraw.GetTop() , (float)cx - (float)nRight, 0.0f, (float)nRight, (float)nTop , Gdiplus:: UnitPixel ); } //右下角 if (nRight > 0 && nBottom > 0 && nBottom < cy && nRight < cx) { pGraphics->DrawImage( pImage , rcDraw.GetRight() - (float)nRight, rcDraw.GetBottom() - (float)nBottom , (float)cx - (float)nRight, (float)cy - (float)nBottom, (float)nRight, (float)nBottom , Gdiplus:: UnitPixel ); } //左下角 if (nLeft > 0 && nBottom > 0 && nBottom < cy && nLeft < cx) { pGraphics->DrawImage( pImage , rcDraw.GetLeft(), rcDraw.GetBottom() - (float)nBottom , 0.0f, (float)cy - (float)nBottom , (float)nLeft, (float)nBottom , Gdiplus:: UnitPixel ); } ImageAttributes ImgAtt; ImgAtt.SetWrapMode(WrapModeTileFlipXY); //左边 if (nLeft > 0 && cy - nTop - nBottom > 0) { RectF rc(rcDraw.GetLeft(), rcDraw.GetTop() + (float)nTop , (float)nLeft, rcDraw.Height - (float)nTop - (float)nBottom ); pGraphics->DrawImage( pImage , rc , 0.0f, (float)nTop, (float)nLeft, (float)cy - (float)nTop - (float)nBottom , UnitPixel, &ImgAtt ); } //上边 if (nTop > 0 && cx - nLeft - nRight > 0) { RectF rc(rcDraw.GetLeft() + (float)nLeft, rcDraw.GetTop() , rcDraw.Width - (float)nLeft - (float)nRight, (float)nTop ); pGraphics->DrawImage( pImage , rc , (float)nLeft, 0.0f, (float)cx - (float)nLeft - (float)nRight, (float)nTop , UnitPixel, &ImgAtt ); } //右边 if (nRight > 0 && cy - nTop - nBottom > 0) { RectF rc(rcDraw.GetRight() - (float)nRight, rcDraw.GetTop() + (float)nTop , (float)nRight, rcDraw.Height - (float)nTop - (float)nBottom ); pGraphics->DrawImage( pImage , rc , (float)cx - (float)nRight, (float)nTop, (float)nRight, (float)cy - (float)nTop - (float)nBottom , UnitPixel, &ImgAtt ); } //下边 if (nBottom > 0 && cx - nLeft - nRight > 0) { RectF rc(rcDraw.GetLeft() + (float)nLeft, rcDraw.GetBottom() - (float)nBottom , rcDraw.Width - (float)nLeft - (float)nRight, (float)nBottom ); pGraphics->DrawImage( pImage , rc , (float)nLeft, (float)cy - (float)nBottom, (float)cx - (float)nLeft - (float)nRight, (float)nBottom , UnitPixel, &ImgAtt ); CString str; str.Format("下边:%0.4f", rc.GetTop()); OutputDebugString(str); } //中间 { RectF rc = rcDraw; if (nLeft > 0) rc.X += (float)nLeft; if (nTop > 0) rc.Y += (float)nTop; if (nRight > 0) rc.Width -= (float)nRight; if (nBottom > 0) rc.Height -= (float)nBottom; rc.Width -= (float)nLeft; rc.Height -= (float)nTop; pGraphics->DrawImage( pImage , rc , (float)nLeft, (float)nTop, (float)(cx - nLeft - nRight), (float)(cy - nBottom - nTop) , UnitPixel, &ImgAtt ); } }
// // 윈도우 프로시져 함수 ( 메시지 큐에서 받아온 메시지를 처리한다 ) // LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; HDC hdc; switch (msg) { case WM_PAINT: // 화면이 갱신될 때 호출된다. { hdc = BeginPaint(hWnd, &ps); Graphics *graph = Graphics::FromImage(g_bmp); RECT cr; GetClientRect(hWnd, &cr); Rect wndSize(cr.left, cr.top, cr.right, cr.bottom); graph->DrawImage(g_image, wndSize); graph->FillRectangle(g_yellowBrush, g_block); graph->FillRectangle(g_yellowBrush, g_block2); graph->DrawImage(g_image2, g_bullet, g_bulletSrc.X, g_bulletSrc.Y, g_bulletSrc.Width, g_bulletSrc.Height, UnitPixel); float fBlend = 1.f; //set the alpha value ColorMatrix BitmapMatrix = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, fBlend, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; ImageAttributes ImgAttr; ImgAttr.SetColorMatrix(&BitmapMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); //graph->SetCompositingMode(CompositingModeSourceCopy); if (g_isCollision) { graph->DrawImage(g_image3, g_bullet, g_explosion.X, g_explosion.Y, g_explosion.Width, g_explosion.Height, UnitPixel, &ImgAttr); } // graph->DrawImage(g_image3, g_bullet, // g_explosion.X, g_explosion.Y, g_explosion.Width, g_explosion.Height, // UnitPixel); DrawString(graph, 50, 0, frameStr); g_graphics->DrawImage(g_bmp, wndSize); EndPaint(hWnd, &ps); } break; // case WM_ERASEBKGND: // return 0; case WM_LBUTTONDOWN: { g_IsClick = true; g_mouseClickPos = Point(LOWORD(lParam), HIWORD(lParam)); } break; case WM_LBUTTONUP: { g_IsClick = false; } break; case WM_MOUSEMOVE: { } break; case WM_KEYDOWN: switch (wParam) { case VK_LEFT: case VK_UP: ++g_hatchStyle; break; case VK_RIGHT: case VK_DOWN: --g_hatchStyle; break; } break; case WM_TIMER: { if (wParam == 1) { int a = 0; } else if (wParam == 2) { int a = 0; } } break; case WM_DESTROY: //윈도우가 파괴된다면.. PostQuitMessage(0); //프로그램 종료 요청 ( 메시지 루프를 빠져나가게 된다 ) break; } return DefWindowProc( hWnd, msg, wParam, lParam ); // 기본적인 메세지 처리를 담당한다. }
QString ImageReader::ReadLineFromBottom(const QImage& image, const ImageAttributes& imageAttributes, int lineCount, int lineIndex) { #ifdef CHARACTERGRID_DEBUG if (m_CharacterGrid.GetImage().size() != image.size() || lineIndex == 0) { m_CharacterGrid.GetImage() = QImage(image.size(), image.format()); } #endif // CHARACTERGRID_DEBUG const int lastLineY = imageAttributes.GetLastLineY() - lineIndex * imageAttributes.GetLineDistance() + imageAttributes.GetLineYOffset(); if (lastLineY < 0 || lastLineY >= image.height()) { // line position invalid, return return ""; } Q_ASSERT(lineIndex >= 0 && lineIndex < lineCount); QString numbers; QRgb rgb = QColor(Qt::black).rgb(); m_CharacterGrid.SetLowerRgbLimit(CHARACTERGRID_LOWER_RGB_LIMIT); int lastValidX = INT_MAX; int lastValidCharX = IMAGEATTRIBUTES_LINE_X_START; const int lineWidth = IMAGEATTRIBUTES_MAX_WIDTH; for (int x = IMAGEATTRIBUTES_LINE_X_START, y = lastLineY; x < lineWidth; ++x) { const int minValidX = x - imageAttributes.GetCharacterWidth() * 3; if (lastValidX < minValidX || lastValidCharX < minValidX) { // Line numbers all found, break break; } if (!CharacterGrid::IsDeviationTooLarge(image, rgb, x, y)) { continue; } if (m_CharacterGrid.IsPartOfCharacter(image.pixel(x, y))) { lastValidCharX = x; } if (!m_CharacterGrid.IsPartOfNumber(image.pixel(x, y))) { continue; } m_CharacterGrid.FindNumber(image, x, y, imageAttributes); int offsetAdd = 0; if (m_CharacterGrid.GetXOffset() <= x - imageAttributes.GetCharacterWidth()) { // Read more numbers at once, set offset to begin of last completely read number offsetAdd = (x - m_CharacterGrid.GetXOffset()) / imageAttributes.GetCharacterWidth() * imageAttributes.GetCharacterWidth(); } const QString number = m_Pattern.ConvertCharGridToCharacter(m_CharacterGrid, imageAttributes, offsetAdd); if (number != "") { lastValidX = x; numbers += number; QRgb lastRgb = image.pixel(x, y); int lred = qRed(lastRgb); int lgreen = qGreen(lastRgb); int lblue = qBlue(lastRgb); // R238, G51, B51 (Krit) // R224, G129, B3 (Normal) // R208, G82, B209 (Condi) // R51, G204, B17 (Healing) if ((lred>150)&& (lgreen<60) && (lblue<60)) LastColor=1; if ((lred>100)&& (lgreen>70) && (lblue<40)) LastColor=2; if ((lred>100)&& (lgreen<80) && (lblue>100)) LastColor=3; if (((lred>90) && (lred<140)) && ((lgreen>90) && (lgreen<140)) && ((lblue>90) && (lblue<140))) LastColor=4; //timestamp color if ((lred<60)&&(lred>40) && (lgreen>110) && (lblue>10) && (lblue<40)) LastColor=5; x = qMax(x, m_CharacterGrid.GetXOffset() + offsetAdd + imageAttributes.GetCharacterWidth() - 1); } } #ifdef CHARACTERGRID_DEBUG m_CharacterGrid.GetImage().save("../Images/debugImage.png"); #endif // CHARACTERGRID_DEBUG return numbers; }
/* ** Draws the meter on the double buffer ** */ bool MeterImage::Draw(Gfx::Canvas& canvas) { if (!Meter::Draw(canvas)) return false; if (m_Image.IsLoaded()) { // Copy the image over the doublebuffer Bitmap* drawBitmap = m_Image.GetImage(); int imageW = drawBitmap->GetWidth(); int imageH = drawBitmap->GetHeight(); if (imageW == 0 || imageH == 0 || m_W == 0 || m_H == 0) return true; int x = GetX(); int y = GetY(); int drawW = m_W; int drawH = m_H; if (drawW == imageW && drawH == imageH && m_ScaleMargins.left == 0 && m_ScaleMargins.top == 0 && m_ScaleMargins.right == 0 && m_ScaleMargins.bottom == 0) { canvas.DrawBitmap(drawBitmap, Rect(x, y, drawW, drawH), Rect(0, 0, imageW, imageH)); } else if (m_DrawMode == DRAWMODE_TILE) { Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext(); ImageAttributes imgAttr; imgAttr.SetWrapMode(WrapModeTile); Rect r(x, y, drawW, drawH); graphics.DrawImage(drawBitmap, r, 0, 0, drawW, drawH, UnitPixel, &imgAttr); canvas.EndGdiplusContext(); } else if (m_DrawMode == DRAWMODE_KEEPRATIO || m_DrawMode == DRAWMODE_KEEPRATIOANDCROP) { int cropX = 0; int cropY = 0; int cropW = imageW; int cropH = imageH; if (m_WDefined && m_HDefined) { REAL imageRatio = imageW / (REAL)imageH; REAL meterRatio = m_W / (REAL)m_H; if (imageRatio != meterRatio) { if (m_DrawMode == DRAWMODE_KEEPRATIO) { if (imageRatio > meterRatio) { drawH = m_W * imageH / imageW; y += (m_H - drawH) / 2; } else { drawW = m_H * imageW / imageH; x += (m_W - drawW) / 2; } } else { if (imageRatio > meterRatio) { cropW = (int)(imageH * meterRatio); cropX = (imageW - cropW) / 2; } else { cropH = (int)(imageW / meterRatio); cropY = (imageH - cropH) / 2; } } } } Rect r(x, y, drawW, drawH); canvas.DrawBitmap(drawBitmap, r, Rect(cropX, cropY, cropW, cropH)); } else { const RECT& m = m_ScaleMargins; if (m.top > 0) { if (m.left > 0) { // Top-Left Rect r(x, y, m.left, m.top); canvas.DrawBitmap(drawBitmap, r, Rect(0, 0, m.left, m.top)); } // Top Rect r(x + m.left, y, drawW - m.left - m.right, m.top); canvas.DrawBitmap(drawBitmap, r, Rect(m.left, 0, imageW - m.left - m.right, m.top)); if (m.right > 0) { // Top-Right Rect r(x + drawW - m.right, y, m.right, m.top); canvas.DrawBitmap(drawBitmap, r, Rect(imageW - m.right, 0, m.right, m.top)); } } if (m.left > 0) { // Left Rect r(x, y + m.top, m.left, drawH - m.top - m.bottom); canvas.DrawBitmap(drawBitmap, r, Rect(0, m.top, m.left, imageH - m.top - m.bottom)); } // Center Rect r(x + m.left, y + m.top, drawW - m.left - m.right, drawH - m.top - m.bottom); canvas.DrawBitmap(drawBitmap, r, Rect(m.left, m.top, imageW - m.left - m.right, imageH - m.top - m.bottom)); if (m.right > 0) { // Right Rect r(x + drawW - m.right, y + m.top, m.right, drawH - m.top - m.bottom); canvas.DrawBitmap(drawBitmap, r, Rect(imageW - m.right, m.top, m.right, imageH - m.top - m.bottom)); } if (m.bottom > 0) { if (m.left > 0) { // Bottom-Left Rect r(x, y + drawH - m.bottom, m.left, m.bottom); canvas.DrawBitmap(drawBitmap, r, Rect(0, imageH - m.bottom, m.left, m.bottom)); } // Bottom Rect r(x + m.left, y + drawH - m.bottom, drawW - m.left - m.right, m.bottom); canvas.DrawBitmap(drawBitmap, r, Rect(m.left, imageH - m.bottom, imageW - m.left - m.right, m.bottom)); if (m.right > 0) { // Bottom-Right Rect r(x + drawW - m.right, y + drawH - m.bottom, m.right, m.bottom); canvas.DrawBitmap(drawBitmap, r, Rect(imageW - m.right, imageH - m.bottom, m.right, m.bottom)); } } } } return true; }