Exemplo n.º 1
0
bool ScreenCapture::Capture(HWND hWnd, Bitmap** bitmapRet)
{
    HDC desktop_dc = GetDC(nullptr);
    RECT rc = {0};
    GetWindowRect(hWnd, &rc);
    Bitmap* bitmap = new Bitmap(rc.right -rc.left, rc.bottom - rc.top);
    RECT window_rect = { };
    GetWindowRect(hWnd, &window_rect);
    bool success = false;
    do
    {
        Graphics graphic(bitmap); 
        HDC graphic_hdc = graphic.GetHDC();
        success = !!BitBlt(
            graphic_hdc, 0, 0, 
            rc.right -rc.left, rc.bottom - rc.top, 
            desktop_dc, 0, 0, SRCCOPY);
        graphic.ReleaseHDC(graphic_hdc);
    } while (false);
    ReleaseDC(nullptr, desktop_dc);
    *bitmapRet = bitmap->Clone(window_rect.left, window_rect.top, 
        window_rect.right - window_rect.left, 
        window_rect.bottom - window_rect.top, PixelFormat32bppARGB);
    delete bitmap;
    return success;
}
Exemplo n.º 2
0
void CBMPDoc::copyFrom(const CBMPDoc* bmpDoc)
{
	Bitmap *src = bmpDoc->m_bitmap;
	this->m_bitmap = src->Clone(0, 0, src->GetWidth(), src->GetHeight(), PixelFormat8bppIndexed);

	CString newTitle("copied_");
	newTitle.Append(bmpDoc->GetTitle());
	this->SetTitle(newTitle);
}
Exemplo n.º 3
0
void IrisBitmap::FillRect(int x, int y, int width, int height, const IrisColor *color){
	this->needRefreshTexture = true;
	Bitmap* tbitmap = this->bitmap->Clone(0, 0, this->width, this->height, PixelFormat32bppARGB);
	SolidBrush *tpBrush = new SolidBrush(Color(color->alpha, color->red, color->green, color->blue));
	
	delete this->bitmap;
	Graphics g(tbitmap);
	g.FillRectangle(tpBrush, x, y, width, height);

	this->bitmap = tbitmap->Clone(0, 0, tbitmap->GetWidth(), tbitmap->GetHeight(), PixelFormat32bppARGB);

	delete tbitmap;
	delete tpBrush;
}
Exemplo n.º 4
0
ImageEngine *ImageEngineImpl::Clone()
{
    Bitmap *bmp = pages.At(0);
    bmp = bmp->Clone(0, 0, bmp->GetWidth(), bmp->GetHeight(), PixelFormat32bppARGB);
    if (!bmp)
        return NULL;

    ImageEngineImpl *clone = new ImageEngineImpl();
    clone->fileName = str::Dup(fileName);
    clone->fileExt = fileExt;
    if (fileStream)
        fileStream->Clone(&clone->fileStream);
    clone->FinishLoading(bmp);

    return clone;
}
Exemplo n.º 5
0
void IrisBitmap::Clear(){
	this->needRefreshTexture = true;
	//graphics->Clear(Color(100, 100, 100));

	Bitmap* tp = this->bitmap->Clone(0, 0, this->width, this->height, PixelFormat32bppARGB);
	Graphics* tg = new Graphics(tp);

	delete this->bitmap;

	tg->Clear(Color(0, 0, 0, 0));
	
	this->bitmap = tp->Clone(0, 0, tp->GetWidth(), tp->GetHeight(), PixelFormat32bppARGB);

	delete tp;
	delete tg;

}
Exemplo n.º 6
0
vector<Bitmap*> CExampleDemoDlg::LoadTemplateImg(string filesrc)
{
	vector<Bitmap*> tempplate;
	vector<string>filepathname;
	ScanDirectory(filesrc, ".jpg", filepathname);//filesrc是文件夹名字
	//std::sort(filepathname.begin(),filepathname.end());
	for (int i = 0; i < filepathname.size(); i++)
	{
		string image = filesrc+"\\"+ filepathname[i];
		std::wstring widestr = std::wstring(image.begin(), image.end());
		Bitmap* pInImage = Bitmap::FromFile(widestr.c_str());
		if (pInImage->GetLastStatus() == -1)
		{
			SAFE_DELETE(pInImage);
			continue;
		}

		Bitmap*  img = pInImage->Clone(0, 0, pInImage->GetWidth(), pInImage->GetHeight(), PixelFormat32bppARGB);
		tempplate.push_back(img);
	}
	return tempplate;
}
Exemplo n.º 7
0
void CQTTDemoView::OnDraw(CDC* pDC)
{
	{
		/*
		CDC *mdc = new CDC;
		//De lam cai gi vay troi?
		mdc->CreateCompatibleDC(pDC);
		CBitmap* m_bitmap = new CBitmap();
		//Ham de load cai file den cai bitmap // Win32 API
		m_bitmap->m_hObject=(HBITMAP)::LoadImage(
			NULL,
			"tamtit.bmp",
			IMAGE_BITMAP,
			520,
			758,
			LR_LOADFROMFILE);
		//Phai select object thi no moi ve dc.
		mdc->SelectObject(m_bitmap);
		CRect rect;
		//Lay client Rect
		GetClientRect(&rect);
		//BitBlt() // Khong hieu
		//pDC->BitBlt(100,100,400,500,mdc,0,0,SRCCOPY);
		float radians = 3.1416f*0/180;
		float minx = 0;
		float miny = 0;
		float cosine = (float)cos(radians);
		float sine = (float)sin(radians);
		XFORM xform;
		xform.eM11 = cosine;
		xform.eM12 = -sine;
		xform.eM21 = sine;
		xform.eM22 = cosine;
		xform.eDx = (float)-minx;
		xform.eDy = (float)-miny;
		pDC->BitBlt(0,0,400,500,mdc,100,100,SRCCOPY);		
		SetGraphicsMode(pDC->m_hDC, GM_ADVANCED);
		SetWorldTransform(pDC->GetSafeHdc(),&xform);
		pDC->TransparentBlt(100,100,400,500,mdc,0,0,400,500,RGB(144,3,225));
		mdc->DeleteDC();		
		CBrush brush;
		brush.CreatePatternBrush(m_bitmap);
		*/
		// Block for Graphics
		Bitmap* originalBitmap = new Bitmap(L"gameloft_logo.png");
		Graphics g(pDC->GetSafeHdc());
		g.SetSmoothingMode(SmoothingModeHighQuality);
		g.SetInterpolationMode(InterpolationModeHighQualityBicubic);
		g.SetPixelOffsetMode(PixelOffsetModeHighQuality);
		
		for (int i = 0; i < PATH_COUNT; i++)
		{
			//g.RotateTransform(45);
			
			if( i == PATH_IMAGE)
			{
				REAL left		= 34;
				REAL top		= 59;
				REAL width		= 106;
				REAL height		= 76;
				RectF sourceRect(
					left,
					top, 
					width, 
					height
				);
				RectF sourceBound;
				m_Paths[i].GetBounds(&sourceBound);				
				Bitmap* secondBitmap = originalBitmap->Clone(sourceRect, PixelFormatDontCare);
				m_Matrixs[i];
				g.SetTransform(m_Matrixs[i]);
				g.DrawImage(secondBitmap,0,0);
				Matrix* m = m_Matrixs[i]->Clone();
				m->Reset();
				g.SetTransform(m);
				g.DrawPath(m_pPens[i], & m_Paths[i]);
				delete m;				
			}
			else{
				g.FillPath(m_pBrushes[i], & m_Paths[i]);
				g.DrawPath(m_pPens[i], & m_Paths[i]);
			}
			
			//g.GetTransform()
		}
	}
	//Dung de paint may cai nut de co the xoay, resize v.v...
	m_Tracker.Draw(pDC);
}
Exemplo n.º 8
0
HBITMAP renderer::GetThumbnail()
{
    //Calculate icon size
    int iconsize = height;

    if (m_Settings.AsIcon)
    {
        if (width < iconsize)
            iconsize = width;        
        iconsize = (m_Settings.IconSize * iconsize) / 100;
        iconsize -= 2;
    }

    //Calculate Alpha blend based on Transparency
    float fBlend = (100-m_Settings.BG_Transparency)/100.0;

    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
    };

    bool tempfail = fail;
    int iconposition = m_Settings.IconPosition;

    // Draw background if not valid
    if (!background)
    {      
        if (m_Settings.Shrinkframe)
        {
            if (iconposition == IP_LOWERLEFT)
            {
                iconposition = IP_UPPERLEFT;
            }
            else if (m_Settings.IconPosition == IP_LOWERRIGHT)
            {
                iconposition = IP_UPPERRIGHT;
            }
        }

        no_icon = false;                
        fail = false;
        background = new Bitmap(width, height, PixelFormat32bppPARGB);

        switch (tempfail ? m_Settings.Revertto : m_Settings.Thumbnailbackground)
        {
        case BG_TRANSPARENT:
            no_icon = true;
            break;

        case BG_ALBUMART:
            {
                // get album art
                if (!m_albumart.getAA(m_metadata.getFileName(), background, 
                    width, height, iconsize) &&
                    m_Settings.Revertto != BG_ALBUMART)
                {
                    // fallback
                    fail = true;
                    ClearBackground();                            
                    GetThumbnail();
                }
                else
                {
                    m_iconwidth = iconsize;
                    m_iconheight = iconsize;
                }
            }
            break;

        case BG_CUSTOM:
            if (!m_Settings.BGPath.empty())
            {
                if (custom_img == NULL)
                {
                    custom_img = new Bitmap(width, height, PixelFormat32bppPARGB);                       

                    Image img(m_Settings.BGPath.c_str(), true);

                    if (img.GetType() != 0)
                    {
                        Graphics gfx(custom_img);
                        gfx.SetInterpolationMode(InterpolationModeBicubic);
                        float img_width = img.GetWidth();
                        float img_height = img.GetHeight();

                        if (m_Settings.AsIcon)
                        {
                            float new_height = 0;
                            float new_width = 0;

                            if (img_width > img_height)
                            {
                                new_height = img_height / img_width * (float)iconsize;
                                new_height -= 2;
                                new_width = iconsize;
                            }
                            else
                            {
                                new_width = img_width / img_height * (float)iconsize;
                                new_width -= 2;
                                new_height = iconsize;
                            }

                            int iconleft = 0, icontop = 0;

                            switch (iconposition)
                            {
                            case IP_LOWERLEFT:
                                icontop = height - iconsize - 2;
                                break;
                            case IP_UPPERRIGHT:
                                iconleft = width - iconsize - 2;
                                break;
                            case IP_LOWERRIGHT:
                                iconleft = width - iconsize - 2;
                                icontop = height - iconsize - 2;
                                break;
                            }            

                            if (m_Settings.BG_Transparency == 0)
                            {
                                // Draw icon shadow
                                gfx.SetSmoothingMode(SmoothingModeAntiAlias);
                                gfx.FillRectangle(&SolidBrush(Color::MakeARGB(110, 0, 0, 0)),
                                    static_cast<REAL>(iconleft + 1), static_cast<REAL>(icontop + 1), 
                                    static_cast<REAL>(new_width + 1), static_cast<REAL>(new_height + 1));

                                // Draw icon
                                gfx.SetSmoothingMode(SmoothingModeNone);
                                gfx.DrawImage(&img,
                                    RectF(static_cast<REAL>(iconleft), static_cast<REAL>(icontop), 
                                    static_cast<REAL>(new_width), static_cast<REAL>(new_height)));
                            }
                            else
                            {
                                ImageAttributes ImgAttr;
                                ImgAttr.SetColorMatrix(&BitmapMatrix, 
                                    ColorMatrixFlagsDefault, 
                                    ColorAdjustTypeBitmap);

                                // Draw icon shadow
                                gfx.SetSmoothingMode(SmoothingModeAntiAlias);
                                gfx.FillRectangle(&SolidBrush(Color::MakeARGB(110 - m_Settings.BG_Transparency, 0, 0, 0)),
                                    static_cast<REAL>(iconleft + 1), static_cast<REAL>(icontop + 1), 
                                    static_cast<REAL>(new_width + 1), static_cast<REAL>(new_height + 1));

                                // Draw icon
                                gfx.SetSmoothingMode(SmoothingModeNone);
                                gfx.DrawImage(&img,
                                    RectF(static_cast<REAL>(iconleft), static_cast<REAL>(icontop), 
                                    static_cast<REAL>(new_width), static_cast<REAL>(new_height)),
                                    0, 0, img_width, img_height,
                                    UnitPixel, &ImgAttr);
                            }

                            m_iconwidth = new_width;
                            m_iconheight = new_height;
                        }
                        else
                        {
                            float new_height = 0;
                            float new_width = 0;

                            if (width > height)
                            {
                                new_height = img_height / img_width * (float)width;                            
                                new_width = width;

                                if (new_height > height)
                                {
                                    new_width = img_width / img_height * (float)height;                         
                                    new_height = height;
                                }

                            }
                            else
                            {
                                new_width = img_width / img_height * (float)height;                         
                                new_height = height;

                                if (new_width > width)
                                {
                                    new_height = img_height / img_width * (float)width;                            
                                    new_width = width;
                                }
                            }

                            gfx.SetSmoothingMode(SmoothingModeNone);

                            if (m_Settings.BG_Transparency == 0)
                            {
                                gfx.DrawImage(&img, RectF((width / 2) - (new_width/2), 0, 
                                    static_cast<REAL>(new_width), static_cast<REAL>(new_height)));
                            }
                            else
                            {
                                ImageAttributes ImgAttr;
                                ImgAttr.SetColorMatrix(&BitmapMatrix, 
                                    ColorMatrixFlagsDefault, 
                                    ColorAdjustTypeBitmap);

                                gfx.SetSmoothingMode(SmoothingModeNone);
                                gfx.DrawImage(&img, RectF((width / 2) - (new_width/2), 0, static_cast<REAL>(new_width), static_cast<REAL>(new_height)),
                                    0, 0, img_width, img_height,
                                    UnitPixel, &ImgAttr);
                            }
                        }
                    }
                    else if (m_Settings.Revertto != BG_CUSTOM)
                    {
                        fail = true;
                        ClearBackground();
                        GetThumbnail();
                    }	                   
                }       

                delete background;
                background = (Bitmap*)custom_img->Clone();                
            }
            else if (m_Settings.Revertto != BG_CUSTOM)
            {		
                fail = true;
                ClearBackground();
                GetThumbnail();
            }
            break;	

        default:
            {
                fail = true;
                ClearBackground();
                GetThumbnail();                
            }
            break;
        }
    }

    if (tempfail)
    {
        return NULL;
    }

    REAL textheight = 0;
    Bitmap *canvas = background->Clone(0, 0, background->GetWidth(), background->GetHeight(), PixelFormat32bppPARGB);
    Graphics gfx(canvas);

    if (m_Settings.Text.empty())
    {
        Pen p(Color::MakeARGB(1, 255, 255, 255), 0.1);
        gfx.DrawLine(&p, 0, 0, 1, 1);
        textheight = m_iconheight + 10; 
    }
    else
    {
        // Draw text
        static lines text_parser(m_Settings, m_metadata, m_hwnd);
        text_parser.Parse();

        if (m_textpositions.empty())
        {
            m_textpositions.resize(text_parser.GetNumberOfLines(), 0);
        }
        else
        {
            for (std::vector<int>::size_type i = 0; i != m_textpositions.size(); ++i)
            {
                if (m_textpositions[i] != 0)
                {
                    m_textpositions[i] -= 2;
                }
                else
                {
                    if (scroll_block)
                    {
                        bool unblock = true;

                        for (std::vector<int>::size_type j = 0; j != m_textpositions.size(); ++j)
                        {
                            if (m_textpositions[j] < 0)
                            {
                                unblock = false;
                                break;
                            }                                
                        }

                        scroll_block = !unblock;
                        m_textpause = 60;
                    }

                    if (!scroll_block && m_textpause == 0)
                    {
                        m_textpositions[i] -= 2;
                    }
                }
            }
        }

        // Setup fonts	    
        HDC h_gfx = gfx.GetHDC();	    
        Font font(h_gfx, &m_Settings.font);

        LOGFONT large_font = {};
        large_font = m_Settings.font;	    

        LONG large_size = -((m_Settings.font.lfHeight * 72) / GetDeviceCaps(h_gfx, LOGPIXELSY));
        large_size += 4;
        large_font.lfHeight = -MulDiv(large_size, GetDeviceCaps(h_gfx, LOGPIXELSY), 72);
        Font largefont(h_gfx, &large_font);

        gfx.ReleaseHDC(h_gfx);

        SolidBrush bgcolor(Color(GetRValue(m_Settings.bgcolor), GetGValue(m_Settings.bgcolor), GetBValue(m_Settings.bgcolor)));
        SolidBrush fgcolor(Color(GetRValue(m_Settings.text_color), GetGValue(m_Settings.text_color), GetBValue(m_Settings.text_color)));

        StringFormat sf(StringFormatFlagsNoWrap);
        const int text_space = 28;

        for (std::size_t text_index = 0; text_index != text_parser.GetNumberOfLines(); ++text_index)
        {
            RectF ret_rect;
            std::wstring current_text = text_parser.GetLineText(text_index);
            linesettings current_settings = text_parser.GetLineSettings(text_index);

            // Measure size
            gfx.SetTextRenderingHint(TextRenderingHintAntiAlias);
            if (current_settings.largefont)
                gfx.MeasureString(current_text.c_str(), -1, &largefont, RectF(0, 0, 2000, 1000), &sf, &ret_rect);
            else
                gfx.MeasureString(current_text.c_str(), -1, &font, RectF(0, 0, 2000, 1000), &sf, &ret_rect);

            if (ret_rect.GetBottom() == 0)
            {
                if (current_text.empty())
                {
                    gfx.MeasureString(L"QWEXCyjM", -1, &font, RectF(0, 0, static_cast<REAL>(width), static_cast<REAL>(height)), &sf, &ret_rect);			
                }
                else
                {
                    gfx.MeasureString(L"QWEXCyjM", -1, &Font(L"Segoe UI", 14), RectF(0, 0, static_cast<REAL>(width), static_cast<REAL>(height)), &sf, &ret_rect);			
                }
            }

            Bitmap text_bitmap(ret_rect.GetRight(), ret_rect.GetBottom() - 1, PixelFormat32bppPARGB);
            Graphics text_gfx(&text_bitmap);

            // Graphics setup
            text_gfx.SetSmoothingMode(SmoothingModeNone);
            text_gfx.SetInterpolationMode(InterpolationModeNearestNeighbor);
            text_gfx.SetPixelOffsetMode(PixelOffsetModeNone);
            text_gfx.SetCompositingQuality(CompositingQualityHighSpeed);

            (m_Settings.Antialias) ? text_gfx.SetTextRenderingHint(TextRenderingHintAntiAlias) : 
                text_gfx.SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit);

            // Draw box if needed
            if (current_settings.darkbox && !current_text.empty())
            {
                SolidBrush boxbrush(Color::MakeARGB(120, GetRValue(m_Settings.bgcolor),
                    GetGValue(m_Settings.bgcolor), GetBValue(m_Settings.bgcolor)));

                ret_rect.Height += 2;
                text_gfx.FillRectangle(&boxbrush, ret_rect);
            }

            text_gfx.SetTextContrast(120);

            // Draw text to offscreen surface

            //shadow
            if (current_settings.shadow)
            {
                text_gfx.DrawString(current_text.c_str(), -1, 
                    current_settings.largefont ? &largefont : &font, 
                    PointF(1, -1), &bgcolor);
            }

            //text
            text_gfx.DrawString(current_text.c_str(), -1, 
                current_settings.largefont ? &largefont : &font, 
                PointF(0, -2), &fgcolor);

            // Calculate text position
            int X = 0, CX = width;

            if (m_iconwidth == 0)
            {
                m_iconwidth = iconsize;
            }

            if (m_iconheight == 0)
            {
                m_iconheight = iconsize;
            }

            if (m_Settings.AsIcon && !no_icon && !current_settings.forceleft)
            {
                if ( (iconposition == IP_UPPERLEFT || 
                    iconposition == IP_LOWERLEFT) &&
                    !current_settings.forceleft )
                {
                    X += m_iconwidth + 5;
                    CX = width - X;
                }
                else if ( iconposition == IP_UPPERRIGHT || 
                    iconposition == IP_LOWERRIGHT )
                {
                    CX = width - m_iconwidth - 5;
                }
            }

            gfx.SetClip(RectF(X, 0, CX, width), CombineModeReplace);

            // Draw text bitmap to final bitmap
            if (text_bitmap.GetWidth() > CX + 2 && !current_settings.dontscroll)// && m_textpause[text_index] == 0)
            {
                // Draw scrolling text
                int left = m_textpositions[text_index];
                int bmp_width = (int)text_bitmap.GetWidth();
                int bmp_height = (int)text_bitmap.GetHeight();

                if (left + bmp_width < 0)
                {
                    // reset text
                    m_textpositions[text_index] = text_space;
                    left = text_space;
                    scroll_block = true;
                }

                if (left == 0 && m_textpause == 0)
                {
                    m_textpause = 60; // delay; in steps
                }

                if (left + bmp_width >= CX)
                {
                    gfx.DrawImage(&text_bitmap, X, (int)textheight, -left, 0, CX, bmp_height, UnitPixel);
                }
                else
                {
                    gfx.DrawImage(&text_bitmap, X, (int)textheight, -left, 0, bmp_width + left,
                        bmp_height, UnitPixel);

                    gfx.DrawImage(&text_bitmap, X + text_space + 2 + bmp_width + left, (int)textheight, 0, 0,
                        -left, bmp_height, UnitPixel);
                }
            }
            else
            {
                // Draw non-scrolling text
                if (current_settings.center)
                {
                    // Center text
                    int newleft = X + ((CX / 2) - (text_bitmap.GetWidth() / 2));
                    gfx.DrawImage(&text_bitmap, newleft, (int)textheight, 0, 0, text_bitmap.GetWidth(), text_bitmap.GetHeight(), UnitPixel);          
                }
                else
                {
                    gfx.DrawImage(&text_bitmap, X, (int)textheight, 0, 0, text_bitmap.GetWidth(), text_bitmap.GetHeight(), UnitPixel);          
                }

                m_textpositions[text_index] = 2; // Nr. pixels text jumps on each step when scrolling
            }

            gfx.ResetClip();

            textheight += text_bitmap.GetHeight();
        }

        if (m_textpause > 0)
        {
            --m_textpause;
        }

        if (!m_Settings.Shrinkframe)	
            textheight = height-2;

        if (m_Settings.Thumbnailpb)
            textheight += 25;

        if (textheight > height-2)
            textheight = height-2;
    }

    // Draw progressbar
    if (m_Settings.Thumbnailpb && m_Settings.play_total > 0)// && m_Settings.play_current >0)
    {
        gfx.SetSmoothingMode(SmoothingModeAntiAlias);		
        int Y = canvas->GetHeight()-10;
        if (m_Settings.Shrinkframe)
        {
            Y = textheight - 10;
        }
        Pen p1(Color::White, 1);
        Pen p2(Color::MakeARGB(80, 0, 0, 0), 1);

        SolidBrush b1(Color::MakeARGB(50, 0, 0, 0));	
        SolidBrush b2(Color::MakeARGB(220, 255, 255, 255));

        RectF R1(44, (REAL)Y, 10, 9);
        RectF R2((REAL)width - 56, (REAL)Y, 10, 9);

        gfx.FillRectangle(&b1, 46, Y, width-94, 9);
        gfx.DrawLine(&p2, 46, Y+2, 46, Y+6);
        gfx.DrawLine(&p2, width-48, Y+2, width-48, Y+6);

        gfx.DrawArc(&p1, R1, -90.0f, -180.0f);
        gfx.DrawArc(&p1, R2, 90.0f, -180.0f);

        gfx.DrawLine(&p1, 48, Y, width-49, Y);
        gfx.DrawLine(&p1, 48, Y+9, width-49, Y+9);

        gfx.SetSmoothingMode(SmoothingModeDefault);
        gfx.FillRectangle(&b2, 48, Y+3, (m_Settings.play_current*(width-96))/m_Settings.play_total, 4);
    }

    // finalize / garbage    
    HBITMAP retbmp;

    if (!m_Settings.Shrinkframe)
    {
        canvas->GetHBITMAP(NULL, &retbmp);        
    }
    else
    {
        Bitmap *shrink = canvas->Clone(0, 0, (int)width, 
            textheight > m_iconheight ? (int)textheight : (int)m_iconheight, PixelFormat32bppPARGB);
        shrink->GetHBITMAP(NULL, &retbmp);
        delete shrink;
    }

    delete canvas;
    return retbmp;
}
Exemplo n.º 9
0
void ToolFilter::activate()
{
	ChildCore *child = this->core->getActiveChild();
	if( child != NULL ){
		if( this->lastActivate == true && this->isLastActivate == false ){
			this->lastActivate = false;
			return;
		}

		ToolFilter::Info fi;
		Bitmap *source = NULL;
		if( child->getWorkspace()->getSelection() != NULL ){
			source = child->getWorkspace()->getSelectedProjection(NULL,COPCOP);
		}
		else {
			source = child->getWorkspace()->getSelectedLayer()->getRender();
			source = source->Clone(Rect(0,0,source->GetWidth(),source->GetHeight()),source->GetPixelFormat());
		}				

		fi.bmpSource = source;
		fi.bmpEffect = NULL;
		fi.bw = this->lastBw;
		fi.bwalpha = (this->lastAlpha &&
					  this->lastFilterId != ID_FILTER_OLDSTONE &&
					  this->lastFilterId != ID_FILTER_EDGETRACE );
		fi.smooth = true;
		fi.edgeTrace = (this->lastFilterId == ID_FILTER_EDGETRACE);

		fi.filterId = this->lastFilterId;
		fi.filterValue = this->lastFilterValue;
		fi.filterByValue = (this->lastFilterId != ID_FILTER_CUSTOM);

		fi.minVal = 0;
		switch(fi.filterId){
			case ID_FILTER_SHARPEN:
				fi.maxVal = SHARPENMAX;
				break;
			default:
				fi.maxVal = FILTERMAX;
				break;
		}

		if( fi.filterByValue == true )
			fi.matrix = ToolFilter::allocateMatrix(fi.filterId,fi.filterValue);
		else
			fi.matrix = this->lastCustomMatrix;

		int result = NO;
		if( this->lastActivate == false ){
			result = this->core->getDialogs()->showDialog(
														(LPCTSTR)IDD_FIL,
														(DLGPROC)Dialogs::processDlg_Fil,
														(LPARAM)&fi
														);
		}
		else {
			this->lastActivate = false;
			result = YES;
		}
		if( result == YES ){

			Point shift(0,0);
			Rect *bounds = NULL;

			if( child->getWorkspace()->getSelection() != NULL ){
				bounds = new Rect(0,0,0,0);
				child->getWorkspace()->getSelection()->GetBounds(bounds);

				fi.bmpSource = child->getWorkspace()->getSelectedLayer()->getRender();
			}
			else {
				int exw = (int)( floor(fi.matrix.mxw / 2.0) + 1 );
				int exh = (int)( floor(fi.matrix.mxh / 2.0) + 1 );

				shift.X = -exw;
				shift.Y = -exh;

				Bitmap *newsource = new Bitmap(
					source->GetWidth() + 2 * exw,
					source->GetHeight() + 2 * exh,
					source->GetPixelFormat());
				Graphics *g = Graphics::FromImage(newsource);
				g->DrawImage(source,exw,exh,source->GetWidth(),source->GetHeight());

				delete g;
				delete source;

				source = newsource;
				fi.bmpSource = newsource;
			}
			if( fi.filterByValue == true )
				this->lastFilterValue = fi.filterValue;
			else
				this->lastCustomMatrix = fi.matrix;
			this->lastBw = fi.bw;
			this->lastAlpha = fi.bwalpha;

			Rect newbounds = ToolFilter::applyFilter(&fi,bounds);

			if( child->getWorkspace()->getSelection() == NULL ){
				bounds = &newbounds;
				bounds->X += shift.X;
				bounds->Y += shift.Y;
			}

			child->getWorkspace()->getSelectedLayer()->applyEffect(
				fi.bmpEffect,
				bounds,
				this,
				fi.filterId);
			delete fi.bmpEffect;

			this->isLastActivate = true;

			child->getWorkspace()->updateToolws();
			child->getWorkspace()->update();
		}
		if( source != NULL )
			delete source;
	}
}