Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

Previous items Next items

Picture.CountColorMBS(col as color) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 3.3 Yes Yes Yes Yes No
Function: Counts the pixels with the given colors.
Example:
dim p as Picture
dim n1,n2 as Integer

p=NewPicture(300,300,32)

p.Graphics.ForeColor=&cFF0000
p.Graphics.FillRect 0,0,100,100

n1=p.CountColorMBS(&cFF0000)
n2=p.CountColorMBS(&cFFFFFF)

if n1=100*100 then
if n2=300*300-100*100 then
MsgBox "OK"
else
MsgBox "white failed"
end if
else
MsgBox "red failed"
end if
Notes: Returns the number of pixels found.

Some examples which use this method:

Feedback, Comments & Corrections

Picture.CountColorsMBS(byref red as memoryblock, byref blue as memoryblock, byref green as memoryblock, byref count as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 3.3 Yes Yes Yes Yes No
Function: Counts the color parts of each pixel.
Notes:
red, blue and green are filled with 1024 bytes big memoryblocks. One 4 byte integer for each color value possible.
Count is filled with the number of pixels processed.

Feedback, Comments & Corrections

Picture.DrawPictureFMBS(pic as picture, x as Double, y as Double, alpha as Double = 1.0, yield as Integer = 0) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 13.2 Yes Yes Yes Yes No
Function: Draws picture with floating point coordinates.
Notes:
Supports a mask on the picture.
Returns true on success.

Feedback, Comments & Corrections

Picture.EmbeddedMaskMBS(swap as boolean) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
property Graphics & Pictures MBS Picture Plugin 4.0 Yes No Yes Yes No
Function: Read or write a picture mask.
Example:
// Export a mask picture:

dim f as FolderItem
dim t as TiffPictureMBS
dim m,p as Picture
dim q as QTGraphicsExporterMBS

p=NewPicture(100,100,32)
p.Graphics.ForeColor=rgb(100,100,100)
p.Graphics.fillrect 0,0,100,100
p.Graphics.ForeColor=rgb(255,0,0)
p.Graphics.fillrect 20,20,80,30

m=NewPicture(100,100,32)
m.Graphics.ForeColor=rgb(255,255,255)
m.Graphics.FillRect 0,0,30,100
m.Graphics.ForeColor=rgb(200,200,200)
m.Graphics.FillRect 30,0,30,100
m.Graphics.ForeColor=rgb(100,100,100)
m.Graphics.FillRect 60,0,30,100

p.EmbeddedMaskMBS(true)=m
p.Mask.Graphics.DrawPicture m,0,0 // just for showing as a backdrop

q=new QTGraphicsExporterMBS

q.OpenExporter("TIFF")
q.Depth=32
q.InputPicture=p
q.CompressionQuality=1024
q.OutputFile=SpecialFolder.Desktop.Child("Hello.tif")
title=str(q.Export)

Backdrop=p
Notes:
Only useful on 32bit images.
Realbasic takes white for transparent, so you may need to swap this to black using the swap parameter.

Windows support removed somewhere in version 10.4 with internal changes. If you need this, please tell us.
(Read and Write computed property)

Feedback, Comments & Corrections

Picture.ExtractColorMBS(SearchColor as color, ReplaceWithColor as color, BackGroundColor as color) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 7.7 Yes Yes Yes Yes No
Function: Searches the first color and writes matching pixels with the secon color.
Example:
dim p as Picture

p=NewPicture(300,300,32)

p.Graphics.ForeColor=&cFF0000
p.Graphics.FillRect 000,100,100,100

p.Graphics.ForeColor=&c00FF00
p.Graphics.FillRect 100,100,100,100

p.Graphics.ForeColor=&c0000FF
p.Graphics.FillRect 200,100,100,100

p.Graphics.ForeColor=&c777700
p.Graphics.FillRect 100,200,100,100

// shows just a violet box on the left
backdrop=p.ExtractColorMBS(&cFF0000,&cFF00FF,&c000000)
Notes:
All pixels which do not match the search color are written to the new picture using the given background color.
Returns nil on any error.

Feedback, Comments & Corrections

Picture.ExtractColorRectangleMaskMBS as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 9.7 Yes Yes Yes Yes No
Function: Creates a mask picture with all the rectangles marked visible which contain color.
Example:
dim invertedpic as picture
dim pic as Picture

pic=NewPicture(300,300,32)
pic.graphics.drawpicture LogoMBS(100), 150,50

Backdrop=pic.ExtractColorRectangleMaskMBS
// marks black where the logo is drawn
Notes:
If you have a picture which is mostly gray and you need to find a color picture inside, this method can be helpful.

In the returned picture all pixels are black which belong to a rectangle which contains color pixels in the original picture.

See also:

Some examples which use this method:

Feedback, Comments & Corrections

Picture.ExtractColorRectangleMaskMBS(left as Integer,top as Integer,width as Integer,height as Integer) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 9.7 Yes Yes Yes Yes No
Function: Creates a mask picture with all the rectangles marked visible which contain color.
Notes:
If you have a picture which is mostly gray and you need to find a color picture inside, this method can be helpful.

In the returned picture all pixels are black which belong to a rectangle which contains color pixels in the original picture.

All pixel outside the rectangle specified will be white.

See also:

Some examples which use this method:

Feedback, Comments & Corrections

Picture.FindPictureMBS(pic as picture, byref x as Integer, byref y as Integer, StartX as Integer = 0, StartY as Integer = 0, Tolerance as Integer = 3) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 9.8 Yes Yes Yes Yes No
Function: Finds the given picture inside the picture.
Example:
// this is search image
dim p as new Picture(20,20,32)
p.Graphics.ForeColor = &c0000FF
p.Graphics.FillRect 0, 0, 20, 20

// this is target image
dim q as new Picture(500, 500, 32)

// with some color at Random position
q.Graphics.ForeColor = &c0000FF
q.Graphics.FillRect rnd*480, rnd*480, 30, 30

// do a search
dim x, y as Integer

if q.FindPictureMBS(p, x,y) then
// found image, so draw rectangle there

q.Graphics.ForeColor = &cFF0000
q.Graphics.DrawRect x, y, p.Width, p.Height
end if

window1.Backdrop = q
Notes:
Returns true on success and fills x/y variables.
Pixels are compared exactly, so a little bit color correction and make the picture being not found.

StartX/StartY can give start position. Tolerance defines how much two pixel component values can differ and still be considered the same. This helps with color matching and other drawings which may alter pixels a little bit.
If function returns true, you can use x+1, y as the new start position and search again.

Some examples which use this method:

Feedback, Comments & Corrections

Picture.GetMaskMBS(create as boolean = true) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 11.1 Yes Yes Yes Yes No
Function: Returns the mask for that picture.
Notes:
Same as Picture.Mask in Real Studio, but over the Plugin API.
We added it to test for leaks in plugin API.

Feedback, Comments & Corrections

Picture.GrayScale2MBS(mode as Integer) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 15.1 Yes Yes Yes Yes No
Function: Turns picture into grayscale.
Example:
dim l as Picture = LogoMBS(500)
if l.GrayScale2MBS(0) then
Backdrop = l
end if
Notes:
Returns true on success and false on failure.

Modes:
0y = 0.33 * R + 0.5 * G + 0.16 * BFaster version of 3
1y = 0.375 * R + 0.5 * G + 0.125 * BFaster version of 3
2y = 0.2126 * R + 0.7152 * G + 0.0722 * BPhotometric/digital ITU-R
3y = 0.299 * R + 0.587 * G + 0.114 * BDigital CCIR601

Mode 2 and 3 uses doubles and mode 0 and 1 use integers so they should be faster.
Still Mode 0 and 1 are just approximation formulas which trade accuracy for perfomance.

GrayScaleMBS makes a copy of the picture while GrayScale2MBS edits in-place.

Feedback, Comments & Corrections

Picture.GrayScaleMBS(mode as Integer) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 10.1 Yes Yes Yes Yes No
Function: Creates a grayscale copy of the picture.
Example:
dim l as Picture = LogoMBS(500)
Backdrop = l.GrayScaleMBS(0)
Notes:
If you have a mask on the picture, you need to draw that mask in the new picture's mask if you want to keep it.

Modes:
0y = 0.33 * R + 0.5 * G + 0.16 * BFaster version of 3
1y = 0.375 * R + 0.5 * G + 0.125 * BFaster version of 3
2y = 0.2126 * R + 0.7152 * G + 0.0722 * BPhotometric/digital ITU-R
3y = 0.299 * R + 0.587 * G + 0.114 * BDigital CCIR601

Mode 2 and 3 uses doubles and mode 0 and 1 use integers so they should be faster.
Still Mode 0 and 1 are just approximation formulas which trade accuracy for perfomance.

GrayScaleMBS makes a copy of the picture while GrayScale2MBS edits in-place.

Some examples which use this method:

Feedback, Comments & Corrections

Picture.GreenChannelMBS as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 11.0 Yes Yes Yes Yes No
Function: The green channel of the picture copied into a new picture.
Example:
dim p as Picture = LogoMBS(500)
Backdrop = p.GreenChannelMBS

Feedback, Comments & Corrections

Picture.HashMBS as UInt32
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 12.1 Yes Yes Yes Yes No
Function: Calculates CRC 32 over all pixels.
Example:
dim p as new Picture(100, 100, 32)

dim hash1 as UInt32 = p.HashMBS

// one black pixel
p.Graphics.Pixel(50, 50) = &c000000

dim hash2 as UInt32 = p.HashMBS

MsgBox hex(hash1)+" "+hex(hash2)
Notes:
You can use hash to see if two pictures have 100% identical pixel values. Changing just one pixel should give different number.
Does not include alpha channel or mask for the hash, but only RGB channels.

Some examples which use this method:

Feedback, Comments & Corrections

Picture.HasMaskMBS as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 6.4 Yes Yes Yes Yes No
Function: Whether this picture has a mask or not.
Notes: Returns true if yes or false if not.

Feedback, Comments & Corrections

Picture.HMirrorMBS as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin Yes Yes Yes Yes No
Function: Mirrors the picture horizontally (flip).
Example:
// load picture
dim f as FolderItem = SpecialFolder.Desktop.Child("test.png")
dim p as PNGPictureMBS = f.OpenAsPNGMBS

// get parts
dim pic as Picture = p.Pict.HMirrorMBS
dim mask as Picture = p.mask.HMirrorMBS

// save as png
dim g as FolderItem = SpecialFolder.Desktop.Child("output.png")
call g.SaveAsPNGMBS(pic, mask, 0)

// now apply mask to show it
pic.Mask = mask
Backdrop = pic
Notes:
This method returns a copy of the picture mirrored.
Returns nil on low memory.

Some examples which use this method:

Feedback, Comments & Corrections

Picture.HMirrorPictureMBS as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 7.8 Yes Yes Yes Yes No
Function: Mirrors the picture horizontally (flip).
Example:
if pic.HMirrorPictureMBS then // mirror picture
canvas1.backdrop=pic
else
canvas1.backdrop=pic.HMirrorMBS // mirror a copy
end if
Notes: This methods mirrors the picture data itself. Returns true on success and false on failure. Only bitmap pictures can be mirrored this way.

Some examples which use this method:

Feedback, Comments & Corrections

Picture.InvertGrayMBS as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 9.7 Yes Yes Yes Yes No
Function: Inverts the gray pixels inside the picture.
Example:
dim invertedpic as picture
dim pic as picture

pic=LogoMBS(500)
invertedpic=pic.InvertGrayMBS

Backdrop=invertedpic
Notes: Returns nil on any error.

See also:

Some examples which use this method:

Feedback, Comments & Corrections

Picture.InvertGrayMBS(left as Integer,top as Integer,width as Integer,height as Integer) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 9.7 Yes Yes Yes Yes No
Function: Inverts the gray pixels inside the picture.
Example:
dim invertedpic as picture
dim pic as picture

pic=LogoMBS(500)
invertedpic=pic.InvertGrayMBS(0,0,250,250)

Backdrop=invertedpic
Notes:
Returns nil on any error.
The part of the picture which is not inverted will be all black.

See also:

Some examples which use this method:

Feedback, Comments & Corrections

Picture.InvertMBS as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 7.5 Yes Yes Yes Yes No
Function: Inverts the whole picture.
Example:
dim invertedpic as picture
dim pic as picture

pic=LogoMBS(500)
invertedpic=pic.InvertMBS

Backdrop=invertedpic
Notes: Returns nil on any error.

See also:

Some examples which use this method:

Feedback, Comments & Corrections

Picture.InvertMBS(left as Integer,top as Integer,width as Integer,height as Integer) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 4.3 Yes Yes Yes Yes No
Function: Inverts the picture.
Example:
dim invertedpic as picture
dim pic as picture

pic=LogoMBS(500)
invertedpic=pic.InvertMBS(0,0,250,250)

Backdrop=invertedpic
Notes:
Returns nil on any error.
The part of the picture which is not inverted will be all black.

See also:

Some examples which use this method:

Feedback, Comments & Corrections

Picture.isBlackMBS as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 10.0 Yes Yes Yes Yes No
Function: Returns true if the picture has only black pixels.
Example:
dim p as Picture

// test white
p=NewPicture(100,100,32)

MsgBox "isBlackMBS: "+str(p.isBlackMBS)+EndOfLine+"isWhiteMBS: "+str(p.isWhiteMBS)

// test black
p.Graphics.ForeColor=&c000000
p.Graphics.FillRect 0,0,100,100
MsgBox "isBlackMBS: "+str(p.isBlackMBS)+EndOfLine+"isWhiteMBS: "+str(p.isWhiteMBS)

// test red
p.Graphics.ForeColor=&cFF0000
p.Graphics.FillRect 0,0,100,100
MsgBox "isBlackMBS: "+str(p.isBlackMBS)+EndOfLine+"isWhiteMBS: "+str(p.isWhiteMBS)

See also:

Feedback, Comments & Corrections

Picture.isBlackMBS(left as Integer,top as Integer,width as Integer,height as Integer) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 10.0 Yes Yes Yes Yes No
Function: Returns true if the picture has only black pixels in the given rectangle.

See also:

Feedback, Comments & Corrections

Picture.isGrayMBS(tolerance as Integer = 0) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 12.5 Yes Yes Yes Yes No
Function: Checks if a picture has only shades of gray in all pixels.
Example:
dim p as new Picture(100,100,32)

// 1. test white picture

if p.isGrayMBS then
MsgBox "white picture is gray."
end if

// 2. test gray picture
dim g as Graphics = p.Graphics
g.ForeColor = &c777777
g.FillRect 0, 0, 100, 100

if p.isGrayMBS then
MsgBox "gray picture is gray."
end if

// 3. test gray picture with tolerance
g.ForeColor = &c777778
g.FillRect 0, 0, 100, 100

if p.isGrayMBS(0) then
MsgBox "gray (not correct)"
else
MsgBox "not gray (correct)"
end if

if p.isGrayMBS(1) then
MsgBox "gray (correct)"
else
MsgBox "not gray (not correct)"
end if

// 4. test gray picture with over tolerance
g.ForeColor = &c777779
g.FillRect 0, 0, 100, 100

if p.isGrayMBS(0) then
MsgBox "gray (not correct)"
else
MsgBox "not gray (correct)"
end if

if p.isGrayMBS(1) then
MsgBox "gray (not correct)"
else
MsgBox "not gray (correct)"
end if
Notes:
Tolerance defines how big the difference between two channels can be. Typically a value smaller than 5. Pass 0 if you need exact gray scales.
Like the difference between &c000000 and &c000001 is not visible to most people, it can be ignored often.

See also:

Feedback, Comments & Corrections

Picture.isGrayMBS(tolerance as Integer, left as Integer,top as Integer,width as Integer,height as Integer) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 12.5 Yes Yes Yes Yes No
Function: Checks if a picture has only shades of gray in all pixels.
Notes:
Tolerance defines how big the difference between two channels can be. Typically a value smaller than 5. Pass 0 if you need exact gray scales.
Like the difference between &c000000 and &c000001 is not visible to most people, it can be ignored often.

See also:

Feedback, Comments & Corrections

Picture.isWhiteMBS as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 10.0 Yes Yes Yes Yes No
Function: Returns true if the picture has only white pixels.
Example:
dim p as Picture

// test white
p=NewPicture(100,100,32)

MsgBox "isBlackMBS: "+str(p.isBlackMBS)+EndOfLine+"isWhiteMBS: "+str(p.isWhiteMBS)

// test black
p.Graphics.ForeColor=&c000000
p.Graphics.FillRect 0,0,100,100
MsgBox "isBlackMBS: "+str(p.isBlackMBS)+EndOfLine+"isWhiteMBS: "+str(p.isWhiteMBS)

// test red
p.Graphics.ForeColor=&cFF0000
p.Graphics.FillRect 0,0,100,100
MsgBox "isBlackMBS: "+str(p.isBlackMBS)+EndOfLine+"isWhiteMBS: "+str(p.isWhiteMBS)

See also:

Feedback, Comments & Corrections

Picture.isWhiteMBS(left as Integer,top as Integer,width as Integer,height as Integer) as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin 10.0 Yes Yes Yes Yes No
Function: Returns true if the picture has only white pixels in the given rectangle.

See also:

Feedback, Comments & Corrections

Picture.MakeHBITMAPMBS as Ptr
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Graphics & Pictures MBS Picture Plugin No Yes No Yes, Windows only No
Function: Returns a HBITMAP handle to the picture.
Notes:
Warning: This function works only right on HDIB pictures.

The picture is cloned but both pictures may use the same binary data in background.

You will have to free this handle with DeleteObject:
Declare Function DeleteObject Lib "gdi32" (hObject as Integer) as Integer

Feedback, Comments & Corrections

MergePictureMBS(source1 as picture, source2 as picture) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
global method Graphics & Pictures MBS Picture Plugin 7.5 Yes Yes Yes Yes No
Function: Merges the two pictures into one.
Example:
// in RB this method would work like this:

dim i,j as Integer
dim col2 as color
dim r1,r2,g1,g2,b1,b2 as Integer
dim dest as Picture // destination
dim source1, source2 as Picture // source pictures

col2 = source1.graphics.pixel(i,j)
r1 = col2.red
g1 = col2.green
b1 = col2.blue
col2 = source2.graphics.pixel(i,j)
r2 = col2.red
g2 = col2.green
b2 = col2.blue

dest.graphics.pixel(i,j) = RGB(max(r1,r2), max(g1,g2), max(b1,b2))
Notes:
Masks are ignored.
Returns nil on low memory.
Both pictures must have the same size and not be nil.

Some examples using this method:

Feedback, Comments & Corrections

Previous items Next items

The items on this page are in the following plugins: MBS Picture Plugin.





Links
MBS Xojo blog