MBS Xojo Developer Conference and Training
Join us from 3rd to 6th May 2017 in Berlin, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

BinaryStringtoPictureMBS(data as String) as Picture
global method, Pictures Import and Export, MBS Picture Plugin (Picture),
Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Creates the picture back from the binary data inside the string.
Example:
dim pic as Picture = LogoMBS(500)

// encode
dim s as string = PicturetoBinaryStringMBS(pic)

// decode
Backdrop = BinaryStringtoPictureMBS(s)
Notes:
Deprecated. Please do not use for old projects and convert existing images into a new format, e.g. PNG.

The format of the binary encoded picture data:

+ 0 Kenn, PPIC for Packed Picture
+ 4 Length of whole block
+ 8 Width (BigEndian)
+12 Height (BigEndian)
+16 Depth (BigEndian, 32 for 32bit)
+20 Offset of the binary data. maybe 40.
+24 Reserved for future use. Should be 0.
+40 Pixel Data, packed R, G, B in one byte per Subpixel.

300x300 Pixels will make up 300*300+40 -> 270040 Bytes.

This method does not require Quicktime or any other OS Service, but it does no compression.

May be a good way to store pictures crossplatform inside a database. As Valentina can do its own Zip based compression, this may be a wonderfull way to store pictures uncompressed (or lossless compressed) inside the database.
Does not handle mask or alpha channel.

Some examples using this method:

PicturetoBinaryStringMBS(p as picture) as string
global method, Pictures Import and Export, MBS Picture Plugin (Picture),
Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Creates a string with the picture content for saving.
Example:
dim s as string
dim pic as picture = LogoMBS(100)

s=PicturetoBinaryStringMBS(pic)
Notes:
Deprecated. Please do not use for old projects and convert existing images into a new format, e.g. PNG.

The format of the binary encoded picture data:

+ 0 Kenn, PPIC for Packed Picture
+ 4 Length of whole block
+ 8 Width (BigEndian)
+12 Height (BigEndian)
+16 Depth (BigEndian, 32 for 32bit)
+20 Offset of the binary data. maybe 40.
+24 Reserved for future use. Should be 0.
+40 Pixel Data, packed R, G, B in one byte per Subpixel.

300x300 Pixels will make up 300*300+40 -> 270040 Bytes.

This method does not require Quicktime or any other OS Service, but it does no compression.
Does not handle mask or alpha channel.

May be a good way to store pictures crossplatform inside a database. As Valentina can do its own Zip based compression, this may be a wonderfull way to store pictures uncompressed (or lossless compressed) inside the database.

The returned string has the encoding set to binary (no encoding). If you want to concat the string with another you should check the encoding. If you don't handle that RB may convert the JPEG data to UTF8 (Unicode) which will destroy it.

Some examples using this method:

PictureToFileStringMBS(p as picture, compressor as string, quality as integer) as string
global method, Pictures Import and Export, MBS QuickTime Plugin (QTImporter),
Plugin version: 3.3, Mac: Yes, Win: Yes, Linux: No, Console & Web: Yes, Feedback.

Function: QuickTime will make a string from the picture using the specified compressor.
Example:
dim s as string
dim q,p as Picture

p=NewPicture(100,100,32)

s=PictureToFileStringMBS(p,"BMPf",1024)

Title=str(lenb(s))
q=StringtoPictureMBS(s,"test.bmp","")

Backdrop=q
Notes:
p as picture:
Your picture must be a pixel bitmap or in other words a picture made using newpicture. You can check it using the graphics property or just use a function like that to verify that your picture is well:

Function MakeGoodPicture(old as picture) As picture
dim p as picture

p=old
if p<>nil and old.graphics=nil then
p=newpicture(old.width,old.height,32)
p.graphics.drawpicture old,0,0
end if

return p
End Function

compressor as string:
The codec is a 4 letter code to determinate the codec to use. Possible values for QuickTime 5.0, which I've tested:

".SGI"SGI
"8BPS"Photoshop
"BMPf" Windows BMP
"JPEG"JPEG
"PICT"Mac Picture
"PNGf"PNG
"PNTG"MacPaint
"TIFF"Tiff
"TPIC"TGA
"qtif"QuickTime Image file
(if codec is "", jpeg is used as default)

quality as integer
Any value between 0 and &h400 to indicate the quality:

&h000Min Quality
&h100Low Quality
&h200Normal Quality
&h300High Quality
&h3FFMax Quality
&h400Lossless Quality

You may use the function picture.bitmap to make sure that the picture is a bitmap, because this function works only for bitmap pictures.

This function requires QuickTime 3.0 or newer!

The returned string has the encoding set to Binary. If you want to concat the string with another you should change the encoding, so both strings have the same encoding. If you don't handle that RB may convert the JPEG data to UTF8 (Unicode) which will destroy it.
PicturetoStringMBS(p as picture,codec as string,quality as integer,depth as integer) as string
global method, Pictures Import and Export, MBS QuickTime Plugin (QTImporter),
Mac: Yes, Win: Yes, Linux: No, Console & Web: Yes, Feedback.

Function: QuickTime will make a string from the picture using the specified codec.
Example:
dim s as string
dim pic as Picture = LogoMBS(500)
s=PicturetoStringMBS(pic,"jpeg",512,0)
Notes:
p as picture:
Your picture must be a pixel bitmap or in other words a picture made using newpicture. You can check it using the graphics property or just use a function like that to verify that your picture is well:

Function MakeGoodPicture(old as picture) As picture
dim p as picture

p=old
if p<>nil and old.graphics=nil then
p=newpicture(old.width,old.height,32)
p.graphics.drawpicture old,0,0
end if

return p
End Function

codec as string:
The codec is a 4 letter code to determinate the codec to use. Possible values for QuickTime 5.0, which I've tested:

"jpeg",
"gif ",
"png ",
"tiff",
"tga ".
(if codec is "", jpeg is used as default)

quality as integer
Any value between 0 and &h400 to indicate the quality:

&h000Min Quality
&h100Low Quality
&h200Normal Quality
&h300High Quality
&h3FFMax Quality
&h400Lossless Quality

depth as integer

The depth at which the image is likely to be viewed. Compressors may use this as an indication of the color or grayscale resolution of the compressed image. If you set this parameter to 0, the Image Compression Manager determines the appropriate value for the source image. Values of 1, 2, 4, 8, 16, 24, and 32 indicate the number of bits per pixel for color images. Values of 34, 36, and 40 indicate 2-bit, 4-bit, and 8-bit grayscale, respectively, for grayscale images.


Improved for RB 4.5 on Windows to work better by not flipping the image randomly.

You may use the function picture.bitmap to make sure that the picture is a bitmap, because this function works only for bitmap pictures.

This function requires QuickTime 3.0 or newer!

The returned string has the encoding set to MacRoman. If you want to concat the string with another you should change the encoding, so both strings have the same encoding. If you don't handle that RB may convert the JPEG data to UTF8 (Unicode) which will destroy it.

Some examples using this method:

StringtoPictureByOSTypeMBS(data as String, OSType as String) as Picture
global method, Pictures Import and Export, MBS QuickTime Plugin (QTImporter),
Mac: Yes, Win: Yes, Linux: No, Console & Web: Yes, Feedback.

Function: QuickTime will make a picture object from the provided data string (e.g. a downloaded jpeg file from the Internet) and make a picture object from it. To make it faster provide a filename or MimeType so QuickTime will work faster.
Example:
dim data as string // some jpeg data
dim p as Picture
p=StringtoPictureByOSTypeMBS(data,"JPEG")
Notes:
This function is based on the source code from Stephan Huber:
http://www.digitalmind.de/realbasic
I added it to extend it for Windows and add the inverse function.

You may use the function picture.bitmap to make sure that the picture is a bitmap, because this function works only for bitmap pictures.

The OSType is the same type like in mactype of a folderitem.

Some examples using this method:

StringtoPictureMBS(data as String, FileName as String, MimeType as String) as Picture
global method, Pictures Import and Export, MBS QuickTime Plugin (QTImporter),
Mac: Yes, Win: Yes, Linux: No, Console & Web: Yes, Feedback.

Function: QuickTime will make a picture object from the provided data string (e.g. a downloaded jpeg file from the Internet) and make a picture object from it. To make it faster provide a filename or MimeType so QuickTime will work faster.
Example:
dim data as string // picture data
dim p as picture = StringtoPictureMBS(data,"mypicture.jpg","Image/jpeg")
Notes:
This function is based on the source code from Stephan Huber
http://www.digitalmind.de/realbasic
I added it to extend it for Windows and add the inverse function.

You may use the function picture.bitmap to make sure that the picture is a bitmap, because this function works only for bitmap pictures.

This function requires QuickTime 3.0 or newer!
See also FileExtensionToMimeTypeMBS function.

Some examples using this method:

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




Links
MBS Real Studio Plugins