File is not a Windows BMP file - but I have pygame.image.get_extended() = 1
I'm trying to download the images stored in a subdirectory called "images" in pygame, but I get the File is not a Windows BMP file. I am running python 2.7 in Spyder on a Mac OS. I have pygame.image.get_extended() = 1
so not sure what the issue is. My pygame doesn't seem corrupted as it can run fine without a png (tried out a different game). Been struggling to figure out a solution. I already tried using .png and .bmp extensions for the images. Thank you
# From Al Sweigart's book
import pygame, sys, time, random, os
from pygame.locals import *
print os.getcwd()
# set up pygame
pygame.init()
mainClock = pygame.time.Clock()
# Set up window
windowWidth = 400
windowHeight = 400
windowSurface = pygame.display.set_mode((windowWidth, windowHeight), 0, 32)
pygame.display.set_caption("Sprites and Sounds")
# Set up colors
white = (255,255,255)
# Set up block data structure
player = pygame.Rect(300, 100, 40, 40)
playerImage = pygame.image.load("images/ninja.bmp")
playerStretchedImage = pygame.transform.scale(playerImage, (40,40))
foodImage = pygame.image.load("images/apple.bmp")
foodStretchedImage = pygame.transform.scale(foodImage, (15,15))
foods =
for i in range(20):
foods.append(pygame.Rect(random.randint(0, windowWidth- 20),
random.randint(0, windowHeight-20), 20, 20))
foodCounter = 0
newfood = 40
# set up keyboard vars
moveLeft = False
moveRight = False
moveUp = False
moveDown = False
movespeed = 6
## Add sound here
# Run game loop
while True:
# check for quit event
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
# change keyboard variables
if event.key == K_LEFT or event.key == K_a:
moveRight = False
moveLeft = True
if event.key == K_RIGHT or event.key == K_d:
moveLeft = False
moveRight = True
if event.key == K_UP or event.key == K_w:
moveDown = False
moveUp = True
if event.key == K_DOWN or event.key == K_s:
moveUp = False
moveDown = True
if event.type == KEYUP:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == K_LEFT or event.key == K_a:
moveLeft = False
if event.key == K_RIGHT or event.key == K_d:
moveRight = False
if event.key == K_UP or event.key == K_w:
moveUp = False
if event.key == K_DOWN or event.key == K_s:
moveDown = False
if event.key == K_x:
player.top = random.randint(0, windowHeight-player.height)
player.left = random.randint(0, windowWidth-player.width)
if event.type == MOUSEBUTTONUP:
foods.append(pygame.Rect(event.pos[0], event.pos[1], 20, 20))
## Draw white background onto surface
windowSurface.fill(White)
## move player
if moveDown and player.bottom < windowHeight:
player.top += movespeed
if moveUp and player.top > 0:
player.top -= movespeed
if moveLeft and player.left >0:
player.left -= movespeed
if moveRight and player.right < windowWidth:
player.left += movespeed
# draw block image onto surface player object
windowSurface.blit(playerStretchedImage, player)
# check whether player has intersected with food squares
for food in foods[:]:
if player.colliderect(food):
foods.remove(food)
player = pygame.Rect(player.left, player.top,
player.width+2, player.height +2)
playerStretchedImage = pygame.transform.scale(playerImage,
(player.width, player.height))
# draw food
for food in foods:
windowSurface.blit(foodImage,food)
# draw window
pygame.display.update()
mainClock.tick(40)
python pygame
add a comment |
I'm trying to download the images stored in a subdirectory called "images" in pygame, but I get the File is not a Windows BMP file. I am running python 2.7 in Spyder on a Mac OS. I have pygame.image.get_extended() = 1
so not sure what the issue is. My pygame doesn't seem corrupted as it can run fine without a png (tried out a different game). Been struggling to figure out a solution. I already tried using .png and .bmp extensions for the images. Thank you
# From Al Sweigart's book
import pygame, sys, time, random, os
from pygame.locals import *
print os.getcwd()
# set up pygame
pygame.init()
mainClock = pygame.time.Clock()
# Set up window
windowWidth = 400
windowHeight = 400
windowSurface = pygame.display.set_mode((windowWidth, windowHeight), 0, 32)
pygame.display.set_caption("Sprites and Sounds")
# Set up colors
white = (255,255,255)
# Set up block data structure
player = pygame.Rect(300, 100, 40, 40)
playerImage = pygame.image.load("images/ninja.bmp")
playerStretchedImage = pygame.transform.scale(playerImage, (40,40))
foodImage = pygame.image.load("images/apple.bmp")
foodStretchedImage = pygame.transform.scale(foodImage, (15,15))
foods =
for i in range(20):
foods.append(pygame.Rect(random.randint(0, windowWidth- 20),
random.randint(0, windowHeight-20), 20, 20))
foodCounter = 0
newfood = 40
# set up keyboard vars
moveLeft = False
moveRight = False
moveUp = False
moveDown = False
movespeed = 6
## Add sound here
# Run game loop
while True:
# check for quit event
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
# change keyboard variables
if event.key == K_LEFT or event.key == K_a:
moveRight = False
moveLeft = True
if event.key == K_RIGHT or event.key == K_d:
moveLeft = False
moveRight = True
if event.key == K_UP or event.key == K_w:
moveDown = False
moveUp = True
if event.key == K_DOWN or event.key == K_s:
moveUp = False
moveDown = True
if event.type == KEYUP:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == K_LEFT or event.key == K_a:
moveLeft = False
if event.key == K_RIGHT or event.key == K_d:
moveRight = False
if event.key == K_UP or event.key == K_w:
moveUp = False
if event.key == K_DOWN or event.key == K_s:
moveDown = False
if event.key == K_x:
player.top = random.randint(0, windowHeight-player.height)
player.left = random.randint(0, windowWidth-player.width)
if event.type == MOUSEBUTTONUP:
foods.append(pygame.Rect(event.pos[0], event.pos[1], 20, 20))
## Draw white background onto surface
windowSurface.fill(White)
## move player
if moveDown and player.bottom < windowHeight:
player.top += movespeed
if moveUp and player.top > 0:
player.top -= movespeed
if moveLeft and player.left >0:
player.left -= movespeed
if moveRight and player.right < windowWidth:
player.left += movespeed
# draw block image onto surface player object
windowSurface.blit(playerStretchedImage, player)
# check whether player has intersected with food squares
for food in foods[:]:
if player.colliderect(food):
foods.remove(food)
player = pygame.Rect(player.left, player.top,
player.width+2, player.height +2)
playerStretchedImage = pygame.transform.scale(playerImage,
(player.width, player.height))
# draw food
for food in foods:
windowSurface.blit(foodImage,food)
# draw window
pygame.display.update()
mainClock.tick(40)
python pygame
2
"I already tried using .png and .bmp extensions for the images" is a bit worrisome - are the images actually in those formats, or did you just rename the files without any format conversion?
– jasonharper
Jan 20 at 5:03
wow, thank you for letting me know--I didn't know about extensions like that not working. Thanks for the tip, I used imghdr package to check and it was a jpeg after all! I used Preview on Mac to convert to a png and now it works! Thank you again
– user6461080
Jan 21 at 7:33
add a comment |
I'm trying to download the images stored in a subdirectory called "images" in pygame, but I get the File is not a Windows BMP file. I am running python 2.7 in Spyder on a Mac OS. I have pygame.image.get_extended() = 1
so not sure what the issue is. My pygame doesn't seem corrupted as it can run fine without a png (tried out a different game). Been struggling to figure out a solution. I already tried using .png and .bmp extensions for the images. Thank you
# From Al Sweigart's book
import pygame, sys, time, random, os
from pygame.locals import *
print os.getcwd()
# set up pygame
pygame.init()
mainClock = pygame.time.Clock()
# Set up window
windowWidth = 400
windowHeight = 400
windowSurface = pygame.display.set_mode((windowWidth, windowHeight), 0, 32)
pygame.display.set_caption("Sprites and Sounds")
# Set up colors
white = (255,255,255)
# Set up block data structure
player = pygame.Rect(300, 100, 40, 40)
playerImage = pygame.image.load("images/ninja.bmp")
playerStretchedImage = pygame.transform.scale(playerImage, (40,40))
foodImage = pygame.image.load("images/apple.bmp")
foodStretchedImage = pygame.transform.scale(foodImage, (15,15))
foods =
for i in range(20):
foods.append(pygame.Rect(random.randint(0, windowWidth- 20),
random.randint(0, windowHeight-20), 20, 20))
foodCounter = 0
newfood = 40
# set up keyboard vars
moveLeft = False
moveRight = False
moveUp = False
moveDown = False
movespeed = 6
## Add sound here
# Run game loop
while True:
# check for quit event
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
# change keyboard variables
if event.key == K_LEFT or event.key == K_a:
moveRight = False
moveLeft = True
if event.key == K_RIGHT or event.key == K_d:
moveLeft = False
moveRight = True
if event.key == K_UP or event.key == K_w:
moveDown = False
moveUp = True
if event.key == K_DOWN or event.key == K_s:
moveUp = False
moveDown = True
if event.type == KEYUP:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == K_LEFT or event.key == K_a:
moveLeft = False
if event.key == K_RIGHT or event.key == K_d:
moveRight = False
if event.key == K_UP or event.key == K_w:
moveUp = False
if event.key == K_DOWN or event.key == K_s:
moveDown = False
if event.key == K_x:
player.top = random.randint(0, windowHeight-player.height)
player.left = random.randint(0, windowWidth-player.width)
if event.type == MOUSEBUTTONUP:
foods.append(pygame.Rect(event.pos[0], event.pos[1], 20, 20))
## Draw white background onto surface
windowSurface.fill(White)
## move player
if moveDown and player.bottom < windowHeight:
player.top += movespeed
if moveUp and player.top > 0:
player.top -= movespeed
if moveLeft and player.left >0:
player.left -= movespeed
if moveRight and player.right < windowWidth:
player.left += movespeed
# draw block image onto surface player object
windowSurface.blit(playerStretchedImage, player)
# check whether player has intersected with food squares
for food in foods[:]:
if player.colliderect(food):
foods.remove(food)
player = pygame.Rect(player.left, player.top,
player.width+2, player.height +2)
playerStretchedImage = pygame.transform.scale(playerImage,
(player.width, player.height))
# draw food
for food in foods:
windowSurface.blit(foodImage,food)
# draw window
pygame.display.update()
mainClock.tick(40)
python pygame
I'm trying to download the images stored in a subdirectory called "images" in pygame, but I get the File is not a Windows BMP file. I am running python 2.7 in Spyder on a Mac OS. I have pygame.image.get_extended() = 1
so not sure what the issue is. My pygame doesn't seem corrupted as it can run fine without a png (tried out a different game). Been struggling to figure out a solution. I already tried using .png and .bmp extensions for the images. Thank you
# From Al Sweigart's book
import pygame, sys, time, random, os
from pygame.locals import *
print os.getcwd()
# set up pygame
pygame.init()
mainClock = pygame.time.Clock()
# Set up window
windowWidth = 400
windowHeight = 400
windowSurface = pygame.display.set_mode((windowWidth, windowHeight), 0, 32)
pygame.display.set_caption("Sprites and Sounds")
# Set up colors
white = (255,255,255)
# Set up block data structure
player = pygame.Rect(300, 100, 40, 40)
playerImage = pygame.image.load("images/ninja.bmp")
playerStretchedImage = pygame.transform.scale(playerImage, (40,40))
foodImage = pygame.image.load("images/apple.bmp")
foodStretchedImage = pygame.transform.scale(foodImage, (15,15))
foods =
for i in range(20):
foods.append(pygame.Rect(random.randint(0, windowWidth- 20),
random.randint(0, windowHeight-20), 20, 20))
foodCounter = 0
newfood = 40
# set up keyboard vars
moveLeft = False
moveRight = False
moveUp = False
moveDown = False
movespeed = 6
## Add sound here
# Run game loop
while True:
# check for quit event
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
# change keyboard variables
if event.key == K_LEFT or event.key == K_a:
moveRight = False
moveLeft = True
if event.key == K_RIGHT or event.key == K_d:
moveLeft = False
moveRight = True
if event.key == K_UP or event.key == K_w:
moveDown = False
moveUp = True
if event.key == K_DOWN or event.key == K_s:
moveUp = False
moveDown = True
if event.type == KEYUP:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == K_LEFT or event.key == K_a:
moveLeft = False
if event.key == K_RIGHT or event.key == K_d:
moveRight = False
if event.key == K_UP or event.key == K_w:
moveUp = False
if event.key == K_DOWN or event.key == K_s:
moveDown = False
if event.key == K_x:
player.top = random.randint(0, windowHeight-player.height)
player.left = random.randint(0, windowWidth-player.width)
if event.type == MOUSEBUTTONUP:
foods.append(pygame.Rect(event.pos[0], event.pos[1], 20, 20))
## Draw white background onto surface
windowSurface.fill(White)
## move player
if moveDown and player.bottom < windowHeight:
player.top += movespeed
if moveUp and player.top > 0:
player.top -= movespeed
if moveLeft and player.left >0:
player.left -= movespeed
if moveRight and player.right < windowWidth:
player.left += movespeed
# draw block image onto surface player object
windowSurface.blit(playerStretchedImage, player)
# check whether player has intersected with food squares
for food in foods[:]:
if player.colliderect(food):
foods.remove(food)
player = pygame.Rect(player.left, player.top,
player.width+2, player.height +2)
playerStretchedImage = pygame.transform.scale(playerImage,
(player.width, player.height))
# draw food
for food in foods:
windowSurface.blit(foodImage,food)
# draw window
pygame.display.update()
mainClock.tick(40)
python pygame
python pygame
edited Jan 20 at 11:39
Rabbid76
37.1k113247
37.1k113247
asked Jan 20 at 3:34
user6461080user6461080
112
112
2
"I already tried using .png and .bmp extensions for the images" is a bit worrisome - are the images actually in those formats, or did you just rename the files without any format conversion?
– jasonharper
Jan 20 at 5:03
wow, thank you for letting me know--I didn't know about extensions like that not working. Thanks for the tip, I used imghdr package to check and it was a jpeg after all! I used Preview on Mac to convert to a png and now it works! Thank you again
– user6461080
Jan 21 at 7:33
add a comment |
2
"I already tried using .png and .bmp extensions for the images" is a bit worrisome - are the images actually in those formats, or did you just rename the files without any format conversion?
– jasonharper
Jan 20 at 5:03
wow, thank you for letting me know--I didn't know about extensions like that not working. Thanks for the tip, I used imghdr package to check and it was a jpeg after all! I used Preview on Mac to convert to a png and now it works! Thank you again
– user6461080
Jan 21 at 7:33
2
2
"I already tried using .png and .bmp extensions for the images" is a bit worrisome - are the images actually in those formats, or did you just rename the files without any format conversion?
– jasonharper
Jan 20 at 5:03
"I already tried using .png and .bmp extensions for the images" is a bit worrisome - are the images actually in those formats, or did you just rename the files without any format conversion?
– jasonharper
Jan 20 at 5:03
wow, thank you for letting me know--I didn't know about extensions like that not working. Thanks for the tip, I used imghdr package to check and it was a jpeg after all! I used Preview on Mac to convert to a png and now it works! Thank you again
– user6461080
Jan 21 at 7:33
wow, thank you for letting me know--I didn't know about extensions like that not working. Thanks for the tip, I used imghdr package to check and it was a jpeg after all! I used Preview on Mac to convert to a png and now it works! Thank you again
– user6461080
Jan 21 at 7:33
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54273372%2ffile-is-not-a-windows-bmp-file-but-i-have-pygame-image-get-extended-1%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54273372%2ffile-is-not-a-windows-bmp-file-but-i-have-pygame-image-get-extended-1%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
"I already tried using .png and .bmp extensions for the images" is a bit worrisome - are the images actually in those formats, or did you just rename the files without any format conversion?
– jasonharper
Jan 20 at 5:03
wow, thank you for letting me know--I didn't know about extensions like that not working. Thanks for the tip, I used imghdr package to check and it was a jpeg after all! I used Preview on Mac to convert to a png and now it works! Thank you again
– user6461080
Jan 21 at 7:33