Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] How to programmatically change Picture size

Anonymous
Not applicable
Hi

My goal is to change Picture sizes in my C++ code.
Here is my code
IO::Location locationToPic ("d:\\Pictures\\67-hero.jpg"); 
const void* dgPicture = GX::Image (locationToPic).ToDGPicture (); 
DGSetItemImage (IID_SETTINGS, 400, DG::Picture (dgPicture));  
After above code I want to change width and height of picture.
2 REPLIES 2

Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

I wrote you an example code to show how to resize the image or the Picture dialog item:
//---------------------------------------------------------------------------- 
IO::Location locationToPic ("d:\\Pictures\\67-hero.jpg"); 
GX::Image myGXImage (locationToPic); 
 
	// resize the picture 
NewDisplay::NativeImage	tmpNativeImage = ResizeNativeImage (myGXImage.ToNativeImage (), 64 /* new width */); 
myGXImage = GX::Image (tmpNativeImage); 
 
	// get the size of the resized picture 
UInt32 picWidth = myGXImage.GetWidth (); 
UInt32 picHeight = myGXImage.GetHeight (); 
 
	// get actual size of the dialog item 
short left, top, right, bottom; 
DGGetItemRect (IID_SETTINGS, 400, &left, &top, &right, &bottom); 
 
	// change dialog item size to equal the picture size 
short hGrow = (right - left) - picWidth; 
short vGrow = (bottom - top) - picHeight; 
DGGrowItem (IID_SETTINGS, 400, hGrow, vGrow); 
 
	// set the picture 
const void* dgPicture = myGXImage.ToDGPicture ();  
DGSetItemImage (IID_SETTINGS, 400, DG::Picture (dgPicture)); 
//---------------------------------------------------------------------------- 
 
//---------------------------------------------------------------------------- 
// Helper function to resize image 
//---------------------------------------------------------------------------- 
 
NewDisplay::NativeImage ResizeNativeImage (const NewDisplay::NativeImage& image, Int32 newWidth) 
{ 
	if (image == NULL) 
		return image; 
 
	float scale = newWidth / image.GetWidth (); 
	Int32 newHeight = image.GetHeight () * scale; 
 
	NewDisplay::NativeImage retVal (newWidth, newHeight, image); 
	NewDisplay::NativeContext context = retVal.GetContext (); 
	context.DrawImage (image, scale, scale, 0.0, 0.0, 0.0, false); 
	retVal.ReleaseContext (context); 
 
	return retVal; 
} 
//----------------------------------------------------------------------------


Hope it helps

Regards,
Tibor

Anonymous
Not applicable
Thank you for the answer!
This is what I needed!

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!