Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Copy image to Windows clipboard
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows NT
Database:
Visual FoxPro
Divers
Thread ID:
01021590
Message ID:
01024054
Vues:
22
>Hugo,
>
>I think I have finally got it. I can use the Image class from the _GDIPLUS library to read the file and get the image height and width. I can then calculate a scale factor for how the image fits into the image control. Then, I can calculate the actual location of the image inside the image control, and copy only that portion.
>
>Again, thanks for your help.
>Jim

Jim,

Sorry for the delay. I never used GDI+ so, I was not able to help you there, but my idea was similar to yours without using GDI, but using Fox.

The trick is creating an image and set its picture property to your control picture property, but with clip as stretch, this will set the new control width and height to the real width and height, then you just do some math to get the right left, top, width and height properties, something like (I am sure it can be improved):
loImageCtrl		= Createobject('Image')
with loImageCtrl
	.Stretch		= 0
	.Picture		= thisform.Image1.Picture
	lnAspect		= .width / .height
	llLandscape		= .width >= .height
endwith

loImage			= thisform.Image1   && Your image in the form, probably stretch = 2 in here, otherwise you wouldn't need anything extra :)

if llLandscape
	lnWidth			= loImage.Width
	lnLeft			= OBJTOCLIENT(loImage, 2)
	lnHeight		= lnWidth / lnAspect
	lnTop			= OBJTOCLIENT(loImage, 1) + ((loImage.Height - lnHeight) / 2)
else
	lnHeight		= loImage.Height
	lnWidth			= lnHeight / lnAspect
	lnTop			= OBJTOCLIENT(loImage, 1)
	lnLeft			= OBJTOCLIENT(loImage, 2) + ((loImage.Width - lnWidth) / 2)
endif

lnHWnd			= thisform.HWnd
lnHDC			= GetDC(lnHWnd)
lnHDC_Mem		= CreateCompatibleDC(lnHDC)
lnHBitMap		= CreateCompatibleBitmap(lnHDC, lnWidth, lnHeight)

if lnHBitMap <> 0
	lnHPrevBmp	= SelectObject(lnHDC_Mem, lnHBitMap)
	BitBlt(lnHDC_Mem, 0, 0, lnWidth, lnHeight, lnHDC, lnLeft, lnTop, SRCCOPY)
	if OpenClipboard(lnHWnd)
		EmptyClipboard()
		SetClipboardData(CF_BITMAP, lnHBitMap)
		CloseClipboard()
	else
		* Error
	endif
	SelectObject(lnHDC_Mem, lnHPrevBmp)	&& Previous object should be re-selected
else
		* Error
endif

DeleteDC(lnHDC_Mem)
ReleaseDC(lnHWnd, lnHDC)
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform