简体   繁体   中英

pygame.error in loading image

My pygame code

bif="images.jpg"
mif="point.png"
import pygame, sys
from pygame.locals import *

pygame.init()
screen=pygame.display.set_mode((640,360),0,32)
background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()
while True:
        for event in pygame.event.get():
                if event.type == QUIT:
                        pygame.quit()
                        sys.exit()
        screen.blit(background, (0,0))

Error message

Traceback (most recent call last):
  File "game.py", line 8, in <module>
    background=pygame.image.load(bif).convert()
pygame.error: File is not a Windows BMP file

I tried this link but this is also not working

Why are my pygame images not loading?

From pygame documentation :

By default it can only load uncompressed BMP images. When built with full image support, the pygame.image.load() function can support the following formats. JPG ...

So, if you want JPG and PNG images, you have to build with full image support.

I highly doubt this will fix your problem, however if anyone else has this exact issue, I want them to see it, as it happened to me, from using a Python version on Microsoft Marketplace.

If it cannot find images specfically, however can once you type the entire path. Meaning a python script cannot find images in the exact same directory and even folder it may be related to something very random, I have not saw on any answers, or even close.

In window there is a .dll file named FileSyncShell64.dll this can go missing, and cause an idle.exe - Bad Image when saving depending on where Python is, and what version and other things. The point is it is the OS that needs the file. So find the correct file on google and place it in the correct spot, if you get an error message when saving it will have the address of where it was or should be. This happened to me somehow, because for some reason the Marketplace put Python in a OneDrive folder, followed by a number DNS or IP it seems, then amd64 when the .dll that is missing.

Just letting anyone know who is having trouble if they already exhausted every other method, like adding the compelete path, maing sure the images are located in the correct spot, making sure python is in Path and everything else possible, this is a rare fix, however none the less it apparently happens. Causing only entire addresses to work when doing anything with any file location, making everything a nightmare, for a possible long time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM