Reading 2 colour BMP files

I cannot seem to load a 2 colour bmp file, code is

Var f As New FolderItem(“3.bmp”, FolderItem.PathModes.Native)
Var pic as picture
If f <> Nil And f.Exists Then
pic=picture.Open(f)
end if
pic.Graphics.DrawText(“test”,40,40,100)

Var ff As New FolderItem(“4.bmp”, FolderItem.PathModes.Native)
// Save the image out to the file
pic.Save(ff, Picture.Formats.BMP)

I am trying to load write some text on it and save it. But I get a NOE on pic=picture.Open(f) the file exists and is a valid 2 colour bmp?

Anyone any ideas?

Xojo hasn’t supported 2 color pictures for many years, annoyingly.
BUT: check whether pic is nil after the Open() statement
if it is not,
Create a new picture in memory, and draw pic to it

dim pic2 as new picture (pic.width,pic.height)

pic2.drawpicture pic,0,0
pic2.Graphics.DrawText("test",40,40,100)

Than save pic2

It’s to update a paperwhite display on pi, so it needs to be 2 col! Shame, was hoping there would be a solution to this.

I can open a 2 color bmp here in windows, not sure about pi, maybe someone can check who has one set up and running?

Is this a console app on the pi ?

But have you tried the code above?
Is pic nil immediately after the picture.open() or not?

Try converting the original image from BMP to PNG.

problem is, the pi paper white screen wont read a png it needs a 2 colour bmp, and unless I use some third party plugin there is no way to get it in and out of Xojo

Is the original one compressed?
If it is not, the 2-color image will be represented in the file as a fairly simple byte array.

if you create a picture in memory of the right size, and draw text on that, you MIGHT succeed in loading the BMP into memory, then setting bytes of the image array, based on the color of pixels in your rendered picture.

For example, the first few bytes of a BMP file should be:

2bytes : holds 'BM' 4bytes: ignore 4bytes: ignore 4bytes: start of the pixel array in the file /memoryblock

https://en.wikipedia.org/wiki/BMP_file_format#Pixel_array_(bitmap_data)