Article ID: 37318
Article Last Modified on 11/21/2006
This article was previously published under Q37318
SUMMARY
There is a correction for Page 141 of the "Microsoft QuickBASIC for Apple Macintosh: Users Guide." Step 6 of the example to transfer a picture from MacPaint to QuickBASIC should read as follows:
PICTURE, image$
(The manual incorrectly uses the PICTURE$ function instead of the PICTURE statement in Step 6.)
Once you successfully put an image into a string variable, you can write it permanently to a disk file if you want, as shown in the examples below.
MORE INFORMATION
Example 1
Below is a complete program that transfers an image from the clipboard to a picture string in Macintosh QuickBASIC. The program also outputs the image string to a sequential file for retrieval at a later time.
To perform this process, do the following:
- Run MacPaint or another graphics application.
- Copy a picture to the clipboard.
- Exit the program.
Run the following program in Microsoft QuickBASIC, or in the earlier Microsoft BASIC Interpreter Version 2.00, 2.10, or 3.00:
OPEN "clip:picture" FOR INPUT AS #1 ' Opens clip: in picture mode. image1$=INPUT$(LOF(1),1) ' Reads the image into image1$ PICTURE, image1$ ' Displays the picture. OPEN "Imagefile" FOR OUTPUT AS #2 ' Opens file for sequential output. PRINT #2, image1$; ' Writes image to the sequential disk file. CLOSE #1 CLOSE #2 CLS ' The following section can also be run at a later time. OPEN "Imagefile" FOR INPUT AS #1 ' Opens file for sequential input. image2$=INPUT$(LOF(1),1) ' Inputs image from disk file into image2$. PICTURE, image2$ ' Displays the picture. CLOSE #1 WHILE MOUSE(0) <> -1 : WEND ' Waits for a mouse click to end. END
Example 2
The following is an example of storing multiple pictures as variable-length strings in one sequential disk file. This program works in Microsoft QuickBASIC 1.00, in Microsoft BASIC Interpreter Version 2.00, 2.10, or 3.00, or in Microsoft BASIC Compiler Version 1.00 for the Apple Macintosh.
INPUT; "Display (D) current image file or Append (A) to file?:,r$ CLS IF r$ <> "A" AND r$ <> "a" THEN GOTO display again: INPUT "COPY a picture from the Scrapbook then hit RETURN",r$ CLS OPEN "CLIP:PICTURE" FOR INPUT AS #1 lenpic% = LOF(1) ' Get length in bytes of clipboard picture. image$ = INPUT$(lenpic%,1) ' Put picture into string variable. CLOSE#1 PICTURE,image$ ' Display the retrieved picture for confirmation OPEN "Stored Images" FOR APPEND AS #2 ' Open a file for images. PRINT#2,lenpic% ' In one record, write length of image string. PRINT#2,image$ ' In next record, write image string variable. CLOSE#2 INPUT "Append another image to images file? (Y/N)",r$ CLS IF r$ = "y" OR r$ = "Y" THEN GOTO again Display: DIM p$(64) ' String array to hold up to 64 pictures. OPEN "Stored Images" FOR INPUT AS #1 ' Opens Stored Images file. imagenum = 0 WHILE ( imagenum < 64 ) AND NOT EOF(1) imagenum = imagenum + 1 INPUT #1,n ' Get length of image string we stored earlier. p$(imagenum) = INPUT$(n,1) ' Input image into string array. extra$ = INPUT$(1,1) ' Skip past ASCII 13 (RETURN) byte WEND ' that terminates image record. CLOSE #1 WHILE 1 FOR j = 1 TO imagenum PICTURE,P$(j) ' Draw each stored picture. FOR Y=1 TO 2000 NEXT ' This pauses briefly so you can see picture. CLS NEXT INPUT "(R) Redisplay, (D) Delete Stored Images, (S) Stop";r$ IF r$ = "D" OR r$ = "d" THEN KILL "Stored Images" : GOTO again IF r$ = "S" OR r$ = "s" THEN STOP WEND
Additional query words: MQuickB
Keywords: KB37318