当前位置:网站首页>VFP a picture processing library, simple and easy to use, free of charge, worth recommending

VFP a picture processing library, simple and easy to use, free of charge, worth recommending

2022-06-25 11:44:00 VFP of Garfield

Cat cat returned to his hometown in Hunan during the Spring Festival , Eat, drink and play during the Chinese New Year , No intention to work , Now let's close our hearts , Move bricks carefully , The people who carry bricks are the most lovely .
Now the picture processing library introduced by cat , From the papaya warrior , Simple and easy to use , No charge for free , Is worth to recommend
At present, the document processing system developed by cat has been used .

Brief introduction

  • MyImg.fll
  • The main function : PrintScreen 、 tailoring 、 The zoom 、 rotate 、 format conversion 、 Generate to variable 、 Copy to clipboard
  • author : Papaya :
  • Call to order :ImgOpen() --> Other functions -->ImgClose() , When something goes wrong , Use ImgGetLastError Read error

Here are the test cases

#define _FROM_SCREEN		1
#define _FROM_CLIPBORD		2

#define _IMG_BMP			1
#define _IMG_GIF			2
#define _IMG_JPG			3
#define _IMG_PNG			4
#define _IMG_TIF			5


Clear 
Set Library To myImg

* 1.  Open the image   The screen 、 clipboard 
 hImg = ImgOpen(_FROM_SCREEN)		&& Open screen 
* hImg = ImgOpen(_FROM_CLIPBORD)	&& Open the shear plate 
* hImg = ImgOpen( cFileName )		&& Open the image 
If hImg==""
	MessageBox(" Failed to open image !")
	Return 
EndIf 
ImgSave(hImg,"1 The original picture .bmp",_IMG_BMP)


* 2.  Get image size 
?" Width :",ImgGetWidth(hImg)
?" Height :",ImgGetHeight(hImg)


* 3.  tailoring  ImgCrop( Parameters : Handle , Left , On , wide , high )
If not ImgCrop(hImg,10,10,500,300) &&( from (10,10) Coordinates start , Generate a wide 500, high 300 Image  
	MessageBox(ImgGetLastError(hImg)," Clipping failed !")
EndIf 
ImgSave(hImg,"3 post-crop .bmp",1)

* 4.  The zoom  ImgZoom( Handle , New width , New height )

If not ImgZoom(hImg,400,400)  && Zoom to 400×400 Image 
	MessageBox(ImgGetLastError(hImg)," Zoom failed !")
EndIf 
ImgSave(hImg,"4 After zooming .bmp",1)

* 5. rotate  ImgRotate( Handle , angle )
If not imgRotate(hImg,90)
	MessageBox(ImgGetLastError(hImg)," Rotation failed !")
EndIf 
ImgSave(hImg,"5 After rotation .bmp",1)

* 6. format conversion 
If not ImgSave(hImg,"6 format conversion .png",_IMG_PNG)  && The second parameter is the file name , The third is the picture type 
	MessageBox(ImgGetLastError(hImg)," Format conversion failed !")
EndIf 

* 7.  If you want to turn JPG, Can be set jpg Quality  1-100
ImgSetJpegQuality(hImg,70)	&& Set up jpg Quality 
If not ImgSave(hImg,"7 format conversion .jpg",_IMG_JPG)
	MessageBox(ImgGetLastError(hImg)," Save as failed !")
EndIf 

* 8.  Copy to clip board 
If ImgCopyToClipbord(hImg) 
	MessageBox(" Copied to clipboard , You can open the drawing program and paste ")
Else
	MessageBox(ImgGetLastError(hImg)," Copy to clipboard failed !") 
EndIf 

* 9. Get the image variable directly ( It returns a variable , It can be directly stored in the database )
vImgSrc = ImgGetPtr(hImg,_IMG_GIF)  && obtain Gif Format image content 
StrToFile(vImgSrc,"9 Use memory variables .gif")

* 10. Close image 
ImgClose(hImg)

* 11. Create... From memory variables  ( vImgSrc It was generated earlier , It can also be used. FileToStr obtain 
hImg2=ImgOpen(vImgSrc,_IMG_GIF)
If hImg2==""
	MessageBox(ImgGetLastError(hImg)," Failed to open image from variable !")
	Return 
EndIf 

*  12. And Vfp9 Of PictureVal Use a combination of ,ImgGetPtr() The return value of can be directly assigned to PictureVal
If Val(_vfp.Version) >=9  
	Local oForm as Form 
	oForm=CreateObject("form")
	oForm.AddObject("image","image")
	With oForm.image as Image 
		.Visible=.t.
		.PictureVal = ImgGetPtr(hImg2,_IMG_TIF)  &&  Change the format to tif, Assign to image The control of PictureVal
	EndWith 
	oForm.Show(1)
EndIf 


*13. obtain DPI
?"DPI:",ImgGetXDpi(hImg),ImgGetXDpi(hImg)

ImgClose(hImg2)


* 14  Grayscale 

hImg=ImgOpen(_FROM_SCREEN)
ImgSetGray(hImg)
ImgSave(hImg," Grayscale processed screen .gif",_IMG_TIF)
ImgClose(hImg)


* 15  Frame operation multi page tif And animation gif It can be operated in this way :
cFile="fox.gif"  && This is an animation 

hImg=ImgOpen(cFile)
If hImg==""
	MessageBox(" Unable to open image !")
	Return 
EndIf 
* Get the number of frames 
nFrames=ImgGetFramesCount(hImg)
?" This file has a total of frames :",nFrames
ImgClose(hImg) && close 

* Get every frame 
For x=1 to nFrames
	hImg=ImgOpen(cFile,0,x)  && Open the first  x  frame , The second parameter can be ignored 
	If hImg==""
		MessageBox(" Unable to open page "+Transform(x)+" frame !")
		Loop 
	EndIf 
	?" Is generating ",x," frame ……"
	ImgSave(hImg,"Frame"+Transform(x)+".gif",_IMG_GIF)
	ImgClose(hImg)  && Each frame is a separate handle , It's all closed 
EndFor 

Set Library To 

Cat has uploaded to the cloud , download
https://share.weiyun.com/JXz9Mzkt

原网站

版权声明
本文为[VFP of Garfield]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200535523073.html