BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

Archicad C++ API
About Archicad add-on development using the C++ API.

[SOLVED] Issue related with Picture displaying

Anonymous
Not applicable
I show an image programmatically in my Dialog picture
Problem is that picture result is a black frame

Here is my code

resource file
'GDLG'	32500	Modal   0	 0	    425   330		"Settings" {
/* [  1] */ Picture            19    12     64    64  400    ClientEdge		/* user picture */
}
'DLGH'  32500  DLG_32500_Settings {
1	""							userImage
}
C++ code
NewDisplay::NativeImage SettingsDialog::setNativeImageSize(const NewDisplay::NativeImage& image)
{
	if (image == NULL) 
		return image; 
   
	NewDisplay::NativeImage retVal (64, 64, image); 
	NewDisplay::NativeContext context = retVal.GetContext (); 

	context.DrawImage (image, 19, 12, 0.0, 0.0, 0.0, false); 

	retVal.ReleaseContext (context);

	return retVal;
}

void SettingsDialog::setDefaultImage(const char* targetPath)
{

	IO::Location locationToPic(targetPath);
	GX::Image myGXImage (locationToPic); 
 

	NewDisplay::NativeImage tmpNativeImage = this->setNativeImageSize(myGXImage.ToNativeImage());
	myGXImage = GX::Image (tmpNativeImage);

	const void* dgPicture = myGXImage.ToDGPicture ();  
	DGSetItemImage (IID_SETTINGS, IDP_USER_IMAGE, DG::Picture (dgPicture));

}
I want to display always with a static size w-64, h-64, x-19, y-12
Result always a black frame
Please look at attached picture


picture_issue.png

2 REPLIES 2
Tamas Zolnai
Graphisoft Alumni
Graphisoft Alumni
As I see the problem is that you use NativeImage::DrawImage on the wrong way. You need something similar to this:

float wScale = 64.0f / image.GetWidth();
float hScale = 64.0f / image.GetHeight();
context.DrawImage (image, wScale, hScale, 0.0, 0.0, 0.0, false);
The second and third parameters are the scaling values, which you should use to make your image fit into the drawing area.
The x=19 and y= 12 positions are not needed here, they are already specified in the resource file.
Tamás Zolnai
Graphisoft
Anonymous
Not applicable
Tamás wrote:
As I see the problem is that you use NativeImage::DrawImage on the wrong way. You need something similar to this:

float wScale = 64.0f / image.GetWidth();
float hScale = 64.0f / image.GetHeight();
context.DrawImage (image, wScale, hScale, 0.0, 0.0, 0.0, false);
The second and third parameters are the scaling values, which you should use to make your image fit into the drawing area.
The x=19 and y= 12 positions are not needed here, they are already specified in the resource file.
Thank you for the help. Now it works ))
Learn and get certified!

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!