Reading 2 colour BMP files

  1. 3 days ago

    dave d

    Mar 24 Pre-Release Testers, Xojo Pro Australia

    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?

  2. Jeff T

    Mar 24 Pre-Release Testers Midlands of England, Europe

    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

  3. 2 days ago

    dave d

    Mar 25 Pre-Release Testers, Xojo Pro Australia

    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.

  4. Julian S

    Mar 25 Pre-Release Testers, Xojo Pro UK

    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 ?

  5. Jeff T

    Mar 25 Pre-Release Testers Midlands of England, Europe

    Shame, was hoping there would be a solution to this

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

  6. 17 hours ago

    Tim J

    17 hours ago Pre-Release Testers, Xojo Pro N. Phoenix, AZ
    Edited 17 hours ago

    Try converting the original image from BMP to PNG.

  7. 9 hours ago

    dave d

    9 hours ago Pre-Release Testers, Xojo Pro Australia

    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

  8. 6 hours ago

    Jeff T

    6 hours ago Pre-Release Testers Midlands of England, Europe

    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 )

or Sign Up to reply!