none
Faster way to remove alpha channel RRS feed

  • Question

  • Just out of curiosity, is there a faster way to remove the alpha channel from an image? This works well but is horribly slow...

      ImgPixels = LDImage.GetImagePixels(Img)
      For px = 1 To 640 
        TextWindow.WriteLine(px)
        For py = 1 To 360
           
          ImgPixels[px][py] = "#" + Text.GetSubTextToEnd(ImgPixels[px][py],4)
         
        EndFor
      EndFor 
       Img2 = LDImage.SetImagePixels(ImgPixels)


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, January 18, 2018 10:30 PM
    Answerer

Answers

  • Variant1:

    save the 32bit image as JPG (24bit) and load it again  (see LDImage.SaveAs)

    Variant2:

    use this ColorMatrix (is a Identity matrix with cm[4][4] = 0 and cm[5][4] = 1) :

      cm[1] = "1=1;2=0;3=0;4=0;5=0;"
      cm[2] = "1=0;2=1;3=0;4=0;5=0;"
      cm[3] = "1=0;2=0;3=1;4=0;5=0;"
      cm[4] = "1=0;2=0;3=0;4=0;5=0;"
      cm[5] = "1=0;2=0;3=0;4=1;5=1;"

    with

    LDImage.ColorMatrix(img, cm)

    (Test image, 32bit, 256x256)

    PS:

    ID: NFM659 (Variant2)


    Friday, January 19, 2018 12:33 AM
    Answerer

All replies

  • img= ImageList.LoadImage( LDDialogs.OpenFile("jpg","c:\"))
     ImgPixels = LDImage.GetImagePixels(Img)
     ImgPixels= LDText.Replace(ImgPixels,"#FF","#")
     TextWindow.WriteLine(ImgPixels)
    Thursday, January 18, 2018 11:28 PM
    Answerer
  • Hadn't thought of that.

    Unfortunately, the alpha isn't always 255 (FF) so that doesn't quite work.


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, January 18, 2018 11:39 PM
    Answerer
  • This seems to work well though: 
      ImgPixels = LDRegex.Replace(ImgPixels,"#[A-Z0-9][A-Z0-9]","#","False")


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, January 18, 2018 11:46 PM
    Answerer
  • Variant1:

    save the 32bit image as JPG (24bit) and load it again  (see LDImage.SaveAs)

    Variant2:

    use this ColorMatrix (is a Identity matrix with cm[4][4] = 0 and cm[5][4] = 1) :

      cm[1] = "1=1;2=0;3=0;4=0;5=0;"
      cm[2] = "1=0;2=1;3=0;4=0;5=0;"
      cm[3] = "1=0;2=0;3=1;4=0;5=0;"
      cm[4] = "1=0;2=0;3=0;4=0;5=0;"
      cm[5] = "1=0;2=0;3=0;4=1;5=1;"

    with

    LDImage.ColorMatrix(img, cm)

    (Test image, 32bit, 256x256)

    PS:

    ID: NFM659 (Variant2)


    Friday, January 19, 2018 12:33 AM
    Answerer
  • Yeah. Much faster that way.

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Friday, January 19, 2018 12:48 AM
    Answerer