Convert full RGBA to grayscale

  1. ‹ Older
  2. 7 months ago

    Graham B

    11 Feb 2019 Pre-Release Testers, Xojo Pro The Canada's

    Einhugur plugin has the picture effects classes which allow you to chain together filters to convert to grayscale. You covert the picture to a raw data class, run all your effects and then get your finial image. It runs nice an fast and apparently can use up to 8 cores.

  3. Christian S

    11 Feb 2019 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    Whatever you have in Xojo, the plugins will be easily several times faster.

  4. Björn E

    12 Feb 2019 Pre-Release Testers, Xojo Pro Iceland

    @Tim J Einhugur

    You can read the PNG directly with GraphicsFormats and use PictureEffectsRaw to do the Grayscale conversion, with option of several variations of grayscale methods. You can do this all synchronous or asynchronous. TypeLibs RawBitmapConverter if at any point in the process you need it in Xojo Picture Object.

  5. Tim J

    12 Feb 2019 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    The good news is that I'm dealing with 16x16, 22x22, 26x26, 32x32, and 48x48 PNG files so all of these are fast.

    Thanks to everyone and I look forward to seeing Dave's transform code!

  6. Dave S

    12 Feb 2019 San Diego, California USA

    @Tim J Thanks to everyone and I look forward to seeing Dave's transform code!

    my bad. My Paint program scans an RGBSurface to do grayscale, sepia and color reduction ... it uses the RGBSurface.Transform function for altering Brightness, Contrast and Exposure

  7. Tim J

    12 Feb 2019 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    For @ChristianSchmitz - the GrayScaleMBS(3) is giving the best result for these images. But ...

    When I set it to the RowPicture, the mask or alpha are being ignored.

    I've tried using both CopyPictureWithMask and CopyPictureWithAlpha when creating the Picture, but the result always has a black background when I set the RowPicture (using GrayScaleMBS(3) doesn't matter either way):

    -image-

    The code looks like this when using the IconMBS picture (leaf is a folderitem):

    Me.RowPicture(Me.LastIndex) = leaf.IconMBS(20).GrayScaleMBS(3)

    And like this when using the NSImageMBS:

    Dim i As NSImageMBS = NSWorkspaceMBS.iconForFileType("fcpxml")
    lbBackupFileSystem.RowPicture(lbBackupFileSystem.LastIndex) = i.CopyPictureWithMask.ScaleMBS(20, 20, True).GrayScaleMBS(3)

    Any ideas?

  8. Christian S

    12 Feb 2019 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    the scale function only works on the main picture, not it's mask.
    you may need to assign the original mask to the new picture.

  9. Tim J

    12 Feb 2019 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    I can understand that when I'm building the picture from the NSImageMBS, but what about the IconMBS call where I'm not scaling the picture returned?

  10. Christian S

    12 Feb 2019 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    well, you got picture form IconMBS and maybe you should put it in variable.
    Than check for nil and call GrayScaleMBS on it.
    Than move the mask from the old picture to the new picture.

  11. Tim J

    12 Feb 2019 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    Hmm, I can get this sorted on the Mac side, but for Linux, LinuxIconMBS.FileIcon(f, 32) is returning a picture without a mask, so trying to get the mask from the icon fails with an UnsupportedFormatException with a message stating that you can't copy a mask from an image with an alpha channel, but the Picture returned doesn't have an alpha channel.

    Calling the Linux code like this:

    iconPic = LinuxIconMBS.FileIcon(leaf, 32)
  12. Christian S

    12 Feb 2019 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    That is strange.

    -image-

    The screenshot looks like the pictures got some alpha channel here!?

  13. Tim J

    12 Feb 2019 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    The Alpha is there on mine as well if I accept the 48x48 image. It's the scaling that's causing the issue and loss of the alpha.

  14. Tim J

    12 Feb 2019 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    It's something in the way the Xojo paints the picture into the RowPicture of a Listbox when you manage the CellBackgroundPaint instead of using defaults.

  15. Dim surf As RGBSurface = picture.RGBSurface
    Dim c As Color
    Dim w As Integer = picture.Width - 1
    Dim h As Integer = picture.Height - 1
    Dim cg As Integer // color grey
    rem farbe in graustufen wandeln
    For y As Integer = 0 To h
    For x As Integer = 0 To w
    c = surf.Pixel(x, y)
    cg=(c.red +c.green + c. blue )/3
    surf.Pixel(x, y) = RGB(cg,cg,cg)
    Next
    Next

    ready

  16. rem listbox 10* addrow =" "
    myicon= New Picture(100,40,32)
    myicon.Graphics.DrawPicture picture,40,0,60,40,0,0,bogenneu2.Width,bogenneu2.Height
    listbox1.RowPicture(1) =myicon

  17. Tim J

    13 Feb 2019 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    More details on the MBS solution -

    Using the MBS Picture.ScaleImageAndMaskMBS() function properly results in an image with a correctly maintained mask/alpha.

    It's now down to the GrayScaleMBS() function.

  18. Tim J

    13 Feb 2019 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    Two issues with MBS -

    GrayScaleMBS() loses the alpha/mask on all three platforms
    LinuxIconMBS.FileIcon() is messing up the alpha/Mask when scaling such that it's not processed properly by Xojo's ListBox.RowPicture().

  19. Christian S

    13 Feb 2019 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    Create a new picture in Xojo, draw the icon picture there scaled and than use the new picture.

  20. Tim P

    13 Feb 2019 Pre-Release Testers Rochester, NY

    @Tim J GrayScaleMBS() loses the alpha/mask on all three platforms

    This is noted in the documentation (and isn't new)

  21. Tim J

    13 Feb 2019 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    @Christian Schmitz Create a new picture in Xojo, draw the icon picture there scaled and than use the new picture.

    Tried that. It seems that even using CopyPictureAndAlphaMBS() under Linux is not retaining the Alpha channel - or maybe I'm misunderstanding the procedure you're describing.

    @Tim P This is noted in the documentation (and isn't new)

    Except I'm not using a mask, but PNG files with an alpha channel. There is no mask to copy.

or Sign Up to reply!