Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am able to show image using Draw Image() but on all Microsoft sites they have resize rectangle.Because of this i am able to show only upper part of image. I want to show full image without changing its height or width.This is all i tried but not working.Only upper part of image getting showed:
picture = Image::From File("image 9.jpeg");

e->Graphics->Draw Image(picture,0,0); //showing only upper part of image

I tried even this:
e->Graphics->Draw Image( new Image, x, y, width, height );

I also tried using drawing rectagle:
R d = R(100,25,450,150);
R s = R(30,30,150,150);*/
Graphics `enter code here`Unit units = Graphics Unit::Pixel;
e->Graphics->DrawImage(picture, d, s, units);

But i want to show full image and not only upper part of image?

What I have tried:

I tried even this:
e->Graphics->Draw Image( new Image, x, y, width, height );

I also tried using drawing rectagle:
R d = R(100,25,450,150);
R s = R(30,30,150,150);*/
Graphics `enter code here`Unit units = Graphics Unit::Pixel;
e->Graphics->DrawImage(picture, d, s, units);

I am calling this from my toolTip Draw_event handler using which i want to set image background to my toolTip control on button.
But i want to show full image and not only upper part of image?
Posted
Updated 17-Jan-17 4:09am
v2

This is not possible if your screen (or window) is not large enough to show the complete image in its original size.

You can resize the image the image to fit in the available area or use a scrollable view where the user can move the visible part of the image.

For resizing get the width and height of the viewable area and use the one with the larger difference to the image size. Then scale the other dimension by the same factor. This ensures that the image is scaled by the same factor in both dimensions (scaled image not compressed in one dimension).

[EDIT]
I forgot another option:
When loading the image from file, edit and resize it to the required size using an image editor application.
[/EDIT]
 
Share this answer
 
v2
Comments
SuchitraAB 17-Jan-17 3:09am    
Ok.But i am doing all above for my toolTip control.I am showing Image as a background for my toolTip on my buttons descibing it by way of image(which is created by Graphics).
Jochen Arndt 17-Jan-17 3:20am    
See my updated answer: Provide an image that already has the required dimensons.

One more tip:
If you are going to load GUI elements like backgrounds from image files you should not use JPEG images. Use BMP or PNG instead.
Most common scenario is that you resize the image after loading to fit into your drawing area. Scale both axes with the smallest factor to pin the aspect ratio. The other most used scenario is that, you use a control which is scrollable and shows only parts.

Tip: add a button (or double clicke event) to show the picture in full size in a new windows.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900