Import a PNG file?

  1. 6 months ago

    Open a PNG file?

    My hope is to start with a PNG file on storage, then open it into an app as a picture and to then extract the pixels from the picture. I have tried the following function:

    Dim picFile As FolderItem
    Dim clr as Color
    Dim pic As Picture
    Dim c, r, pwd, pht as integer

    Dim pngType As New FileType
    pngType.Name = "image/png"
    pngType.MacType = "PNGf"
    pngType.Extensions = ".png"

    picFile = GetOpenFolderItem(pngType)

    If picFile <> Nil Then
    pic = Picture.Open(picFile)
    pwd = pic.Width
    pht = pic.Height
    ReDim mypixels(pwd, pht) // mypixels is global
    dim rs as RGBSurface = pic.RGBSurface
    for c = 0 to pwd - 1
    for r = 0 to pht - 1
    mypixels(c, r) = rs.pixel(c, r)
    End If

    Return True

    What happens: When mypixels are drawn only the upper left quarter of the PNG appears. And pic has a nil Graphics property (so no Graphics.pixel).

  2. Emile S

    19 Dec 2018 Europe (France, Strasbourg)
    Edited 6 months ago

    @Daniel L When mypixels are drawn

    Where: you do not display code for that.

    @Daniel Lamet And pic has a nil Graphics property

    How do you know Graphics is Nil ?

    Start to attribute the loaded image into a Canvas, then ma,nipulate it and display the new contents (elsewhere), so you have better chances to know where there is a trouble (if any).

    At compile time, there is an error on: mypixels(c, r) is not an array: How do you declare it ?

or Sign Up to reply!