You Are Here:

Community: Developer Discussion Boards

#1 Old Unhappy Image display problems - 2008-12-09, 22:25

Join Date: Oct 2008
Posts: 27
Davie1
Offline
Registered User
Hi,

I am trying to read in the location of an image on the memory card and display this image on the screen. There are no problems reading from the file.

The image location is "e:\\python\\map.jpg".

This is held in a variable called theMap.

The error i am getting occurs when i do the following:

Code:
im = graphics.Image.open(theMap)
However this works fine:
Code:
im = graphics.Image.open("e:\\python\\map.jpg")
Can you please show me what the problem is?
Reply With Quote

#2 Old Re: Image display problems - 2008-12-09, 22:34

Join Date: Mar 2008
Posts: 127
jtullis
Offline
Regular Contributor
I'm sorry, I don't actually understand what the problem is.

This works as it should:
Code:
im = graphics.Image.open("e:\\python\\map.jpg")
Clearly python doesn't intuitively 'know' what theMap is, so you'd have to say:

Code:
theMap = u'e:\\python\\map.jpg'
im = graphics.Image.open(theMap)
Sorry if this is little help, but I don't understand what the issue is.
Reply With Quote

#3 Old Re: Image display problems - 2008-12-09, 22:50

Join Date: Oct 2008
Posts: 27
Davie1
Offline
Registered User
Quote:
Originally Posted by jtullis View Post
I'm sorry, I don't actually understand what the problem is.

This works as it should:
Code:
im = graphics.Image.open("e:\\python\\map.jpg")
Clearly python doesn't intuitively 'know' what theMap is, so you'd have to say:

Code:
theMap = u'e:\\python\\map.jpg'
im = graphics.Image.open(theMap)
Sorry if this is little help, but I don't understand what the issue is.
Sorry I will try to explain it a bit better.

The image location can change depending on what map I want to display so I can't have the location "hard coded".

theMap is set to "e:\\python\\map.jpg" because this is what is read from the file, but as I said before
Code:
im = graphics.Image.open(theMap)
does not display the image.
Reply With Quote

#4 Old Re: Image display problems - 2008-12-10, 01:43

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Hi Davie1,

Are you displaying it on a canvas?

If not, you should use canvas as the application body.

Example:

Code:
import appuifw, graphics

path = "E:\\Python\\map.jpg"
img = graphics.Image.open(path)

def handle_redraw(rect):
    canvas.blit(img)

canvas = appuifw.Canvas(redraw_callback = handle_redraw)
appuifw.app.body = canvas

Hope it helps,

Rafael.
Reply With Quote

#5 Old Re: Image display problems - 2008-12-10, 08:14

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Quote:
Originally Posted by Davie1 View Post
theMap is set to "e:\\python\\map.jpg" because this is what is read from the file...
If your file actually says e:\\python\\map.jpg, that's wrong. The problem is this:

Symbian OS uses a single backslash symbol (\) to separate path components. This is unfortunate, as Python uses the same symbol as an escape mechanism for string literals. This enables entering symbols that normally interfere with the syntax of string literals: quotation marks (\"), apostrophes (\') and the backslash (\\) itself, as well as character codes (\xnn and \unnnn). This has the effect that to represent a literal backslash in a Python string literal, you need to precede it with another backslash, i.e. enter the backslash twice, like in your example.

Reading text from a file does not undergo this type of escape-processing. If you read Symbian OS paths from a file, the file must contain a single backslash as path separator, otherwise the OS won't find the file you're referring to. You also need to decide an encoding for your file (UTF-8 is good) and decode it to a Unicode string when reading, so that filenames with accented characters will work.
Reply With Quote

#6 Old Re: Image display problems - 2008-12-10, 13:19

Join Date: Oct 2008
Posts: 27
Davie1
Offline
Registered User
Quote:
Originally Posted by jethro.fn View Post
If your file actually says e:\\python\\map.jpg, that's wrong. The problem is this:

Symbian OS uses a single backslash symbol (\) to separate path components. This is unfortunate, as Python uses the same symbol as an escape mechanism for string literals. This enables entering symbols that normally interfere with the syntax of string literals: quotation marks (\"), apostrophes (\') and the backslash (\\) itself, as well as character codes (\xnn and \unnnn). This has the effect that to represent a literal backslash in a Python string literal, you need to precede it with another backslash, i.e. enter the backslash twice, like in your example.

Reading text from a file does not undergo this type of escape-processing. If you read Symbian OS paths from a file, the file must contain a single backslash as path separator, otherwise the OS won't find the file you're referring to. You also need to decide an encoding for your file (UTF-8 is good) and decode it to a Unicode string when reading, so that filenames with accented characters will work.
This solved my problem.

Thank you to everyone for their help. It is much appreciated
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
modifying image on display in canvas aqibarain Mobile Java General 1 2007-11-30 10:01
simple script to display rgb image gojkoa Python 1 2005-11-21 10:33
HELP: Mutable Image to Immutable Image? rj_cybersilver Mobile Java Media (Graphics & Sounds) 1 2005-03-26 10:58
how to display image? ganesh_babu Mobile Java Media (Graphics & Sounds) 8 2004-06-22 09:02
Game Developement - Display object on a image background kenkwokkam Mobile Java General 0 2003-02-08 15:58

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia