Visual Basic Online Course - VB .NET Faded Image

Fade Image in VB 2010

VB 2010 Fade Image
VB 2010 Fade Image
How to fade image in Visual Basic 2010

It doesn’t matter if you are a photographer or a graphic designer, chances are that you have come across the need to fade or blend images in Visual Basic 2010. You can always use Photoshop to create faded images and then use them in your VB 2010 applications, but as a developer you also have to know what does it take to do so, not just to fade an Image but also as a general, after all it's your job to come up with answers.

In our demonstration here well will use ordinary common tools in VB 2010 to be able to fade an Image.

Project Design
 
VB 2010 Example to Fade Image
VB 2010 Example to Fade Image
Form
Name : Form1
Text : Fade Image in VB 2010
PictureBox
Name : PicToFade
BackColor : Transparent
Dock : Full
Timer
Name : Timer1
Interval : 100

How does it work 

Run the application, click on the PicToFade [PictureBox], it will show the [OpenFileDialog] choose and Image [JPEG] and then notice that it will begin to fade away.

You can alter the code to change the fading values [Alpha from 0 to 1 and DeltaAlpha], you can use a Progressbar control to change the fading values too.

Source Code
'Visual Basic Online Course
'VB 2010 Fade Image
Imports System.Drawing.Imaging
Public Class Form1
Dim BMP As Bitmap
Dim ImgPath As String
Dim ofd As New OpenFileDialog
Dim Alpha As Single = 0 ' Alpha on a 0-1 scale.
Dim DeltaAlpha As Single = 0.03
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
Dim BMP1 As Bitmap = New Bitmap(BMP.Width, BMP.Height, PixelFormat.Format32bppArgb)
Dim gr As Graphics = Graphics.FromImage(BMP1)
Alpha += DeltaAlpha
If Alpha > 1 Then 'Finish
Timer1.Enabled = False
End If
Dim ColorMx As ColorMatrix
ColorMx = New ColorMatrix(New Single()() { _
New Single() {1.0, 0.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, 1.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, 1.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, Alpha, 1.0}})
Dim image_attr As New ImageAttributes
image_attr.SetColorMatrix(ColorMx)
gr.DrawImage(BMP, New Rectangle(0, 0, BMP.Width, BMP.Height), 0, 0, _
BMP.Width, BMP.Height, GraphicsUnit.Pixel, image_attr)
PicToFade.Image = BMP1
BMP = BMP1
End Sub
Private Sub PicToFade_Click(sender As System.Object, _
e As System.EventArgs) Handles PicToFade.Click
With ofd
.Filter = ("Jpg format|*.JPG")
.ShowDialog()
ImgPath = .FileName
End With
BMP = Image.FromFile(ImgPath)
PicToFade.Image = BMP
Application.DoEvents()
Timer1.Enabled = True
End Sub
End Class
view raw gistfile1.vb hosted with ❤ by GitHub

Download Source Code
MediaFire.com fade image

Here are some online Visual Basic lessons and courses :

Popular posts from this blog

VB .NET DropBox Api Source Code Example

VB .NET Google Drive Api Source Code Example

VB.NET Access 2007 Hierarchical TreeView

VB.NET How to properly close a windows application Form

DAO in VB .NET MS ACCESS Database

Solution - There is already an open DataReader associated with this Command which must be closed first.