RE: Display Picture.
- Posted by Chris Bensler <bensler at mail.com> Apr 09, 2002
- 393 views
Sam wrote: > Hi ... > > Appreciate the answers I've gotten from you guys. Hope you can come > up with one more. I can't seem to get Euphoria to display a picture. > > include image.e > sequence Pic1 > Pic1 = read_bitmap ("C:\\Euphoria\\MyPic.Bmp") > > Got message "type_check failure, MyPic is 1" > > Tried a different picture. This time, for variety, I got, "type_check > failure, DiffPic is 3." > > Wasn't going to give up that easily though. Changed the program > slightly. > > include image.e > object Pic1 > Pic1 = read_bitmap ("C:\\Euphoria\\MyPic.Bmp") > > Hey! No error msg. this time! > > So I added a line: > > display_image ({100, 20}, Pic1 [2]) > > This time I got, "attempt to subscript an atom > (reading from it)" > > So then I tried to run the `Bitmap.ex' program in the demo\dos32 > directory. Tried three different pictures. One showed up on screen, but > only the bottom 20 percent. The other two get msg, `unsupported format.' > > > Any idea?? > > Thanks, > > Sam > read_bitmap() returns a a 2-element sequence where the first element is a sequence that contains the bitmap palette, and the second is a sequence containing the bitmap data. Bitmaps of 2, 4, 16 or 256 colors are supported. If the file is not in a good format, an error code (atom) is returned instead: global constant BMP_OPEN_FAILED = 1, BMP_UNEXPECTED_EOF = 2, BMP_UNSUPPORTED_FORMAT = 3 Your first attempt failed to open the specified bitmap. Your second attempt tried to open an unsupported bitmap. The third attempt also failed to read_bitmap(), but you didn't check to see if Pic1 was successful and passed an atom to display_image(), when it accepts a sequence. This is what you should have, to be safe. (untested code) object Pic1 Pic1 = read_bitmap("C:\\Euphoria\\MyPic.Bmp") if atom(Pic1) then puts(2,sprintf("read_bitmap() failed. Error code: %d\n",Pic1)) abort(1) end if display_image({100,20},Pic1[2]) I can't explain why you would get unexpected images displayed, except that the bitmaps you are trying to use probably aren't supported. Chris