60 lines
1.6 KiB
Plaintext
60 lines
1.6 KiB
Plaintext
include "NSLog.incl"
|
|
/*
|
|
|
|
This task creates an image with a background filled with red pixels.
|
|
Then sets one pixel to blue in the center of the image.
|
|
Then gets the RGB color values at that pixel position.
|
|
Then saves the image as a jpg to the desktop.
|
|
|
|
*/
|
|
|
|
_Window = 1
|
|
_Horz = 300
|
|
_Vert = 100
|
|
_X = 150
|
|
_Y = 50
|
|
|
|
window _Window, @"Bitmap window with blue dot",(0,0,_Horz, _Vert)
|
|
WindowSetBackgroundColor(_Window,fn colorwhite)
|
|
|
|
|
|
local fn DrawImage as ImageRef
|
|
ImageRef image = fn ImageWithSize( fn CGSizeMake(_Horz,_Vert ) ) // create blank image
|
|
|
|
ImageLockFocus( image ) // lock image during drawing
|
|
|
|
CFIndex i
|
|
|
|
for i = 0 to _Horz // fill all horizontal pixels with red dots
|
|
BezierPathStrokeLine( fn CGPointMake( i, 0 ), fn CGPointMake( i, _Vert ), 1, fn Colorred )
|
|
next
|
|
|
|
BezierPathStrokeRect( fn CGRectMake( _X,_Y,1,1), 1.0, fn ColorBlue) // Draw a blue dot in the center.
|
|
|
|
ImageUnlockFocus( image ) // unlock image afer drawing
|
|
|
|
end fn = image
|
|
|
|
|
|
// Draw the image
|
|
ImageRef theImage
|
|
theImage = fn DrawImage
|
|
|
|
// Display the image
|
|
imageview 1,, theImage, (0,0,_Horz, _Vert)
|
|
|
|
// Get the color of the pixel at horizontal position X and vertical position Y
|
|
colorref color
|
|
color = fn ViewColorAtXY( _Window, _X, _Y )
|
|
NSLog( @"RGB Color values at pixel position X,Y are %@", color)
|
|
|
|
// Save the image as a jpg
|
|
CFURLRef DesktopDirectory,url
|
|
DesktopDirectory = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask )
|
|
url = fn URLByAppendingPathComponent( DesktopDirectory, @"Bitmap Image.jpg" )
|
|
bool err
|
|
err = fn ImageWriteToURL( theImage, url, NSBitmapImageFileTypeJPEG, _true ) // save image as jpg
|
|
|
|
|
|
handleevents
|