Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:54:37+00:00 2026-06-18T09:54:37+00:00

In Python the string: a = ‘00001111\n00110011\n00110101\n…..’ How would I convert that to an

  • 0

In Python the string:

a = '00001111\n00110011\n00110101\n.....'

How would I convert that to an image of let’s say 8×8 pixels where 0 stands for black and 1 stands for white. Is the route to study for example BMP and make a BMP file from it. Or are there smoother roads to enlightenment?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:54:38+00:00Added an answer on June 18, 2026 at 9:54 am

    The first step is to convert your string to a sequence of bytes containing the proper values:

    pixel_value = {'0': 0, '1': 255}
    byte_seq = ''.join(chr(pixel_value[c]) for c in a if c in pixel_value)
    

    Then use PIL’s Image.fromstring to convert it to an image:

    from PIL import Image
    im = Image.fromstring('L', (8, 8), byte_seq)
    im.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a standard Python string (such as one obtained from raw_input()
I have some code in a python string that contains extraneous empty lines. I
Python is doing string multiplication where I would expect it to do numeric multiplication,
I have a string in Python 2.7.2 say u\u0638. When I write it to
How can I remove duplicate characters from a string using Python? For example, let's
I want to convert Python string to URL syntax. For example >>> u'한글'.encode('utf-8') '\xed\x95\x9c\xea\xb8\x80'
What would the best way of unpacking a python string into fields I have
Possible Duplicate: Convert XML/HTML Entities into Unicode String in Python Decode HTML entities in
I need to convert the Python string Mon Aug 29 2011 18:30:00 GMT+0530 (IST)
I've got a python string like this 2012/04/08 13:31:00 UTC How can I convert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.