Click here to Skip to main content
14,426,490 members
Rate this:
Please Sign up or sign in to vote.
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 5:09am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

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]
   
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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100