Click here to Skip to main content
15,888,092 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: free memory when constructor throw exception Pin
rxantos19-Jan-17 19:05
rxantos19-Jan-17 19:05 
AnswerRe: free memory when constructor throw exception Pin
«_Superman_»19-Jan-17 19:32
professional«_Superman_»19-Jan-17 19:32 
AnswerRe: free memory when constructor throw exception Pin
Albert Holguin20-Jan-17 10:14
professionalAlbert Holguin20-Jan-17 10:14 
QuestionSend data to POS Printer by USB Pin
Member 1286002219-Jan-17 16:10
Member 1286002219-Jan-17 16:10 
AnswerRe: Send data to POS Printer by USB Pin
«_Superman_»19-Jan-17 19:48
professional«_Superman_»19-Jan-17 19:48 
SuggestionRe: Send data to POS Printer by USB Pin
David Crow20-Jan-17 3:15
David Crow20-Jan-17 3:15 
QuestionLight weight solution for distrubted memory map Pin
Member 380393118-Jan-17 16:12
Member 380393118-Jan-17 16:12 
QuestionGdiplus: DrawImage not working Pin
Member 162132314-Jan-17 3:28
Member 162132314-Jan-17 3:28 
Hi all,

I need some help from you: I try to render an SVG image on the screen (with alpha channel). The problem is, when I try to draw the image on the screen, I see absolutely nothing.
First of all, my SVG image is loaded correctly, and the ATL CImage from the below code, contains a correct image. The problem start when I try to use Gdiplus + alpha channel.
For instance, if I use PixelFormat24bppRGB instead of PixelFormat32bppARGB, the image is drawn correctly, but alpha channel is not preserved - a black halo is shown around my image.
Do you see any problem in my code?

PS: I use Win7, 32 bit + Visual Studio 2013 Ultimate.

Many thanks!

C++
void CAppView::OnDraw(CDC* pDC)
{

	int width = 600, height = 600;

	GError* pError = NULL;

	rsvg_init();
	g_my_svg = rsvg_handle_new_from_file("d:\\myImage.svg", &pError);
	rsvg_handle_get_dimensions(g_my_svg, &g_dimension);


	cairo_surface_t *surface = cairo_win32_surface_create_with_dib(CAIRO_FORMAT_ARGB32, width, height);
	cairo_t* cr = cairo_create(surface);

	rsvg_handle_render_cairo(g_my_svg, cr);

	HDC srcHDC = cairo_win32_surface_get_dc(surface);

	// Create ATL CImage, then, copy the content of srcHDC in the CImage HDC
	CImage image;
	image.Create(width, height, 32);

	HDC imageHDC = image.GetDC();

	TransparentBlt(imageHDC, 0, 0, width, height, srcHDC, 0, 0, width, height, RGB(0, 0, 0));


	// Initialize Gdiplus
	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

// Problems starts from this point.

	// Create a Gdiplus bitmap, and copy the content of CImage in bitmap, then write the bitmap on the screen.
	Gdiplus::Bitmap bmp(image.GetWidth(), image.GetHeight(), image.GetPitch(), PixelFormat32bppARGB, static_cast<BYTE*>(image.GetBits()));
	Gdiplus::Graphics graphics(pDC->GetSafeHdc());
	graphics.DrawImage(&bmp, Gdiplus::Rect(0, 0, width, height));



	Gdiplus::GdiplusShutdown(gdiplusToken);
	image.ReleaseDC();
	image.Destroy();
	cairo_surface_flush(surface);
	cairo_destroy(cr);
	cairo_surface_destroy(surface);
}

AnswerRe: Gdiplus: DrawImage not working Pin
leon de boer14-Jan-17 23:45
leon de boer14-Jan-17 23:45 
GeneralRe: Gdiplus: DrawImage not working Pin
Member 162132325-Jan-17 10:57
Member 162132325-Jan-17 10:57 
Questionwhat?where? Pin
Member 1294982214-Jan-17 1:54
Member 1294982214-Jan-17 1:54 
AnswerRe: what?where? Pin
Afzaal Ahmad Zeeshan14-Jan-17 2:59
professionalAfzaal Ahmad Zeeshan14-Jan-17 2:59 
AnswerRe: what?where? Pin
Patrice T14-Jan-17 16:03
mvePatrice T14-Jan-17 16:03 
AnswerRe: what?where? Pin
jeron116-Jan-17 5:15
jeron116-Jan-17 5:15 
GeneralRe: what?where? Pin
Daniel Pfeffer16-Jan-17 5:22
professionalDaniel Pfeffer16-Jan-17 5:22 
GeneralRe: what?where? Pin
NotPolitcallyCorrect16-Jan-17 9:20
NotPolitcallyCorrect16-Jan-17 9:20 
QuestionDisable a Tab on CPropertySheet Pin
Member 1294722612-Jan-17 4:58
Member 1294722612-Jan-17 4:58 
AnswerRe: Disable a Tab on CPropertySheet Pin
David Crow12-Jan-17 5:19
David Crow12-Jan-17 5:19 
GeneralRe: Disable a Tab on CPropertySheet Pin
Member 129472265-Feb-17 20:45
Member 129472265-Feb-17 20:45 
GeneralRe: Disable a Tab on CPropertySheet Pin
David Crow6-Feb-17 2:37
David Crow6-Feb-17 2:37 
QuestionVS2008 Debugger and CStrings - inconistent display Pin
charlieg9-Jan-17 9:17
charlieg9-Jan-17 9:17 
QuestionRe: VS2008 Debugger and CStrings - inconistent display Pin
David Crow9-Jan-17 10:19
David Crow9-Jan-17 10:19 
AnswerRe: VS2008 Debugger and CStrings - inconistent display Pin
charlieg9-Jan-17 10:47
charlieg9-Jan-17 10:47 
QuestionMultithreading question Pin
ForNow7-Jan-17 16:36
ForNow7-Jan-17 16:36 
AnswerRe: Multithreading question Pin
Daniel Pfeffer7-Jan-17 19:02
professionalDaniel Pfeffer7-Jan-17 19:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.