Microsoft KB Archive/37318

= How to Input Image from Clipboard, Output to Screen or File =

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 &quot;Microsoft QuickBASIC for Apple Macintosh: Users Guide.&quot; 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.



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 &quot;clip:picture&quot; 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 &quot;Imagefile&quot; 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 &quot;Imagefile&quot; 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; &quot;Display (D) current image file or Append (A) to file?:,r$ CLS IF r$ <> &quot;A&quot; AND r$ <> &quot;a&quot; THEN GOTO display again: INPUT &quot;COPY a picture from the Scrapbook then hit RETURN&quot;,r$ CLS OPEN &quot;CLIP:PICTURE&quot; 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 &quot;Stored Images&quot; 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 &quot;Append another image to images file? (Y/N)&quot;,r$ CLS IF r$ = &quot;y&quot; OR r$ = &quot;Y&quot; THEN GOTO again Display: DIM p$(64)   ' String array to hold up to 64 pictures. OPEN &quot;Stored Images&quot; 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 &quot;(R) Redisplay, (D) Delete Stored Images, (S) Stop&quot;;r$ IF r$ = &quot;D&quot; OR r$ = &quot;d&quot; THEN KILL &quot;Stored Images&quot; : GOTO again IF r$ = &quot;S&quot; OR r$ = &quot;s&quot; THEN STOP WEND

Additional query words: MQuickB

Keywords: KB37318

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.