Code archives/Graphics/HalvePic
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| This code is my discover of how to halve a picture preserving the original image points. Enjoy! EsseEmmeErre | |||||
;-> HalvePic public by Stefano Maria Regattin
;d> 3 Nov 2012
;m> 3 Nov 2012
;--------------
AppTitle("HalvePic public by Stefano Maria Regattin")
Graphics(710,FontHeight(),0,2)
PixPath$=Input$(">")
If FileType(PixPath$)=1 Then
Pix=LoadImage(PixPath$)
PixWidth=ImageWidth(Pix)
PixHeight=ImageHeight(Pix)
BeforeLast=PixHeight-FontHeight()-FontHeight()
EndGraphics()
Graphics(PixWidth,PixHeight,0,2)
HalvedPixWidth=PixWidth/2
HalvedPixHeight=PixHeight/2
Immagine=LoadImage(PixPath$)
DrawImage(Pix,0,0):Delay(2000):Cls()
For PointY=0 To HalvedPixHeight-1
For PointX=0 To HalvedPixWidth-1
SetBuffer(ImageBuffer(Pix))
PointColour=ReadPixel(PointX*2,PointY*2) And $FFFFFF
RedOfPoint=PointColour/65536 Mod 256
GreenOfPoint=PointColour/256 Mod 256
BlueOfPoint=PointColour Mod 256
PointColour=ReadPixel(PointX*2,PointY*2) And $FFFFFF
RedOfPoint=RedOfPoint+PointColour/65536 Mod 256
GreenOfPoint=GreenOfPoint+PointColour/256 Mod 256
BlueOfPoint=BlueOfPoint+PointColour Mod 256
RedOfPoint=RedOfPoint/4:GreenOfPoint=GreenOfPoint/4:BlueOfPoint=BlueOfPoint/4
SetBuffer(FrontBuffer())
Color(RedOfPoint,GreenOfPoint,BlueOfPoint)
Plot(PointX,PointY)
Next
Next
Locate(0,BeforeLast):Color(255,255,255):Print("Image halved.")
Write("Press a key to leave...")
Else
Write("Image not found, press a key to leave...")
EndIf
WaitKey()
EndGraphics():End |
Comments
| ||
| Hi EEE., THat's very nice HalvePic code; With some minor changes to your code I got it to work for me. For some reason, it would only run on my PC if I commented out the following 'graphics' statements. ![]() I see that your purpose was to reuse a [halved] subset of the image color points to make an image that is half the dimensions... and has 25% of the original points. I did before and after screenshots using your program. Here is "Happy Days", and cut in half: ![]() ![]() I don't know why, but the same image halved by "Irfanview" looks brighter. ![]() ; -------------------------------------------------------- In case you'd like to investigate it further, there is this free Library called FreeImage.DLL http://freeimage.sourceforge.net/ http://sourceforge.net/projects/freeimage/ http://sourceforge.net/p/freeimage/discussion/ Freeimage works perfectly with Blitz3D, and it has various image manipulation routines, and is faster than the Blitz3D's own routines. http://freeimage.sourceforge.net/documentation.html { <--Freeimage documentation } http://graphics.stanford.edu/courses/cs148-10-summer/docs/FreeImage3131.pdf { <-- Freeimage PDF } The FiRescale Function is similar to what you've done with your HalvePic code, however, I doubt that FiRescale preserves all the original half points, which makes your own HalvePic very unique. ![]() This screenshot shows a list of Freeimage Functions: |
Code Archives Forum




