[Gambas-user] Sample code to convert image to b/w image

Safiur Rahman isafiur at gmail.com
Sun Sep 17 04:02:11 CEST 2023


Application using gb.image, gb.image.effect and gb.media in addition to
gb.qt5

There are two controls for image:
Drawing Area (dwgVideo) and ImageView (ImageView1)

Private myPlayer As New MediaPlayer As "Player"

Public Sub Button1_Click()

  With myPlayer
    If .State = Media.Playing Then
      .Stop
    Endif
    .URL = "v4l2://" & ComboBox1.Text
    .SetWindow(dwgVideo)
    .Play()
  End With

End

'While adding values of Opacity or threshold there is error
Public Sub BtnTakeShot_Click()

  Dim ximage As Image

  If myPlayer.State <> Media.Playing Then Return
  ximage = myPlayer.Video.Image

  If chkopacity.Value Then
    ximage = ximage.Opacity(spnopacity.Value)
  Endif

  If chkthres.Value Then
    ximage.Threshold(spnthreshold.Value)
  Endif

  ImageView1.Image = ximage

End

Attached a sample project

On Sun, Sep 17, 2023 at 1:19 AM Safiur Rahman <isafiur at gmail.com> wrote:

> Hi
>
> I want to achieve the following black-in-white image output with
> Imagemagick with gambas
> $ convert old.png -alpha off -threshold 50% new.png
>
> Any sample code to achieve it?
>
> Also using Image.Opacity and Image.Threshold, I get following errors
>
> With Image.Opacity(50) I am getting error "The image must have an alpha
> channel"
> With Image.Threshold(0.5) the gambas crashed.
>
>
>
> --
> Regards
> Safiur Rahman
>


-- 
Regards
Safiur Rahman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230917/2f7de1ca/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.zip
Type: application/zip
Size: 15347 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230917/2f7de1ca/attachment-0001.zip>


More information about the User mailing list