Klaus
Nombre de messages : 12331 Age : 75 Localisation : Ile de France Date d'inscription : 29/12/2009
| Sujet: Re: 2.27 du 30 avril 2013: corr. bug dans ReplacePictureColor Mar 30 Avr 2013 - 19:12 | |
| Et voici une version complétée de mon ancien programme effets.bas. Ce programme applique l'ensemble des effets de la DLL à une image que l'on peut ensuite sauvegarder. J'ai ajouté la gestion de l'effet "remplacement de couleur" et "miroir". Pour le remplacement de couleur, il y a deux jeux de glissières pour déterminer la couleur à remplacer et la couleur à mettre en place. Chacune de ces deux groupes a un bouton "Pipette". Un clic sur un de ces boutons met le programme en mode "pipette". Le prochain clic dans l'image place alors la couleur du point du clic dans le sélecteur de couleur associé. Voici le code de 567 lignes: - Code:
-
' effets.bas
label labels : gosub labels gosub constantes gosub variables gosub form0 gosub menu gosub GUI gosub initialisations end
labels: label constantes, variables, menu, form0 label GUI, initialisations label ouvrir, sauver, sortir, purger, couper label gradient, change_debut, change_fin label gammas, brillance, gris, filtrer, change_filtre label outil1, outil2, click_picture label remp_debut, remp_fin, remplacer, pipette_debut, pipette_fin label miroir return
constantes: dim KGF$ : KGF$ = "C:\DOCUME~1\Klaus\MESDOC~1\MESPRO~3\KGF\KGF.dll" dim M1% : M1% = 0 - 1 dim M20% : M20% = 0-20 dim grad_type$ : grad_type$ = "LCPRB" dim tit_outil1$ : tit_outil1$ = "Générateur de bulles d'information" dim tit_outil2$ : tit_outil2$ = "Incruster des vignettes dans une image" dim nom_outil1$ : nom_outil1$ = "C:\DOCUME~1\Klaus\MESDOC~1\MESPRO~2\INFOBU~1\INFOBU~1.EXE" dim nom_outil2$ : nom_outil2$ = "C:\DOCUME~1\Klaus\MESDOC~1\MESPRO~2\INFOBU~1\INCRUS~1.EXE"
return variables: dim i%, w%,h%, R%, G%, B%, n%, f1$, f2$, s$ dim sta$, adresse$, c0$, c1$, present% dim no%, no1%, no2% dim no_open%, no_save%, no_image%, no_menu_effets% dim no_grad_x%, no_grad_y%, no_grad_type%, no_cont_grad% dim no_grad_debut%, no_grad_debut_R%, no_grad_debut_G%, no_grad_debut_B% dim no_grad_fin%, no_grad_fin_R%, no_grad_fin_G%, no_grad_fin_B% dim no_cont_gamma%, no_gamma%, no_gamma_wait%, no_cont_clip% dim no_clip_x0%, no_clip_y0%, no_clip_x1%, no_clip_y1%, x0%, x1%, y0%, y1% dim no_cont_bright%, no_bright%, no_bright_wait% dim no_cont_gris%, no_gris_wait% dim no_cont_filter%, no_filter_wait%, no_filter_r%, no_filter_g%, no_filter_b% dim no_filter%, no_filtre_r%, no_filtre_g%, no_filtre_b% dim no_remp_debut%, no_remp_fin%, no_miroir_wait% dim no_remp_debut_R%, no_remp_debut_G%, no_remp_debut_B%, no_cont_miroir% dim no_remp_fin_R%, no_remp_fin_G%, no_remp_fin_B%, no_remp_wait%, no_miroir% dim no_cont_rempl%, pipette% dim image_w%, image_h%, fact_w, fact_h return
form0: full_space 0 on_close 0,purger return
GUI: no% = no% + 1 : open_dialog no% : no_open% = no% filter no%,"Images|*.bmp;*.jpg" no% = no% + 1 : save_dialog no% : no_save% = no% filter no%,"Images|*.bmp"
no% = no% + 1 : picture no% : no_image% = no% top no%,10 : left no%,10 : stretch_on no% width no%,800 : height no%,460 on_click no%,click_picture no% = no% + 1 : container no% : no1% = no% : no_cont_grad% = no% width no%,400 : height no%,290 : inactive no% caption no%,"Dégradé de couleurs" top no%,10 : left no%,width(no_image%)+20 width no%,300 no% = no% + 1 : alpha no% : parent no%,no1% top no%,20 : left no%,20 : caption no%,"Point de référence X:" no% = no% + 1 : edit no% : parent no%,no1% : no_grad_x% = no% top no%,20 : left no%,130 : width no%,40 no% = no% + 1 : alpha no% : parent no%,no1% top no%,20 : left no%,190 : caption no%,"Y:" no% = no% + 1 : edit no% : parent no%,no1% : no_grad_y% = no% top no%,20 : left no%,210 : width no%,40 no% = no% + 1 : alpha no% : parent no%,no1% top no%,50 : left no%,20 : caption no%,"Type de dégradé" no% = no% + 1 : combo no% : parent no%,no1% : no_grad_type% = no% top no%,50 : left no%,130 : width no%,120 item_add no%,"par lignes" item_add no%,"par colonnes" item_add no%,"en rectangle" item_add no%,"en cercle" item_add no%,"en bulles" no% = no% + 1 : alpha no% : parent no%,no1% top no%,80 : left no%,20 : caption no%,"Couleur de début" no% = no% + 1 : picture no% : parent no%,no1% top no%,100 : left no%,10 : width no%,130 : height no%,150 no_grad_debut% = no% color no%,255,0,0 no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,110 : left no%,30 : min no%,0 : max no%,255 no_grad_debut_r% = no% position no%,255 : on_change no%,change_debut no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,110 : left no%,60 : min no%,0 : max no%,255 no_grad_debut_g% = no% position no%,0 : on_change no%,change_debut no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,110 : left no%,90 : min no%,0 : max no%,255 no_grad_debut_b% = no% position no%,0 : on_change no%,change_debut no% = no% + 1 : alpha no% : parent no%,no1% top no%,80 : left no%,170 : caption no%,"Couleur de fin" no% = no% + 1 : picture no% : parent no%,no1% top no%,100 : left no%,160 : width no%,130 : height no%,150 no_grad_fin% = no% color no%,255,0,0 no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,110 : left no%,180 : min no%,0 : max no%,255 no_grad_fin_r% = no% position no%,255 : on_change no%,change_fin no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,110 : left no%,210 : min no%,0 : max no%,255 no_grad_fin_g% = no% position no%,0 : on_change no%,change_fin no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,110 : left no%,240 : min no%,0 : max no%,255 no_grad_fin_b% = no% position no%,0 : on_change no%,change_fin no% = no% + 1 : button no% : parent no%,no1% top no%,260 : left no%,10 : caption no%,"Appliquer" on_click no%,gradient
no% = no% + 1 : container no% : no1% = no% : no_cont_gamma% = no% width no%,400 : height no%,70 : inactive no% caption no%,"Gamma" top no%,300 : left no%,width(no_image%)+20 width no%,300 no% = no% + 1 : check no% : parent no%,no1% : no_gamma% = no% width no%,200 : top no%,20 : left no%,10 caption no%,"Augmenter le Gamma (plus clair)" no% = no% + 1 : button no% : parent no%,no1% top no%,40 : left no%,10 : caption no%,"Appliquer" on_click no%,gammas no% = no% + 1 : alpha no% : parent no%,no1% : no_gamma_wait% = no% : hide no% top no%,40 : left no%,200 : caption no%,"Attendre svp..."
no% = no% + 1 : container no% : no1% = no% : no_cont_bright% = no% width no%,400 : height no%,70 : inactive no% caption no%,"Brillance" top no%,370 : left no%,width(no_image%)+20 width no%,300 no% = no% + 1 : check no% : parent no%,no1% : no_bright% = no% width no%,200 : top no%,20 : left no%,10 caption no%,"Augmenter la brillance" no% = no% + 1 : button no% : parent no%,no1% top no%,40 : left no%,10 : caption no%,"Appliquer" on_click no%,brillance no% = no% + 1 : alpha no% : parent no%,no1% : no_bright_wait% = no% : hide no% top no%,40 : left no%,200 : caption no%,"Attendre svp..."
no% = no% + 1 : container no% : no1% = no% : no_cont_gris% = no% width no%,400 : height no%,60 : inactive no% caption no%,"Niveaux de gris" top no%,440 : left no%,width(no_image%)+20 width no%,300 no% = no% + 1 : button no% : parent no%,no1% top no%,20 : left no%,10 : caption no%,"Appliquer" on_click no%,gris no% = no% + 1 : alpha no% : parent no%,no1% : no_gris_wait% = no% : hide no% top no%,20 : left no%,200 : caption no%,"Attendre svp..."
no% = no% + 1 : container no% : no1% = no% : no_cont_filter% = no% width no%,400 : height no%,220 : inactive no% caption no%,"Filtre par couleur" top no%,500 : left no%,width(no_image%)+20 width no%,300 no% = no% + 1 : picture no% : parent no%,no1% top no%,20 : left no%,10 : width no%,130 : height no%,160 no_filter% = no% color no%,255,0,0 no% = no% + 1 : check no% : parent no%,no1% : no_filter_r% = no% top no%,30 : left no%,25 : caption no%,"R" : width no%,25 no% = no% + 1 : check no% : parent no%,no1% : no_filter_g% = no% top no%,30 : left no%,55 : caption no%,"G" : width no%,25 no% = no% + 1 : check no% : parent no%,no1% : no_filter_b% = no% top no%,30 : left no%,85 : caption no%,"B" : width no%,25 no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,50 : left no%,30 : min no%,0 : max no%,255 no_filtre_r% = no% position no%,255 : on_change no%,change_filtre no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,50 : left no%,60 : min no%,0 : max no%,255 no_filtre_g% = no% position no%,0 : on_change no%,change_filtre no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,50 : left no%,90 : min no%,0 : max no%,255 no_filtre_b% = no% position no%,0 : on_change no%,change_filtre no% = no% + 1 : button no% : parent no%,no1% top no%,190 : left no%,10 : caption no%,"Appliquer" on_click no%,filtrer no% = no% + 1 : alpha no% : parent no%,no1% : no_filter_wait% = no% : hide no% top no%,190 : left no%,200 : caption no%,"Attendre svp..."
no% = no% + 1 : container no% : no1% = no% : no_cont_clip% = no% width no%,120 : height no%,200 : inactive no% caption no%,"Extraire rectangle" top no%,10 : left no%,left(no_cont_grad%)+width(no_cont_grad%)+10 no% = no% + 1 : alpha no% : parent no%,no_cont_clip% top no%,20 : left no%,10 : caption no%,"X0:" no% = no% + 1 : edit no% : parent no%,no_cont_clip% : no_clip_x0% = no% top no%,20 : left no%,40 : width no%,50 no% = no% + 1 : alpha no% : parent no%,no_cont_clip% top no%,50 : left no%,10 : caption no%,"Y0:" no% = no% + 1 : edit no% : parent no%,no_cont_clip% : no_clip_y0% = no% top no%,50 : left no%,40 : width no%,50 no% = no% + 1 : alpha no% : parent no%,no_cont_clip% top no%,90 : left no%,10 : caption no%,"X1:" no% = no% + 1 : edit no% : parent no%,no_cont_clip% : no_clip_x1% = no% top no%,90 : left no%,40 : width no%,50 no% = no% + 1 : alpha no% : parent no%,no_cont_clip% top no%,120 : left no%,10 : caption no%,"Y1:" no% = no% + 1 : edit no% : parent no%,no_cont_clip% : no_clip_y1% = no% top no%,120 : left no%,40 : width no%,50 no% = no% + 1 : button no% : parent no%,no_cont_clip% top no%,160 : left no%,10 : caption no%,"Couper" on_click no%,couper no% = no% + 1 : container no% : no1% = no% : no_cont_rempl% = no% width no%,310 : height no%,260 : inactive no% caption no%,"Remplacer une couleur" top no%,top(no_image%)+height(no_image%)+10 : left no%,10 no% = no% + 1 : alpha no% : parent no%,no1% top no%,20 : left no%,20 : caption no%,"Couleur à remplacer" no% = no% + 1 : picture no% : parent no%,no1% top no%,40 : left no%,10 : width no%,130 : height no%,150 no_remp_debut% = no% color no%,255,0,0 no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,50 : left no%,30 : min no%,0 : max no%,255 no_remp_debut_r% = no% position no%,255 : on_change no%,remp_debut no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,50 : left no%,60 : min no%,0 : max no%,255 no_remp_debut_g% = no% position no%,0 : on_change no%,remp_debut no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,50 : left no%,90 : min no%,0 : max no%,255 no_remp_debut_b% = no% position no%,0 : on_change no%,remp_debut no% = no% + 1 : alpha no% : parent no%,no1% top no%,20 : left no%,170 : caption no%,"Nouvelle couleur" no% = no% + 1 : picture no% : parent no%,no1% top no%,40 : left no%,160 : width no%,130 : height no%,150 no_remp_fin% = no% color no%,255,0,0 no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,50 : left no%,180 : min no%,0 : max no%,255 no_remp_fin_r% = no% position no%,255 : on_change no%,remp_fin no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,50 : left no%,210 : min no%,0 : max no%,255 no_remp_fin_g% = no% position no%,0 : on_change no%,remp_fin no% = no% + 1 : scroll_bar no% : parent no%,no1% : vertical no% top no%,50 : left no%,240 : min no%,0 : max no%,255 no_remp_fin_b% = no% position no%,0 : on_change no%,remp_fin no% = no% + 1 : alpha no% : parent no%,no1% : no_remp_wait% = no% : hide no% top no%,40 : left no%,110 : caption no%,"Attendre svp..." no% = no% + 1 : button no% : parent no%,no1% top no%,200 : left no%,10 : caption no%,"Pipette" on_click no%,pipette_debut no% = no% + 1 : button no% : parent no%,no1% top no%,200 : left no%,215 : caption no%,"Pipette" on_click no%,pipette_fin no% = no% + 1 : button no% : parent no%,no1% top no%,230 : left no%,110 : caption no%,"Appliquer" on_click no%,remplacer
no% = no% + 1 : container no% : no1% = no% : no_cont_miroir% = no% width no%,130 : height no%,100 : inactive no% caption no%,"Appliquer un effet miroir" top no%,top(no_image%)+height(no_image%)+10 : left no%,left(no_cont_rempl%)+width(no_cont_rempl%)+10 no% = no% + 1 : check no% : parent no%,no1% : no_miroir% = no% top no%,20 : left no%,10 : caption no%,"Miroir vertical" no% = no% + 1 : alpha no% : parent no%,no1% : no_miroir_wait% = no% : hide no% top no%,40 : left no%,10 : caption no%,"Attendre svp..." no% = no% + 1 : button no% : parent no%,no1% top no%,50 : left no%,10 : caption no%,"Appliquer" on_click no%,miroir
return
initialisations: dll_on KGF$ i% = dll_call1("SetImmediateMode",1) text no_clip_x0%,"0" text no_clip_y0%,"0" text no_clip_x1%,"100" text no_clip_y1%,"100" return menu: no% = no% + 1 : main_menu no% : no1% = no% no% = no% + 1 : sub_menu no% : parent no%,no1% : no2% = no% caption no%,"Fichier" no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Ouvrir" : on_click no%,ouvrir no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Enregistrer" : on_click no%,sauver no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"-------------" no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Sortir" : on_click no%,sortir
no% = no% + 1 : sub_menu no% : parent no%,no1% : no2% = no% caption no%,"Effets" : inactive no% : no_menu_effets% = no% no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Gradient" : on_click no%,gradient no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Gamma" : on_click no%,gammas no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Brillance" : on_click no%,brillance no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Niveaux de gris" : on_click no%,gris no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Filtre de couleurs" : on_click no%,filtrer no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Remplacer une couleur" : on_click no%,remplacer no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Effet miroir" : on_click no%,miroir no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Extraire un rectangle" : on_click no%,couper
no% = no% + 1 : sub_menu no% : parent no%,no1% : no2% = no% caption no%,"Outils" no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Info_bulle" : on_click no%,outil1 no% = no% + 1 : sub_menu no% : parent no%,no2% caption no%,"Incruster" : on_click no%,outil2
return ouvrir: f1$ = file_name$(no_open%) if f1$="_" then return file_load no_image%,f1$ clipboard_copy no_image% pause 500 i% = dll_call0("LoadPicture") image_w% = dll_call0("GetPictureWidth") image_h% = dll_call0("GetPictureHeight") fact_w = image_w%/width(no_image%) fact_h = image_h%/height(no_image%) present% = 1 active no_menu_effets% active no_cont_grad% active no_cont_gamma% active no_cont_bright% active no_cont_gris% active no_cont_filter% active no_cont_clip% active no_cont_rempl% active no_cont_miroir% return
sauver: if present%=0 message "Il n'y a pas d'image à enregistrer" return end_if f2$ = file_name$(no_save%) if f2$="_" then return if f2$="" then return if lower$(right$(f2$,4))<>".bmp" then f2$ = f2$ + ".bmp" if file_exists(f2$) s$ = "Le fichier "+f2$+"existe. Voulez_vous le remplacer ?" if message_confirmation_yes_no(s$)<>1 then return end_if file_save no_image%,f2$ return sortir: if present%=1 s$ = "Voulez-vous vraiment quitter le programme ?" if message_confirmation_yes_no(s$)<>1 then return end_if purger: if present%=1 i%=dll_call0("SavePicture") pause 3 end_if dll_off terminate change_debut: color no_grad_debut%,position(no_grad_debut_R%),position(no_grad_debut_G%),position(no_grad_debut_B%) return
change_fin: color no_grad_fin%,position(no_grad_fin_R%),position(no_grad_fin_G%),position(no_grad_fin_B%) return
remp_debut: color no_remp_debut%,position(no_remp_debut_R%),position(no_remp_debut_G%),position(no_remp_debut_B%) return
remp_fin: color no_remp_fin%,position(no_remp_fin_R%),position(no_remp_fin_G%),position(no_remp_fin_B%) return
gradient: if item_index(no_grad_type%)=0 message "Il faut choisir le type de dégradé." return end_if sta$ = mid$(grad_type$,item_index(no_grad_type%),1) adresse$ = text$(no_grad_x%)+","+text$(no_grad_y%) c0$ = str$(position(no_grad_debut_R%)) c0$ = c0$ + "," + str$(position(no_grad_debut_G%)) c0$ = c0$ + "," + str$(position(no_grad_debut_B%)) ' c0$ = "240,237,23" c1$ = "16,46,216" i% = dll_call4("CreatePictureGradientColor",adr(sta$),adr(adresse$),adr(c0$),adr(c1$)) pause 300 clipboard_paste no_image% return
gammas: show no_gamma_wait% display inactive no_cont_gamma% n% = checked(no_gamma%) i% = dll_call1("SetPictureGamma",n%) pause 300 clipboard_paste no_image% active no_cont_gamma% hide no_gamma_wait% return
brillance: show no_bright_wait% display inactive no_cont_bright% i% = M20% if checked(no_bright%)=1 then i% = 0 - M20% i% = dll_call1("SetPictureBrightness",i%) pause 300 clipboard_paste no_image% active no_cont_bright% hide no_bright_wait% return
gris: show no_gris_wait% display inactive no_cont_gris% i% = dll_call0("SetPictureGrayScale") pause 300 clipboard_paste no_image% active no_cont_gris% hide no_gris_wait% return
filtrer: show no_filter_wait% display inactive no_cont_filter% r% = m1% : g% = m1% : b% = m1% if checked(no_filter_r%)=1 then r% = position(no_filtre_R%) if checked(no_filter_g%)=1 then g% = position(no_filtre_G%) if checked(no_filter_b%)=1 then b% = position(no_filtre_B%) i% = dll_call3("SetPictureFilter",r%,g%,b%) pause 300 clipboard_paste no_image% active no_cont_filter% hide no_filter_wait% return
change_filtre: r% = position(no_filtre_R%) g% = position(no_filtre_G%) b% = position(no_filtre_B%) color no_filter%,r%,g%,b% return couper: x0% = int(val(text$(no_clip_x0%))) y0% = int(val(text$(no_clip_y0%))) x1% = int(val(text$(no_clip_x1%))) y1% = int(val(text$(no_clip_y1%))) i% = dll_call4("ExtractRectangleFromPicture",x0%,y0%,x1%,y1%) pause 300 clipboard_paste no_image% return
outil1: if handle_form(tit_outil1$)= 0 then execute nom_outil1$ return outil2: if handle_form(tit_outil2$)= 0 then execute nom_outil2$ return click_picture: if pipette%>0 then extraire_couleur() pipette% = 0 return pipette_debut: pipette% = 1 return pipette_fin: pipette% = 2 return remplacer: if position(no_remp_debut_R%)=position(no_remp_fin_R%) if position(no_remp_debut_G%)=position(no_remp_fin_G%) if position(no_remp_debut_B%)=position(no_remp_fin_B%) message "C'est la même couleur !" return end_if end_if end_if show no_remp_wait% display inactive no_cont_rempl% i% = dll_call6("ReplacePictureColor",position(no_remp_debut_R%),position(no_remp_debut_G%),position(no_remp_debut_B%),position(no_remp_fin_R%),position(no_remp_fin_G%),position(no_remp_fin_B%)) pause 300 clipboard_paste no_image% active no_cont_rempl% hide no_remp_wait% return miroir: show no_miroir_wait% display inactive no_cont_miroir% i% = dll_call1("MirrorPicture",checked(no_miroir%)+1) pause 300 clipboard_paste no_image% active no_cont_miroir% hide no_miroir_wait% return
sub extraire_couleur() dim_local x%, y%, r%, g%, b% x% = mouse_x_left_down(no_image%)*fact_w y% = mouse_y_left_down(no_image%)*fact_h r% = color_pixel_red(no_image%,x%,y%) g% = color_pixel_green(no_image%,x%,y%) b% = color_pixel_blue(no_image%,x%,y%) if pipette%=1 position no_remp_debut_R%,r% position no_remp_debut_G%,g% position no_remp_debut_B%,b% else position no_remp_fin_R%,r% position no_remp_fin_G%,g% position no_remp_fin_B%,b% end_if end_sub
| |
|