wmismail Posted August 10, 2008 Share Posted August 10, 2008 GDI+ (Graphics Device Interface) grafik çizmekte kullanılan bir .Net classıdır. GDI ile grafik uygulamalarımızı geliştirmekteyiz. Grafik uygulamalarını geliştirirken, genellikle lisede hemen hemen hepimize analitik geometri dersinde öğretilen koordinat sistemini (x,y) kullanırız. Koordinat sistemi, nesnelerin konumlarını ifade etmek için kullanılan bir adresleme metodudur. Bilgisayarın kullandığı koordinat sisteminde (0,0) koordinatları ile belirttiğimiz yer ekranın sağ üst köşesidir. (Kullanıcıya göre sol üst köşe) x değerini arttırdığımızda nesnemiz sol tarafa doğru, y değerini arttırdığımızda ise nesnemiz aşağı doğru kayar. Grafik nesnelerinin çizim ve doldurulma metodlarından bazıları şunlardır: Drawline : Çizgi Drawrectange : Dörtgen Drawarc : Yay Drawpie : Pasta dilimi Drawlines : Birbirine bağlı çizgiler DrawPolygon : Çokgen DrawString : Text DrawImage : Resim FillEllipse : Elipsin iç kısmını doldurur FillRectangle : Dörtgenin iç kısmını doldurur FillPie : Pasta diliminin iç kısmını doldurur FillPolygon : Çokgenin iç kısmını doldurur. GDI+ hakkında küçük bir tanımlama yaptıktan sonra basit bir program ile GDI+ ?a bir giriş yapalım. Örnek programımız basit bir paint programından oluşmaktadır. Programımızın ara yüzünü tasarlayalım. Formumuzu tasarladıktan sonra kod kısmında yapmamız gereken ilk şey, gerekli namespace lerimizi eklemek olacaktır. Imports System.Drawing Imports System.Drawing.Drawing2D Gerekli değişkenlerimizi tanımlayalım: Dim basX, sonX, basY, sonY As Integer Dim ciz As Boolean Dim sil As Boolean Dim kalem As New Pen(Color.Black) Dim a, b, x, y As Integer Kullanıcı programı çalıştırdığında koordinatlara göre Mouse nin iki türlü hareketi mevcut olur. çizimin başlangıç ordinatı veya apsisi (veya her ikisi) bitiş koordinatlarına göre büyük olur veya başlangıç ordinatı veya apsisi (veya her ikisi) bitiş koordinatlarına göre küçük olur. Başlangıç ve bitiş noktaları arasındaki farkı programın birçok yerinde kullanacağımız için if koşul operatörünü kullanarak bir sub oluşturalım : Sub cizim() If (sonX - basX) >= 0 Then a = sonX - basX x = basX Else a = basX - sonX x = sonX End If If (sonY - basY) >= 0 Then b = sonY - basY y = basY Else b = basY - sonY y = sonY End If End Sub Mouse nin hareketlerine göre koordinatları belirlemek için şu kodları yazarız: Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown If RadioButton3.Checked = True Then ?serbest çizim seçildiğinde? ciz = True End If basX = e.X basY = e.Y End Sub Private Sub Label1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp sonX = e.X sonY = e.Y If ciz = False Then Label1.Refresh() End If ciz = False End Sub Tasarımımızdaki radio buttonların seçimine göre yapılacak işlemleri yazalım: Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint Dim g As Graphics = e.Graphics If sil Then g.Clear(System.Drawing.Color.White) sil = False Return End If If RadioButton1.Checked = True Then cizim() g.DrawLine(kalem, New Point(basX, basY), New Point(sonX, sonY)) ?düz çizgi çiz ElseIf RadioButton2.Checked = True Then cizim() g.DrawRectangle(kalem, New Rectangle(x, y, a, ) ?dörtgen çiz ElseIf RadioButton4.Checked = True Then cizim() g.DrawEllipse(kalem, New Rectangle(x, y, a, ) ?elips çiz ElseIf RadioButton5.Checked = True Then cizim() Dim res As Image res = New Bitmap(OpenFileDialog1.FileName) Dim f As New TextureBrush(res) g.DrawRectangle(kalem, New Rectangle(x, y, a, ) g.FillRectangle(f, x, y, a, ?çizdiğin dörtgenin içini seçtiğin bir resim ile doldur ElseIf RadioButton6.Checked = True Then cizim() Dim res As Image res = New Bitmap(OpenFileDialog1.FileName) Dim f As New TextureBrush(res) g.DrawEllipse(kalem, New Rectangle(x, y, a, ) g.FillEllipse(f, x, y, a, ?çizdiğin elipsin içini seçtiğin bir resim ile doldur ElseIf RadioButton8.Checked = True Then cizim() Dim gradientdik As LinearGradientBrush = New LinearGradientBrush(New Rectangle(x, y, a, , ColorDialog1.Color, ColorDialog2.Color, LinearGradientMode.BackwardDiagonal) g.FillEllipse(gradientdik, x, y, a, ?seçtiğin iki renge göre elips çiz ElseIf RadioButton7.Checked = True Then cizim() Dim gradientdik As LinearGradientBrush = New LinearGradientBrush(New Rectangle(x, y, a, , ColorDialog1.Color, ColorDialog2.Color, LinearGradientMode.BackwardDiagonal) g.FillRectangle(gradientdik, x, y, a, ?seçtiğin iki renge göre dörtgen çiz End If End Sub Bu projede çizgi kalınlığını belirlemek için trackbar kullandık: Trackbar ımızın scroll eventine Label2.Text = TrackBar1.Value kalem.Width = TrackBar1.Value ekrandaki çizimleri silmek için button1?in click eventine sil = True ciz = False Label1.Refresh() yazdıktan sonra aslında programımız genel itibariyle bitmiş oldu. Bundan sonra yapacaklarımız kullanıcının beklenenden farklı bir olayı gerçekleştirmek istediğinde, programın hata vermemesi için ve renk seçimi gibi olaylar için gerekli olan bazı kodlar olacaktır. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load sil = False kalem.Width = 2 RadioButton5.Visible = False RadioButton6.Visible = False RadioButton7.Visible = False RadioButton8.Visible = False End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ColorDialog1.ShowDialog() kalem.Color = ColorDialog1.Color End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click RadioButton7.Visible = False RadioButton8.Visible = False RadioButton5.Visible = True RadioButton6.Visible = True OpenFileDialog1.ShowDialog() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click RadioButton7.Visible = True RadioButton8.Visible = True RadioButton5.Visible = False RadioButton6.Visible = False ColorDialog1.ShowDialog() ColorDialog2.ShowDialog() End Sub Makaledeki amacımız GDI+ ile henüz tanışmamış arkadaşlara GDI+ ?ı basit bir şekilde tanıtmaktı. Link to comment Share on other sites More sharing options...
wmismail Posted August 10, 2008 Author Share Posted August 10, 2008 Bu makalemizde de Drawstring metodunu kullanarak nasıl Text yaratıldığını göreceğiz. Teoriden çok pratikte görme açısından konuyu her zamanki gibi bir örnek proje (text editör) eşliğinde anlatacağım. İlk önce ara yüzümüzü tasarlayalım: Bunun için 1 picturebox, 3 button, 1 label , 1 textbox , 1 listbox ve 2 tanede trackbar ekleyelim. Imports System.Drawing.Drawing2D Imports System.Drawing.Text Değişkenlerimizi tanımlayalım Dim cd As New ColorDialog Dim cd2 As New ColorDialog Dim fd As New FontDialog Dim b4 As Boolean 'button 4 e basılıp basılmadığını kontrol için Dim b3 As Boolean 'button 3 e basılıp basılmadığını kontrol için Dim g As Graphics Dim gbas As New PointF(10, 10) Dim gson As New PointF(20, 20) Private Sub btnrenk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnrenk.Click b3 = True cd.ShowDialog() cd2.ShowDialog() End Sub Private Sub btnyazi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnyazi.Click b4 = True fd.ShowDialog() End Sub Private Sub forum_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListBox1.SelectedIndex = 0 TrackBar1.Value = 6 TrackBar2.Value = 6 b3 = False b4 = False End Sub Göster buttonumuz için gerekli kodları yazdıktan sonra alt kısımda gerekli subları yazacağız. Private Sub btngoster_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngoster.Click Select Case ListBox1.SelectedIndex Case 0 normalyazi() Case 1 golge() Case 2 boyut3() End Select End Sub Listbox ?ımızda da görüldüğü gibi 3 çeşit text hazırlayacağız. Bunlarda içlerinde bölünecekler. Eğer renk seç butonuna basılmadıysa yazımızın rengi blueviolet ve seagreen olacaktır.Yazi ayarlari butonuna basılmadığı zaman ise fontumuz kalın Trebuchet MS ve puntosuda 30 olacaktır. Kolaylık olması açısından bu 3 text için sublar kullanalım: Normal textimiz için : Sub normalyazi() Dim yazi As String = TextBox1.Text g = PictureBox1.CreateGraphics Dim tur As New FontFamily(fd.Font.Name.ToString) Dim boyut As Single = fd.Font.Size Dim durum As FontStyle = fd.Font.Style Dim yazitipi As New Font(tur, boyut, durum) If b3 = True Then Dim gbr As New LinearGradientBrush(gbas, gson, cd.Color, cd2.Color) If b4 = True Then g.DrawString(yazi, yazitipi, gbr, 50, 50) Else Dim yazitipi2 As New Font("Trebuchet MS", 30, FontStyle.Bold) g.DrawString(yazi, yazitipi2, gbr, 50, 50) End If b4 = False Else Dim gbr As New LinearGradientBrush(gbas, gson, Color.BlueViolet, Color.SeaGreen) If b4 = True Then g.DrawString(yazi, yazitipi, gbr, 50, 50) Else Dim yazitipi2 As New Font("Trebuchet MS", 30, FontStyle.Bold) g.DrawString(yazi, yazitipi2, gbr, 50, 50) End If b4 = False End If b3 = False End Sub Bu işlem sonucunda Gradient efekti uygulanmış text karşımıza çıkacaktır. Şimdide gölge efektini yapalım. Aslında gölge efektimiz normal de yazılmış text in yakınına aynı textin gri renkle yazılmasından ibaret. İki tane trackbar koyduk projemize. Bu sayede gölgenin boyutunu gölgenin sağ taraftan mı sol taraftan mı olacağına kullanıcı karar verecek. Sub gölgemizi şu şekilde yazdık. Sub golge() Dim yazi As String = TextBox1.Text g = PictureBox1.CreateGraphics Dim tur As New FontFamily(fd.Font.Name.ToString) Dim boyut As Single = fd.Font.Size Dim durum As FontStyle = fd.Font.Style Dim yazitipi As New Font(tur, boyut, durum) Dim golge As Brush = Brushes.Gray If b3 = True Then Dim gbr As New LinearGradientBrush(gbas, gson, cd.Color, cd2.Color) If b4 = True Then g.DrawString(yazi, yazitipi, golge, 50 + TrackBar1.Value, 50 + TrackBar2.Value) g.DrawString(yazi, yazitipi, gbr, 50, 50) Else Dim yazitipi2 As New Font("Trebuchet MS", 30, FontStyle.Bold) g.DrawString(yazi, yazitipi, golge, 50 + TrackBar1.Value, 50 + TrackBar2.Value) g.DrawString(yazi, yazitipi, gbr, 50, 50) End If b4 = False Else Dim gbr As New LinearGradientBrush(gbas, gson, Color.BlueViolet, Color.SeaGreen) If b4 = True Then g.DrawString(yazi, yazitipi, golge, 50 + TrackBar1.Value, 50 + TrackBar2.Value) g.DrawString(yazi, yazitipi, gbr, 50, 50) Else Dim yazitipi2 As New Font("Trebuchet MS", 30, FontStyle.Bold) g.DrawString(yazi, yazitipi, golge, 50 + TrackBar1.Value, 50 + TrackBar2.Value) g.DrawString(yazi, yazitipi, gbr, 50, 50) End If b4 = False End If End Sub Gelelim 3boyutlu yazı efektimize. Bunu hemen hemen hepimiz Office uygulamalarındaki wordart özelliğinden hatırlayacağız. Sub boyut3() g = PictureBox1.CreateGraphics Dim renk1 As Brush = Brushes.DarkBlue Dim yazi As String = TextBox1.Text Dim tur As New FontFamily(fd.Font.Name.ToString) Dim boyut As Single = fd.Font.Size Dim durum As FontStyle = fd.Font.Style Dim yazitipi As New Font(tur, boyut, durum) If b3 = True Then If b4 = True Then For i As Integer = CInt(TrackBar1.Value) To 0 Step -1 g.DrawString(yazi, yazitipi, renk1, 50 - i, 50 + i) Next Dim gbr As New LinearGradientBrush(gbas, gson, cd.Color, cd2.Color) g.DrawString(yazi, yazitipi, gbr, 50, 50) Else Dim yazitipi2 As New Font("Trebuchet MS", 30, FontStyle.Bold) g.Clear(Color.White) For i As Integer = CInt(TrackBar1.Value) To 0 Step -1 g.DrawString(yazi, yazitipi2, renk1, 50 - i, 50 + i) Next Dim gbr As New LinearGradientBrush(gbas, gson, cd.Color, cd2.Color) g.DrawString(yazi, yazitipi2, gbr, 50, 50) End If b4 = False Else Dim gbr As New LinearGradientBrush(gbas, gson, Color.BlueViolet, Color.Bisque) If b4 = True Then For i As Integer = CInt(TrackBar1.Value) To 0 Step -1 g.DrawString(yazi, yazitipi, renk1, 50 - i, 50 + i) Next g.DrawString(yazi, yazitipi, gbr, 50, 50) Else Dim yazitipi2 As New Font("Trebuchet MS", 30, FontStyle.Bold) g.Clear(Color.White) For i As Integer = CInt(TrackBar1.Value) To 0 Step -1 g.DrawString(yazi, yazitipi2, renk1, 50 - i, 50 + i) Next g.DrawString(yazi, yazitipi2, gbr, 50, 50) End If b4 = False End If b3 = False End Sub Yukarıda yaptığımız şey aslında gölge efektinin devamı niteliğinde. Gölge efektini verirken tasarladığımız text in koordinatlarına yakın aynı textin farklı renkte olanını çizdirmiştik. 3d efektinde ise hazırlamış olduğumuz gölge textinin koordinatları ile normal textimizin koordinatları arasındaki farkı for döngüsüyle doldurmamızdan ibaret. Böylece text editörümüzü hazırlamış olduk. Link to comment Share on other sites More sharing options...
wmismail Posted August 10, 2008 Author Share Posted August 10, 2008 GDI+ Nedir yazı dizisinin bu bölümünde basit bir Picture editor programının nasıl yapılacağını göstereceğiz. Yapacağımız program sayesinde bilgisayarımızdaki resimleri gösterebilecek, bu resimlerin boyutları ve yönleri ile oynarak resmimizi farklı olarak kaydedebilecek, seçtiğimiz resmi masaüstümüze nasıl duvar kağıdı yapacağımızı öğrenecek, bunun yanında bir çok arkadaşımızın bildiği Adobe Photoshop programındaki birkaç görüntü efektinin nasıl yapıldığının farkına varacağız.İlk önce programımızın arayüzünü tasarlayalım:[img=http://www.yazilimgunlugu.com/ArticlePictures/367/1000000761_image001.jpg]Programımızda drivelistbox, dirlistbox, filelistbox, SaveFileDialog nesnelerine ilaveten şekilde de görüldüğü gibi birkaç label,textbox,button ve combobox kullandık.Filelistbox nesnemizin property ?sinden pattern özelliğini *.jpg yaptık.Namespacelerimizi ve global değişkenlerimizi ekleyelim:Imports System.DrawingImports System.Drawing.Drawing2DImports System.Drawing.ImagingImports System.IODim ima As ImageDim oran As DecimalDrivelistbox, dirlistbox ve filelistbox nesnelerimizin ilişkisini kuralım.Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChangedDirListBox1.Path = DriveListBox1.DriveEnd SubPrivate Sub DirListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DirListBox1.SelectedIndexChangedFileListBox1.Path = DirListBox1.PathEnd SubFileListBox tan seçtiğimiz resim picturebox?ımıza büyük gelebilir. Bunu düzeltmenin birçok yolu vardır. Aşağıdaki yöntemde bunlardan biri.ima = Image.FromFile(FileListBox1.Path & "\" & FileListBox1.SelectedItem)Dim gerceken As Integer = ima.WidthDim gercekboy As Integer = ima.HeightDim sonen As IntegerDim sonboy As IntegerLabel3.Text = gercekenLabel4.Text = gercekboyTextBox1.Text = gercekenTextBox2.Text = gercekboyLabel8.Text = Math.Round(FileLen(FileListBox1.Path & "\" & FileListBox1.SelectedItem) / 1024) & " Kb."oran = gercekboy / gercekenoran = Math.Round(oran, 2)If gercekboy > PictureBox1.Height Thensonboy = PictureBox1.Heightsonen = PictureBox1.Height * oranPictureBox1.Image = ima.GetThumbnailImage(sonen, sonboy, Nothing, Nothing)End IfIf gerceken > PictureBox1.Width Thensonen = PictureBox1.Widthsonboy = PictureBox1.Width * oranPictureBox1.Image = ima.GetThumbnailImage(sonen, sonboy, Nothing, Nothing)ElsePictureBox1.Image = imaEnd Ifİleri ? Geri Buttonlarımızın eventlerini yazalım:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickIf FileListBox1.SelectedIndex = FileListBox1.Items.Count - 1 ThenButton1.Enabled = FalseElse : FileListBox1.SelectedIndex = FileListBox1.SelectedIndex + 1End IfButton2.Enabled = TrueEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickIf FileListBox1.SelectedIndex = 0 ThenButton2.Enabled = FalseElse : FileListBox1.SelectedIndex = FileListBox1.SelectedIndex - 1End IfButton1.Enabled = TrueEnd SubBüyültme ? Küçültme işlemlerini yaparken resmin görüntüsünü bozmamak için belirli bir oranda küçültme büyültme yapmamız gerekir. Bu projede uzunluk biriminin girildiği textbox ?ın readonly özelliğini True yaparak, resmin sadece genişliğinin belirlenmesini kullanıcıya bıraktık. İsterseniz bu iki taraflıda yapılabilir.Büyültme-Küçültme Buttonumuzun Click even?tine aşağıdaki kodları yazıyoruz :Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChangedIf TextBox1.Text = "" ThenTextBox2.Text = ""Else : TextBox2.Text = oran * TextBox1.TextEnd IfEnd SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickIf TextBox1.Text <= PictureBox1.Height ThenIf TextBox1.Text <> "" ThenIf TextBox2.Text <> "" ThenDim myCallback As Image.GetThumbnailImageAbortPictureBox1.Image = ima.GetThumbnailImage(TextBox1.Text, TextBox2.Text, Nothing, Nothing)Else : MessageBox.Show("Genişlik boş değer içeremez")End IfElse : MessageBox.Show("uzunluk boş değer içeremez")End IfElse : MessageBox.Show("Pencereden Büyük Değer Girdiniz.")End IfEnd SubŞimdi de resmimizi nasıl dönderdiğimiz ve farklı kaydetme yapabilmemiz için gerekli kodları yazalım:Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChangedSelect Case ComboBox1.SelectedIndexCase 0ima.RotateFlip(RotateFlipType.Rotate90FlipX)PictureBox1.Refresh()Case 1ima.RotateFlip(RotateFlipType.Rotate270FlipX)PictureBox1.Refresh()Case 2ima.RotateFlip(RotateFlipType.Rotate180FlipX)PictureBox1.Refresh()End SelectEnd SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickSaveFileDialog1.Filter = "Resim Dosyasi (*.jpg)|*.jpg"SaveFileDialog1.ShowDialog()If SaveFileDialog1.FileName <> "" ThenPictureBox1.Image.Save(SaveFileDialog1.FileName)MsgBox("kayit basarili")End IfEnd SubBir çok arkadaşımızın Adobe Photoshop programından bildiği birkaç görüntü efekti (Emboss, Diffuse, Smoth, Sharpen) uygulayalım. Bunları daha kolay anlayabilelim ve birçok yerde kullanalım diye sub yordamının içine yazdık.Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.ClickIf ComboBox2.SelectedIndex = 0 Then : emboss()ElseIf ComboBox2.SelectedIndex = 1 Then : diffuse()ElseIf ComboBox2.SelectedIndex = 2 Then : smooth()ElseIf ComboBox2.SelectedIndex = 4 Then : sharpen()End IfEnd SubSub diffuse()Dim bmap As New Bitmap(PictureBox1.Image)PictureBox1.Image = bmapDim tempbmp As New Bitmap(PictureBox1.Image)Dim i As Integer, j As IntegerDim DX As IntegerDim DY As IntegerDim red As Integer, green As Integer, blue As IntegerWith tempbmpFor i = 3 To .Height - 3For j = 3 To .Width - 3DX = Rnd() * 4 - 2DY = Rnd() * 4 - 2red = .GetPixel(j + DX, i + DY).Rgreen = .GetPixel(j + DX, i + DY).Gblue = .GetPixel(j + DX, i + DY).Bbmap.SetPixel(j, i, Color.FromArgb(red, green, blue))NextIf i Mod 10 = 0 ThenPictureBox1.Invalidate()PictureBox1.Refresh()End IfNextEnd WithPictureBox1.Refresh()End SubSub sharpen()Dim bmap As New Bitmap(PictureBox1.Image)PictureBox1.Image = bmapDim tempbmp As New Bitmap(PictureBox1.Image)Dim i, j As IntegerDim DX As Integer = 1, DY As Integer = 1Dim red, green, blue As IntegerWith tempbmpFor i = DX To .Height - DX - 1 'satırFor j = DY To .Width - DY - 1 'sutunred = CInt(.GetPixel(j, i).R) + 0.5 * CInt((.GetPixel(j, i).R) - CInt(.GetPixel(j - DX, i - DY).R))green = CInt(.GetPixel(j, i).G) + 0.7 * CInt((.GetPixel(j, i).G) - CInt(.GetPixel(j - DX, i - DY).G))blue = CInt(.GetPixel(j, i).B) + 0.5 * CInt((.GetPixel(j, i).B - CInt(.GetPixel(j - DX, i - DY).B)))red = Math.Min(Math.Max(red, 0), 255)green = Math.Min(Math.Max(green, 0), 255)blue = Math.Min(Math.Max(blue, 0), 255)bmap.SetPixel(j, i, Color.FromArgb(red, green, blue))NextIf i Mod 10 = 0 ThenPictureBox1.Invalidate()PictureBox1.Refresh()End IfNextEnd WithPictureBox1.Refresh()End Sub Sub emboss()Dim bmap As New Bitmap(PictureBox1.Image)PictureBox1.Image = bmapDim tempbmp As New Bitmap(PictureBox1.Image)Dim i, j As IntegerDim DispX As Integer = 1, DispY As Integer = 1Dim red, green, blue As IntegerWith tempbmpFor i = 0 To .Height - 2 'satırFor j = 0 To .Width - 2 'sutunDim pixel1, pixel2 As System.Drawing.Colorpixel1 = .GetPixel(j, i)pixel2 = .GetPixel(j + DispX, i + DispY)'Renklerini Değiştiriyoruzred = Math.Min(Math.Abs(CInt(pixel1.R) - _CInt(pixel2.R)) + 128, 255)green = Math.Min(Math.Abs(CInt(pixel1.G) - _CInt(pixel2.G)) + 128, 255)blue = Math.Min(Math.Abs(CInt(pixel1.B) - _CInt(pixel2.B)) + 128, 255)bmap.SetPixel(j, i, Color.FromArgb(red, green, blue))NextIf i Mod 10 = 0 ThenPictureBox1.Invalidate()PictureBox1.Refresh()End IfNextEnd WithPictureBox1.Refresh()End SubSub smooth()Dim bmap As New Bitmap(PictureBox1.Image)PictureBox1.Image = bmapDim tempbmp As New Bitmap(PictureBox1.Image)Dim DX As Integer = 1Dim DY As Integer = 1Dim red, green, blue As IntegerDim i, j As IntegerWith tempbmpFor i = DX To .Height - DX - 1 'satırFor j = DY To .Width - DY - 1 'sutunred = CInt((CInt(.GetPixel(j - 1, i - 1).R) + _CInt(.GetPixel(j - 1, i).R) + _CInt(.GetPixel(j - 1, i + 1).R) + _CInt(.GetPixel(j, i - 1).R) + _CInt(.GetPixel(j, i).R) + _CInt(.GetPixel(j, i + 1).R) + _CInt(.GetPixel(j + 1, i - 1).R) + _CInt(.GetPixel(j + 1, i).R) + _CInt(.GetPixel(j + 1, i + 1).R)) / 9)green = CInt((CInt(.GetPixel(j - 1, i - 1).G) + _CInt(.GetPixel(j - 1, i).G) + _CInt(.GetPixel(j - 1, i + 1).G) + _CInt(.GetPixel(j, i - 1).G) + _CInt(.GetPixel(j, i).G) + _CInt(.GetPixel(j, i + 1).G) + _CInt(.GetPixel(j + 1, i - 1).G) + _CInt(.GetPixel(j + 1, i).G) + _CInt(.GetPixel(j + 1, i + 1).G)) / 9)blue = CInt((CInt(.GetPixel(j - 1, i - 1).B) + _CInt(.GetPixel(j - 1, i).B) + _CInt(.GetPixel(j - 1, i + 1).B) + _CInt(.GetPixel(j, i - 1).B) + _CInt(.GetPixel(j, i).B) + _CInt(.GetPixel(j, i + 1).B) + _CInt(.GetPixel(j + 1, i - 1).B) + _CInt(.GetPixel(j + 1, i).B) + _CInt(.GetPixel(j + 1, i + 1).B)) / 9)red = Math.Min(Math.Max(red, 0), 255)green = Math.Min(Math.Max(green, 0), 255)blue = Math.Min(Math.Max(blue, 0), 255)bmap.SetPixel(j, i, Color.FromArgb(red, green, blue))NextIf i Mod 10 = 0 ThenPictureBox1.Invalidate()PictureBox1.Refresh()End IfNextEnd WithPictureBox1.Refresh()End Sub Seçtiğimiz resmimizi masaüstü arka planı olarak ayarlamak için API lerden faydalanacağız.Arka plan resimlerinin uzantıları BMP dir. Bizim üzerinde çalıştığımız resimleri en başta JPG olarak belirttiğimiz için bu resmin BMP uzantılı bir kopyasını çıkarmamız gerekmektedir.BMP uzantılı resmimizi BIN dosyasının içine kaydedecek daha sonrada bu resmi masaüstü arkaplanımız yapacağız. Arka plan yapmak içinde Apilerin (Application Programming Interface) yardımı alacağız:Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As IntegerPrivate Const SPI_SETDESKWALLPAPER = 20Private Const SPIF_UPDATEINIFILE = &H1Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickDim imagePath As String = Application.StartupPath & "\DuvarKagidi.bmp"PictureBox1.Image.Save(imagePath, ImageFormat.Bmp)SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE)End Sub[img=http://www.yazilimgunlugu.com/ArticlePictures/367/1000000761_image002.jpg][img=http://www.yazilimgunlugu.com/ArticlePictures/367/1000000761_image003.jpg][/CODE] Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.