iOS saves bmp with "Flip row order" format. Can this option be removed in Swift?
Asked Answered
B

1

0

UPDATE: When taking an iOS-created .bmp and using "Save As..." in Photoshop with "Flip row order" unchecked, this .bmp will then work on the Adafruit PyPortal (thanks John Park for this lead). I've searched in iOS and don't find anything that looks like a "Flip row order" command for bmp image data. Is anyone familiar with how to get iOS data into this "unflipped row order" format? Thanks! John

-- The 8-bit bmps I'm creating in Swift on an iOS device aren't showing on an Adafruit PyPortal, but when I run the same bmp (or any other 320 x 240 png or jpeg) through an online bmp converter, it then shows on the PyPortal. Both the before and after bmps are readable by Photoshop & Mac Preview and both show as 8-bit "Windows BMP Image" format files. PyPortal requires "a 320 x 240 pixel RGB 16-bit raster graphic in .bmp format" but going down to 8 bit doesn't make a difference. The bmp file that works (the one run through the online converter) shows on my Mac as a 231 KB file, while the bmp that doesn't (the one as created in Swift) shows as 230 KB.

I've put both files in a Google Drive at: https://drive.google.com/open?id=1DQYes-cJXKm3ue8Z9cACDLEN5bxnnkJc

The one that works (created in Swift, but then run through the bmp converter) is named: adafruit-log-as-iOS-created-bmp-then-converted-online-shows-in-PyPortal.bmp

And the one that doesn't work (just created in Swift) is named: adafruit-log-as-iOS-created.bmp (On Google Drive they both show as 225 KB files

The technique I use to create the bmp in Swift is the one employed when I answered the question at: How to convert UIImage to BMP and save as Data (not JPG or PNG)

and uses the helpful extension from @vasily-bodnarchuk via: Convert UIImage to NSData and convert back to UIImage in Swift?

When I run the files through a byte-by-byte comparison engine like https://www.diffnow.com show there are differences between the files.

I'm hopeful someone can quickly size up the difference between the formats of these two bmps and offer insight in getting the Swift code to create something that the Adafruit PyPortal can use. Thanks to anyone with the stamina to follow this far. Cheers!

Beaker answered 28/7, 2019 at 13:33 Comment(0)
T
1

I had a similar problem. I ended up editing the file with Paintbrush on the Mac and saving as a .PNG file. Then used python3 Pillow to reformat the image to a bitmap. To make this work you need to: 1) Create a PNG file in Paintbrush ( you can load an existing IOS or OSX bitmap file then save it as a PNG file in Pantbrush. 2) install Pillow: python3 -m pip install Pillow 3) Write a simple python3 program to convert the image e.g.:

from PIL import Image    # note Pillow is a fork of PIL but the Image object is in PIL
Image.open("pngFile.PNG").save("bitmapFile.bmp")

3) Run the program. This worked for me. Good luck.

This worked for me to edit bitmap files for PyPortal Titano.

Tailstock answered 23/1, 2020 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.