C#图片加水印实例与代码
本文要提供的类可以为图片加文字水印,以及判断是否是图片文件。经过测试可运行,例子请下载:http://hovertree.com/h/bjaf/5qc5eh6y.htm 例子效果图: 以下是HovercWarter类的代码: 1 using System.Drawing; 2 using System.Drawing.Imaging; 3 using Syst
本文要提供的类可以为图片加文字水印,以及判断是否是图片文件。经过测试可运行,例子请下载:http://hovertree.com/h/bjaf/5qc5eh6y.htm
例子效果图:
以下是HovercWarter类的代码:
<span style="color: #008080;"> 1</span> <span style="color: #0000ff;">using</span><span style="color: #000000;"> System.Drawing; </span><span style="color: #008080;"> 2</span> <span style="color: #0000ff;">using</span><span style="color: #000000;"> System.Drawing.Imaging; </span><span style="color: #008080;"> 3</span> <span style="color: #0000ff;">using</span><span style="color: #000000;"> System.IO; </span><span style="color: #008080;"> 4</span> <span style="color: #008080;"> 5</span> <span style="color: #0000ff;">namespace</span><span style="color: #000000;"> HoverTreeBatch.HovercFrame </span><span style="color: #008080;"> 6</span> <span style="color: #000000;">{ </span><span style="color: #008080;"> 7</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> HovercWarter </span><span style="color: #008080;"> 8</span> <span style="color: #000000;">{ </span><span style="color: #008080;"> 9</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> Image AddTextToImg(Image image, <span style="color: #0000ff;">string</span><span style="color: #000000;"> text) </span><span style="color: #008080;">10</span> <span style="color: #000000;">{ </span><span style="color: #008080;">11</span> Bitmap bitmap = <span style="color: #0000ff;">new</span><span style="color: #000000;"> Bitmap(image, image.Width, image.Height); </span><span style="color: #008080;">12</span> Graphics g =<span style="color: #000000;"> Graphics.FromImage(bitmap); </span><span style="color: #008080;">13</span> <span style="color: #008080;">14</span> <span style="color: #0000ff;">float</span> fontSize = <span style="color: #800080;">12.0f</span>; <span style="color: #008000;">//</span><span style="color: #008000;">字体大小</span> <span style="color: #008080;">15</span> <span style="color: #0000ff;">float</span> textWidth = text.Length * fontSize; <span style="color: #008000;">//</span><span style="color: #008000;">文本的长度 </span><span style="color: #008080;">16</span> <span style="color: #008000;">//</span><span style="color: #008000;">下面定义一个矩形区域,以后在这个矩形里画上白底黑字</span> <span style="color: #008080;">17</span> <span style="color: #0000ff;">float</span> rectX = <span style="color: #800080;">0</span><span style="color: #000000;">; </span><span style="color: #008080;">18</span> <span style="color: #0000ff;">float</span> rectY = <span style="color: #800080;">0</span><span style="color: #000000;">; </span><span style="color: #008080;">19</span> <span style="color: #0000ff;">float</span> rectWidth = text.Length * (fontSize + <span style="color: #800080;">8</span><span style="color: #000000;">); </span><span style="color: #008080;">20</span> <span style="color: #0000ff;">float</span> rectHeight = fontSize + <span style="color: #800080;">8</span><span style="color: #000000;">; </span><span style="color: #008080;">21</span> <span style="color: #008000;">//</span><span style="color: #008000;">声明矩形域</span> <span style="color: #008080;">22</span> RectangleF textArea = <span style="color: #0000ff;">new</span><span style="color: #000000;"> RectangleF(rectX, rectY, rectWidth, rectHeight); </span><span style="color: #008080;">23</span> <span style="color: #008080;">24</span> Font font = <span style="color: #0000ff;">new</span> Font(<span style="color: #800000;">"</span><span style="color: #800000;">宋体</span><span style="color: #800000;">"</span>, fontSize); <span style="color: #008000;">//</span><span style="color: #008000;">定义字体</span> <span style="color: #008080;">25</span> Brush whiteBrush = <span style="color: #0000ff;">new</span> SolidBrush(Color.White); <span style="color: #008000;">//</span><span style="color: #008000;">白笔刷,画文字用</span> <span style="color: #008080;">26</span> Brush blackBrush = <span style="color: #0000ff;">new</span> SolidBrush(Color.Black); <span style="color: #008000;">//</span><span style="color: #008000;">黑笔刷,画背景用</span> <span style="color: #008080;">27</span> <span style="color: #008080;">28</span> <span style="color: #000000;">g.FillRectangle(blackBrush, rectX, rectY, rectWidth, rectHeight); </span><span style="color: #008080;">29</span> <span style="color: #008080;">30</span> <span style="color: #000000;">g.DrawString(text, font, whiteBrush, textArea); </span><span style="color: #008080;">31</span> MemoryStream ms = <span style="color: #0000ff;">new</span><span style="color: #000000;"> MemoryStream(); </span><span style="color: #008080;">32</span> <span style="color: #008000;">//</span><span style="color: #008000;">保存为Jpg类型</span> <span style="color: #008080;">33</span> <span style="color: #000000;">bitmap.Save(ms, ImageFormat.Jpeg); </span><span style="color: #008080;">34</span> <span style="color: #008080;">35</span> Image h_hovercImg =<span style="color: #000000;"> Image.FromStream(ms); </span><span style="color: #008080;">36</span> <span style="color: #008080;">37</span> <span style="color: #000000;">g.Dispose(); </span><span style="color: #008080;">38</span> <span style="color: #000000;">bitmap.Dispose(); </span><span style="color: #008080;">39</span> <span style="color: #008080;">40</span> <span style="color: #008080;">41</span> <span style="color: #0000ff;">return</span><span style="color: #000000;"> h_hovercImg; </span><span style="color: #008080;">42</span> <span style="color: #000000;">} </span><span style="color: #008080;">43</span> <span style="color: #008080;">44</span> <span style="color: #008080;">45</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><summary></summary></span> <span style="color: #008080;">46</span> <span style="color: #808080;">///</span><span style="color: #008000;"> 根据文件头判断上传的文件类型 </span><span style="color: #008080;">47</span> <span style="color: #808080;">///</span> <span style="color: #808080;"></span> <span style="color: #008080;">48</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><param name="filePath"></span><span style="color: #008000;">filePath是文件的完整路径 </span><span style="color: #808080;"></span> <span style="color: #008080;">49</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><returns></returns></span><span style="color: #008000;">返回true或false</span><span style="color: #808080;"></span> <span style="color: #008080;">50</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">bool</span> IsPicture(<span style="color: #0000ff;">string</span><span style="color: #000000;"> filePath) </span><span style="color: #008080;">51</span> <span style="color: #000000;">{ </span><span style="color: #008080;">52</span> <span style="color: #0000ff;">try</span> <span style="color: #008080;">53</span> <span style="color: #000000;">{ </span><span style="color: #008080;">54</span> FileStream fs = <span style="color: #0000ff;">new</span><span style="color: #000000;"> FileStream(filePath, FileMode.Open, Fileaccess.Read); </span><span style="color: #008080;">55</span> BinaryReader reader = <span style="color: #0000ff;">new</span><span style="color: #000000;"> BinaryReader(fs); </span><span style="color: #008080;">56</span> <span style="color: #0000ff;">string</span><span style="color: #000000;"> fileClass; </span><span style="color: #008080;">57</span> <span style="color: #0000ff;">byte</span><span style="color: #000000;"> buffer; </span><span style="color: #008080;">58</span> buffer =<span style="color: #000000;"> reader.ReadByte(); </span><span style="color: #008080;">59</span> fileClass =<span style="color: #000000;"> buffer.ToString(); </span><span style="color: #008080;">60</span> buffer =<span style="color: #000000;"> reader.ReadByte(); </span><span style="color: #008080;">61</span> fileClass +=<span style="color: #000000;"> buffer.ToString(); </span><span style="color: #008080;">62</span> <span style="color: #000000;">reader.Close(); </span><span style="color: #008080;">63</span> <span style="color: #000000;">fs.Close(); </span><span style="color: #008080;">64</span> <span style="color: #0000ff;">if</span> (fileClass == <span style="color: #800000;">"</span><span style="color: #800000;">255216</span><span style="color: #800000;">"</span> || fileClass == <span style="color: #800000;">"</span><span style="color: #800000;">7173</span><span style="color: #800000;">"</span> || fileClass == <span style="color: #800000;">"</span><span style="color: #800000;">13780</span><span style="color: #800000;">"</span> || fileClass == <span style="color: #800000;">"</span><span style="color: #800000;">6677</span><span style="color: #800000;">"</span><span style="color: #000000;">) </span><span style="color: #008080;">65</span> <span style="color: #008000;">//</span><span style="color: #008000;">何问起 hovertree.com </span><span style="color: #008080;">66</span> <span style="color: #008000;">//</span><span style="color: #008000;">255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar </span> <span style="color: #008080;">67</span> <span style="color: #000000;">{ </span><span style="color: #008080;">68</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">; </span><span style="color: #008080;">69</span> <span style="color: #000000;">} </span><span style="color: #008080;">70</span> <span style="color: #0000ff;">else</span> <span style="color: #008080;">71</span> <span style="color: #000000;">{ </span><span style="color: #008080;">72</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">; </span><span style="color: #008080;">73</span> <span style="color: #000000;">} </span><span style="color: #008080;">74</span> <span style="color: #000000;">} </span><span style="color: #008080;">75</span> <span style="color: #0000ff;">catch</span> <span style="color: #008080;">76</span> <span style="color: #000000;">{ </span><span style="color: #008080;">77</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">; </span><span style="color: #008080;">78</span> <span style="color: #000000;">} </span><span style="color: #008080;">79</span> <span style="color: #000000;">} </span><span style="color: #008080;">80</span> <span style="color: #000000;">} </span><span style="color: #008080;">81</span> }
另外出一道.NET的题目:http://hovertree.com/shortanswer/bjaf/9vqxwuda.htm
开发技术文章收集: http://www.cnblogs.com/sosoft/p/kaifajishu.html

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

Video Face Swap
Échangez les visages dans n'importe quelle vidéo sans effort grâce à notre outil d'échange de visage AI entièrement gratuit !

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

Commencez par dessiner un cercle dans PPT, puis insérez une zone de texte et saisissez le contenu du texte. Enfin, définissez le remplissage et le contour de la zone de texte sur Aucun pour terminer la production d'images et de texte circulaires.

Vous voulez savoir comment ajouter un filigrane à MeituXiuXiu ? Meitu Xiuxiu est un logiciel de retouche photo très simple à utiliser. Il fournit des fonctions telles que découper des images et les placer sur une autre image, modifier la taille de l'image en Ko, supprimer les filigranes, modifier la couleur d'arrière-plan des photos d'identité et ajouter du temps. , les filigranes de date et de lieu en plein écran. Aidez les utilisateurs à terminer rapidement la production d'images. Certains utilisateurs ont créé leurs propres images et ne veulent pas que d’autres les volent. Ils veulent les recouvrir de leurs propres filigranes, mais ne savent pas comment faire ? L'éditeur va maintenant partager avec vous comment ajouter des filigranes à de belles images ! Si vous l'aimez, venez le télécharger ! 1. Comment ajouter un filigrane à de belles images ? Partagez comment ajouter un filigrane à de belles photos ! 1. Ouvrez la version 2023 de Meitu Xiu Xiu téléchargée depuis ce site. Version Meitu Xiu Xiu 2023 Catégorie : Photographie et embellissement Télécharger La version Meitu Xiu Xiu 2023 est un logiciel d'embellissement et d'édition d'images riche en fonctionnalités

Avec le développement continu des médias sociaux, Xiaohongshu est devenue une plateforme permettant à de plus en plus de jeunes de partager leur vie et de découvrir de belles choses. De nombreux utilisateurs sont gênés par des problèmes de sauvegarde automatique lors de la publication d’images. Alors, comment résoudre ce problème ? 1. Comment résoudre le problème de l'enregistrement automatique des images lors de la publication sur Xiaohongshu ? 1. Vider le cache Tout d'abord, nous pouvons essayer de vider les données du cache de Xiaohongshu. Les étapes sont les suivantes : (1) Ouvrez Xiaohongshu et cliquez sur le bouton « Mon » dans le coin inférieur droit (2) Sur la page du centre personnel, recherchez « Paramètres » et cliquez dessus (3) Faites défiler vers le bas et recherchez « ; "Vider le cache". Cliquez sur OK. Après avoir vidé le cache, entrez à nouveau dans Xiaohongshu et essayez de publier des photos pour voir si le problème de sauvegarde automatique est résolu. 2. Mettez à jour la version Xiaohongshu pour vous assurer que votre Xiaohongshu

La suppression des filigranes est un outil utile dans le logiciel Scanner. Certains utilisateurs ne savent pas comment supprimer les filigranes dans le scanner. Vous pouvez cliquer sur Supprimer le filigrane dans Modifier le PDF sur l'interface de sauvegarde pour le fermer. Ensuite, l'éditeur expliquera aux utilisateurs une introduction. à comment supprimer les filigranes Si vous êtes intéressé, venez jeter un œil ! Tutoriel d'utilisation de Scanner King Comment supprimer le filigrane avec Scanner King Réponse : Vous pouvez cliquer sur l'interface de sauvegarde pour modifier la suppression du filigrane dans le PDF. Détails : 1. Entrez dans le logiciel et cliquez sur l'icône [Appareil photo]. 2. Photographiez et numérisez les documents qui doivent être filigranés. 3. Cliquez sur [→] pour passer à l'étape suivante. 4. Une fois l'édition terminée, cliquez sur [ ✓]. 5. Cliquez sur [Modifier le PDF]. 6. Sélectionnez [Supprimer le filigrane] ci-dessous.

Avec la popularité des courtes vidéos Douyin, les interactions des utilisateurs dans la zone de commentaires sont devenues plus colorées. Certains utilisateurs souhaitent partager des images en commentaires pour mieux exprimer leurs opinions ou émotions. Alors, comment publier des photos dans les commentaires TikTok ? Cet article répondra à cette question en détail et vous fournira quelques conseils et précautions connexes. 1. Comment publier des photos dans les commentaires Douyin ? 1. Ouvrez Douyin : Tout d'abord, vous devez ouvrir l'application Douyin et vous connecter à votre compte. 2. Recherchez la zone de commentaire : lorsque vous parcourez ou publiez une courte vidéo, recherchez l'endroit où vous souhaitez commenter et cliquez sur le bouton "Commentaire". 3. Saisissez le contenu de votre commentaire : saisissez le contenu de votre commentaire dans la zone de commentaire. 4. Choisissez d'envoyer une photo : Dans l'interface de saisie du contenu des commentaires, vous verrez un bouton « image » ou un bouton « + », cliquez sur

Afin de rendre les photos prises plus personnalisées et uniques, Xiaomi Mi 14 propose des paramètres de filigrane photo. En définissant des filigranes de photos, les utilisateurs peuvent ajouter des motifs, du texte et des logos aux photos qu'ils prennent, afin que chaque photo puisse mieux enregistrer des moments et des souvenirs précieux. Ensuite, nous présenterons comment définir un filigrane photo dans Xiaomi 14 pour rendre vos photos plus personnalisées et plus vives. Comment définir un filigrane photo sur Xiaomi Mi 14 ? 1. Cliquez d'abord sur « Caméra ». 2. Cliquez ensuite sur « Paramètres ». 3. Recherchez ensuite le filigrane et vous pourrez ensuite commencer la prise de vue.

Lorsque nous créons quotidiennement des documents Word, nous devons parfois ajouter des points sous certains mots du document, notamment lorsqu'il y a des questions de test. Pour mettre en valeur cette partie du contenu, l'éditeur partagera avec vous les astuces pour ajouter des points au texte dans Word. J'espère que cela pourra vous aider. 1. Ouvrez un document Word vierge. 2. Par exemple, ajoutez des points sous les mots « Comment ajouter des points au texte ». 3. Nous sélectionnons d'abord les mots "Comment ajouter des points au texte" avec le bouton gauche de la souris. Notez que si vous souhaitez ajouter des points à ce mot à l'avenir, vous devez d'abord utiliser le bouton gauche de la souris pour sélectionner quel mot. . Aujourd'hui, nous ajoutons des points à ces mots, nous avons donc choisi plusieurs mots. Sélectionnez ces mots, cliquez avec le bouton droit et cliquez sur Police dans la boîte de fonction contextuelle. 4. Ensuite, quelque chose comme ceci apparaîtra

Comment supprimer le texte de la copie d'évaluation dans le coin inférieur droit de win1124H2 ? Lorsque nous utilisons le système, le bureau affiche parfois un filigrane transparent dans le coin inférieur droit de l'écran. Alors, comment supprimer ce filigrane transparent ? Les utilisateurs peuvent utiliser directement un logiciel tiers pour fonctionner. Laissez ce site présenter soigneusement aux utilisateurs comment supprimer le filigrane sur la copie d'évaluation win1124H2. Pour supprimer le filigrane sur la copie d'évaluation win1124H2, téléchargez l'outil UniversalWatermarkDisabler. Après l'avoir exécuté, la version actuelle du système et l'état du filigrane seront affichés. Si « Prêt pour l'installation » s'affiche dans « Statut », il peut être supprimé.
