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

vuott at tutanota.com vuott at tutanota.com
Mon Sep 18 18:24:45 CEST 2023


« Also using Image.Opacity and Image.Threshold, I get following errors »

The notice says you need to obtain data image with Alpha channel (like RGBA).
It seems that you can solve it by converting the "Image" Object to a "Picture" and then converting the "Picture" back to an "Image" Object.
You also need to divide the values of both "Spinbox" by 100 to get a float value.

Ehmmm... so, I suggest:
[code]
......
If myPlayer.State <> Media.Playing Then Return
ximage = myPlayer.Video.Image.Picture.Image

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

If chkthres.Value Then
  ximage.Threshold(spnthreshold.Value / 100)
Endif
......
[/code]




17 set 2023, 04:03 da isafiur at gmail.com:

> 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/20230918/12e5ffe1/attachment.htm>


More information about the User mailing list