Jump to content

Gdi + Nedir [3 Bölüm]


wmismail

Recommended Posts

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.

1000000496_image001.jpg

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, :dribble:)

?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, :D)

g.FillRectangle(f, x, y, a, :D

?ç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, B))

g.FillEllipse(f, x, y, a, B)

?ç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, B), ColorDialog1.Color, ColorDialog2.Color, LinearGradientMode.BackwardDiagonal)

g.FillEllipse(gradientdik, x, y, a, B)

?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, B), ColorDialog1.Color, ColorDialog2.Color, LinearGradientMode.BackwardDiagonal)

g.FillRectangle(gradientdik, x, y, a, B)

?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

1000000496_image002.jpg

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

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.

1000000497_image001.jpg

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.

1000000497_image002.jpg

Ş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

1000000497_image003.jpg

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.

1000000497_image004.jpg

Böylece text editörümüzü hazırlamış olduk.

Link to comment
Share on other sites

 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.Drawing

Imports System.Drawing.Drawing2D

Imports System.Drawing.Imaging

Imports System.IO

Dim ima As Image

Dim oran As Decimal

Drivelistbox, dirlistbox ve filelistbox nesnelerimizin ilişkisini kuralım.

Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChanged

DirListBox1.Path = DriveListBox1.Drive

End Sub

Private Sub DirListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DirListBox1.SelectedIndexChanged

FileListBox1.Path = DirListBox1.Path

End Sub

FileListBox 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.Width

Dim gercekboy As Integer = ima.Height

Dim sonen As Integer

Dim sonboy As Integer

Label3.Text = gerceken

Label4.Text = gercekboy

TextBox1.Text = gerceken

TextBox2.Text = gercekboy

Label8.Text = Math.Round(FileLen(FileListBox1.Path & "\" & FileListBox1.SelectedItem) / 1024) & " Kb."

oran = gercekboy / gerceken

oran = Math.Round(oran, 2)

If gercekboy > PictureBox1.Height Then

sonboy = PictureBox1.Height

sonen = PictureBox1.Height * oran

PictureBox1.Image = ima.GetThumbnailImage(sonen, sonboy, Nothing, Nothing)

End If

If gerceken > PictureBox1.Width Then

sonen = PictureBox1.Width

sonboy = PictureBox1.Width * oran

PictureBox1.Image = ima.GetThumbnailImage(sonen, sonboy, Nothing, Nothing)

Else

PictureBox1.Image = ima

End 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.Click

If FileListBox1.SelectedIndex = FileListBox1.Items.Count - 1 Then

Button1.Enabled = False

Else : FileListBox1.SelectedIndex = FileListBox1.SelectedIndex + 1

End If

Button2.Enabled = True

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

If FileListBox1.SelectedIndex = 0 Then

Button2.Enabled = False

Else : FileListBox1.SelectedIndex = FileListBox1.SelectedIndex - 1

End If

Button1.Enabled = True

End Sub

Bü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.TextChanged

If TextBox1.Text = "" Then

TextBox2.Text = ""

Else : TextBox2.Text = oran * TextBox1.Text

End If

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

If TextBox1.Text <= PictureBox1.Height Then

If TextBox1.Text <> "" Then

If TextBox2.Text <> "" Then

Dim myCallback As Image.GetThumbnailImageAbort

PictureBox1.Image = ima.GetThumbnailImage(TextBox1.Text, TextBox2.Text, Nothing, Nothing)

Else : MessageBox.Show("Genişlik boş değer içeremez")

End If

Else : MessageBox.Show("uzunluk boş değer içeremez")

End If

Else : MessageBox.Show("Pencereden Büyük Değer Girdiniz.")

End If

End 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.SelectedIndexChanged

Select Case ComboBox1.SelectedIndex

Case 0

ima.RotateFlip(RotateFlipType.Rotate90FlipX)

PictureBox1.Refresh()

Case 1

ima.RotateFlip(RotateFlipType.Rotate270FlipX)

PictureBox1.Refresh()

Case 2

ima.RotateFlip(RotateFlipType.Rotate180FlipX)

PictureBox1.Refresh()

End Select

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

SaveFileDialog1.Filter = "Resim Dosyasi (*.jpg)|*.jpg"

SaveFileDialog1.ShowDialog()

If SaveFileDialog1.FileName <> "" Then

PictureBox1.Image.Save(SaveFileDialog1.FileName)

MsgBox("kayit basarili")

End If

End Sub

Bir ç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.Click

If ComboBox2.SelectedIndex = 0 Then : emboss()

ElseIf ComboBox2.SelectedIndex = 1 Then : diffuse()

ElseIf ComboBox2.SelectedIndex = 2 Then : smooth()

ElseIf ComboBox2.SelectedIndex = 4 Then : sharpen()

End If

End Sub

Sub diffuse()

Dim bmap As New Bitmap(PictureBox1.Image)

PictureBox1.Image = bmap

Dim tempbmp As New Bitmap(PictureBox1.Image)

Dim i As Integer, j As Integer

Dim DX As Integer

Dim DY As Integer

Dim red As Integer, green As Integer, blue As Integer

With tempbmp

For i = 3 To .Height - 3

For j = 3 To .Width - 3

DX = Rnd() * 4 - 2

DY = Rnd() * 4 - 2

red = .GetPixel(j + DX, i + DY).R

green = .GetPixel(j + DX, i + DY).G

blue = .GetPixel(j + DX, i + DY).B

bmap.SetPixel(j, i, Color.FromArgb(red, green, blue))

Next

If i Mod 10 = 0 Then

PictureBox1.Invalidate()

PictureBox1.Refresh()

End If

Next

End With

PictureBox1.Refresh()

End Sub

Sub sharpen()

Dim bmap As New Bitmap(PictureBox1.Image)

PictureBox1.Image = bmap

Dim tempbmp As New Bitmap(PictureBox1.Image)

Dim i, j As Integer

Dim DX As Integer = 1, DY As Integer = 1

Dim red, green, blue As Integer

With tempbmp

For i = DX To .Height - DX - 1 'satır

For j = DY To .Width - DY - 1 'sutun

red = 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))

Next

If i Mod 10 = 0 Then

PictureBox1.Invalidate()

PictureBox1.Refresh()

End If

Next

End With

PictureBox1.Refresh()

End Sub

Sub emboss()

Dim bmap As New Bitmap(PictureBox1.Image)

PictureBox1.Image = bmap

Dim tempbmp As New Bitmap(PictureBox1.Image)

Dim i, j As Integer

Dim DispX As Integer = 1, DispY As Integer = 1

Dim red, green, blue As Integer

With tempbmp

For i = 0 To .Height - 2 'satır

For j = 0 To .Width - 2 'sutun

Dim pixel1, pixel2 As System.Drawing.Color

pixel1 = .GetPixel(j, i)

pixel2 = .GetPixel(j + DispX, i + DispY)

'Renklerini Değiştiriyoruz

red = 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))

Next

If i Mod 10 = 0 Then

PictureBox1.Invalidate()

PictureBox1.Refresh()

End If

Next

End With

PictureBox1.Refresh()

End Sub

Sub smooth()

Dim bmap As New Bitmap(PictureBox1.Image)

PictureBox1.Image = bmap

Dim tempbmp As New Bitmap(PictureBox1.Image)

Dim DX As Integer = 1

Dim DY As Integer = 1

Dim red, green, blue As Integer

Dim i, j As Integer

With tempbmp

For i = DX To .Height - DX - 1 'satır

For j = DY To .Width - DY - 1 'sutun

red = 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))

Next

If i Mod 10 = 0 Then

PictureBox1.Invalidate()

PictureBox1.Refresh()

End If

Next

End With

PictureBox1.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 Integer

Private Const SPI_SETDESKWALLPAPER = 20

Private Const SPIF_UPDATEINIFILE = &H1

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim 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

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...