获取图像模式PIL Python

时间:2015-11-20 16:31:17

标签: python image python-imaging-library blending

我正在尝试将两个图像混合在一起,但我一直收到一个错误,其中一个图像处于错误模式。我尝试转换此图像,但我尝试过的每种模式都会使整个图像变白。有没有一种方法在Python中使用PIL模块来找出当前的图像模式是什么?

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include <semaphore.h>
#include <errno.h>



void *write(void *t)
{   char str[100]  = "\0";
    char str1[50];
    key_t key;
    char *shmptr;
    int shmid;
    if( (key = ftok("shmSemphore.c",'B')) == -1)
    {
        perror("ftok in writer");
        pthread_exit(NULL);
    }
    if( (shmid = shmget(key, 1024, 0666 | IPC_CREAT)) == -1)
    {
        perror("shmget in writer");
        pthread_exit(NULL);
    }
    shmptr = shmat(shmid,0,0);
    if( (shmptr == (char *)(-1)))
    {
        perror("shmget in writer");
        pthread_exit(NULL);
    }
    printf("ENter your text :- ");
    //scanf("%s",str);
    fgets(str,sizeof(str),stdin);   
    strcpy(shmptr,str);
    sleep(2);
    shmdt(shmptr);
    if( shmctl(shmid, IPC_RMID, NULL) == -1 )
    {
        perror("shmctl");
        exit(-1);
    }
    pthread_exit(NULL);
}

void *read(void *t)
{   sleep(2);
    key_t key;
    char *shmptr;
    int shmid;
    if( (key = ftok("shmSemphore.c",'B')) == -1)
    {
        perror("ftok in writer");
        pthread_exit(NULL);
    }
    if( (shmid = shmget(key, 1024, 0)) == -1)
    {
        perror("shmget in reader");
        pthread_exit(NULL);
    }
    shmptr = shmat(shmid,0,0);
    if( (shmptr == (char *)-1))
    {
        perror("shmget in writer");
        pthread_exit(NULL);
    }
    printf("your text:- %s \n",shmptr);
    pthread_exit(NULL);
}

int main()
{
    pthread_t reader,writer;
    int rt;
    long t = 0;
    rt = pthread_create(&writer,NULL,write,(void *)t);
    /*if(rt == -1)
    {   perror("writer thread");
        pthread_exit(NULL);
    }*/
    rt = pthread_create(&reader,NULL,read,(void *)t);
    /*if(rt == -1)
    {   perror("writer thread");
        pthread_exit(NULL);
    }*/
    pthread_join(writer,NULL);
    pthread_join(reader,NULL);
    return 0;
}

错误讯息: Image.blend(img ,im ,0.05)

1 个答案:

答案 0 :(得分:6)

请参阅文档中的Image Attributes

  

im.modestring

     

图像模式。这是一个字符串,指定图像使用的像素格式。典型值为'1''L''RGB''CMYK.'有关完整列表,请参阅Concepts

Image.convert方法从现有图片中创建具有给定Image的新mode