Getting Properties of an image[VB.NET]
Getting Properties of an Image
Language: VB.NET
Author: Aamir Mustafa
Introduction:
This simple article will show how to get image properties. In this article I will load a photo and then its property will be shown. it will display all the properties of an image like name, image type, image size, its resolution.
How to show property:
Create an empty project and add following controls on the form.
Control | Properties |
Form | Name=Form1 Text= Properties Width=554 Height=224 |
Button | Name= btnLoad Text= Load Photo |
ListView | Name= lstProperties Width=329 Height=149 Scrollable=False Font Style=Bold Font Size=8 ForeColor=Coral |
PictureBox | Name= pic Width=117 Height=149 BorderStyle=FixedSingle SizeMode=StretchImage |
After doing that go to view code and add following code below Public Class Form1
Dim bitmapImage As Bitmap
Dim imageFile As String
After that add following just below the above code
Here we are initializing the List View so when first our program runs so we can see two columns, one for Property and second for Property value.
Public Sub New()
InitializeComponent()
lstProperties.View = View.Details
lstProperties.View = View.Details
lstProperties.Columns.Add("Property", Convert.ToInt32(lstProperties.Width * 50 \ 100))
lstProperties.Columns.Add("Value", Convert.ToInt32(lstProperties.Width * 45 \ 100))
lstProperties.GridLines = True
End Sub
Now write a function called GetProperties which gets the properties of an image and shows them in list view.
Private Sub GetProperties()
lstProperties.Items.Clear() ' clear the list view
lstProperties.Items.Add(New ListViewItem(New String() {"Name", System.IO.Path.GetFileNameWithoutExtension(imageFile)})) 'this will show name of image but not with extension
lstProperties.Items.Add(New ListViewItem(New String() {"Type", System.IO.Path.GetExtension(imageFile)})) 'this will show image type like JPEG
lstProperties.Items.Add(New ListViewItem(New String() {"Size", New System.IO.FileInfo(imageFile).Length.ToString() & " Bytes"})) 'this will show image size in bytes
lstProperties.Items.Add(New ListViewItem(New String() {"Width", pic.Width.ToString() & " Pixels"})) 'this will show image width
lstProperties.Items.Add(New ListViewItem(New String() {"Height", pic.Height.ToString() & " Pixels"})) 'this will show image height
lstProperties.Items.Add(New ListViewItem(New String() {"Vertical Resolution", bitmapImage.VerticalResolution.ToString() & " Pixels/Inch"})) 'this will show Vertical Resolution
lstProperties.Items.Add(New ListViewItem(New String() {"Horizontal Resolution", bitmapImage.HorizontalResolution.ToString() & " Pixels/Inch"})) 'this will show Horizontal Resolution
lstProperties.Items.Add(New ListViewItem(New String() {"Pixel Format", bitmapImage.PixelFormat.ToString()})) 'this will show pixel format.
lstProperties.Items.Add(New ListViewItem(New String() {"Palette Flags", bitmapImage.Palette.Flags.ToString()})) 'this will show pallete flags
End Sub
After that add following code to the load button’s click event. This opens a dialog to load picture from the local disk.
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim fileDialog As FileDialog = New OpenFileDialog()
fileDialog.Filter = "JPG (*.jpg)|*.jpg| Bitmap (*.bmp)|*.bmp|GIF (*.gif)|*.gif|JPEG (*.jpeg)|*.jpeg|PNG (*.png)|*.png|TIFF (*.tif)|*.tif|All Files (*.*)|*.*"
fileDialog.ShowDialog(Me)
pic.SizeMode = PictureBoxSizeMode.StretchImage
imageFile = fileDialog.FileName
If imageFile = String.Empty Then
Return
End If
pic.Image = Image.FromFile(imageFile)
bitmapImage = New Bitmap(imageFile)
GetProperties() ‘call GetProperties method
End Sub
Note:
If you want to get size of the image in Kilo Bytes then you can do it as follow
System.IO.FileInfo(imageFile).Length.ToString()\1024 & lstProperties.Items.Add(New ListViewItem(New String() {"Size", New" KB"})) 'this will show image size in kilo bytes
Converting decimal to binary[VC++.NET]
Converting decimal number into Binary number
Language: Visual C++.NET
Author: Aamir Mustafa
Introduction:
This article will show you how to convert a decimal number into binary number.
How to Convert:
This is Visual C++.Net so here is some different technique to create a project. I will use here Windows Form Application Project.
Follow these steps to create a project
File->New->New Project
Another window will open,in this window select CLR and then choose
Windows Form Application.
After that enter a name for your project and click OK
A new project will be created and a new form will be front of you.
On the form, add a button, two textboxes
- btnBinary
- txtNum
- txtBinary
We will take input through txtNum and show binary number into txtBinary and we will use btnBinary for converting decimal into Binary.
Double click on btnBinary
Write following code in btnBinary Click event.
[Code]
private: System::Void btnBinary_Click(System::Object^ sender, System::EventArgs^ e)
{
try
{
long num=0;
num=Convert::ToInt64(txtNum->Text);
txtBinary->Text=Convert::ToString(num,2);
}
catch(Exception ^ex)
{
MessageBox::Show("Please enter the number","Binary",MessageBoxButtons::OK,MessageBoxIcon::Information);
txtNum->Focus();
}
}
Converting decimal number into Octal number[C#.NET]
Converting decimal number into octal number
Language: C#.NET
Author: Aamir Mustafa
Introduction:
This article will show you how to convert a decimal number into octal number.
How to Use:
Create an empty project
On the form, add a button, two textboxes
- btnOctal
- txtNum
- txtOctal
We will take input through txtNum and show binary number into txtOctal and we will use btnOctal for converting decimal into octal.
Write following code in btnOctal Click event.
Code:
private void btnOctal_Click(object sender, EventArgs e)
{
try
{
long num = 0; //number that we will take through input
num = Convert.ToInt64(txtNum.Text);
txtOctal.Text = Convert.ToString(num, 8); //here 8 means converting to octal
}
catch (Exception ex)
{
MessageBox.Show("Plz enter the number", "Octal", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtNum.Focus();
}
}
Converting decimal to binary[C#.NET]
Converting decimal number into Binary number
Language: C#.NET
Author: Aamir Mustafa
Introduction:
This article will show you how to convert a decimal number into binary number.
How to Use:
Create an empty project
On the form, add a button, two textboxes
- btnBinary
- txtNum
- txtBinary
We will take input through txtNum and show binary number into txtBinary and we will use btnBinary for converting decimal into Binary.
Write following code in btnBinary Click event.
[Code]
private void btnBinary_Click(object sender, EventArgs e)
{
try
{
long num = 0; //number that we will take through input
num = System.Convert.ToInt64(txtNum.Text);
txtBinary.Text = Convert.ToString(num, 2); //here 2 means converting to binary
}
catch (Exception ex)
{
MessageBox.Show("Plz enter the number", "Binary", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtNum.Focus();
}
}
Converting decimal number into Hexadecimal number[VB.NET]
Converting decimal number into Hexadecimal number
Language: VB.NET
Author: Aamir Mustafa
E-Mail: aamir_mustafa2007@msn.com
Introduction:
This article will show you how to convert a decimal number into Hexadecimal number.
How to Use:
Create an empty project
On the form, add a button, two textboxes
- btnHexadecimal
- txtNum
- txtHexadecimal
We will take input through txtNum and show Hexadecimal number into txtHexadecimal and we will use btnHexadecimal for converting decimal into Hexadecimal.
Write following code in btn Hexadecimal Click event
[code]
Private Sub btnHexadecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHexadecimal.Click
Try
Dim num As Long 'number that we will take through input
num = CLng(txtNum.Text) 'assigning textbox value to num and converting string value to long using CLng function
If IsNumeric(num) Then 'checking that text box contains numeric value
txtHexadecimal.Text = Convert.ToString(num, 16) 'here 16 means converting to hexadecimal
End If
Catch ex As Exception
MessageBox.Show("Plz enter the number", "Octal", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtNum.Focus()
End Try
End Sub
Converting decimal number into Octal number[VB.NET]
Converting decimal number into Octal number
Language: VB.NET
Author: Aamir Mustafa
E-Mail: aamir_mustafa2007@msn.com
Introduction:
This article will show you how to convert a decimal number into octal number.
How to Use:
Create an empty project
On the form, add a button, two textboxes
- btnOctal
- txtNum
- txtOctal
We will take input through txtNum and show binary number into txtBinary and we will use btnOctal for converting decimal into Octal.
Write following code in btnOctal Click event.
Code:
End Sub Private Sub btnOctal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOctal.Click
Try
Dim num As Long 'number that we will take through input
num = CLng(txtNum.Text) 'assigning textbox value to num and converting string value to long using CLng function
If IsNumeric(num) Then 'checking that text box contains numeric value
txtOctal.Text = Convert.ToString(num, 8) 'here 8 means converting to octal
End If
Catch ex As Exception
MessageBox.Show("Plz enter the number", "Octal", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtNum.Focus()
End Try
End Sub
Converting decimal to binary[VB.NET]
Converting decimal number into Binary number
Language: VB.NET
Author: Aamir Mustafa
E-Mail: aamir_mustafa2007@msn.com
Introduction:
This article will show you how to convert a decimal number into binary number.
How to Use:
Create an empty project
On the form, add a button, two textboxes
- btnBinary
- txtNum
- txtBinary
We will take input through txtNum and show binary number into txtBinary and we will use btnBinary for converting decimal into binary.
Write following code in btnBinray Click event.
Code:
Private Sub btnBinary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBinary.Click
Try
Dim num As Long 'number that we will take through input
num = CLng(txtNum.Text) 'assigning textbox value to num and converting string value to Long using CLng function
If IsNumeric(num) Then 'checking that text box contains numeric value
txtBinary.Text = Convert.ToString(num, 2) 'here 2 means converting to binary
End If
Catch ex As Exception
MessageBox.Show("Plz enter the number", "Binary", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtNum.Focus()
End Try
End Sub
Converting decimal to binary
Converting decimal into Binary
Language: C++
Author: Aamir Mustafa
E-Mail: aamir_mustafa2007@msn.com
Introduction:
This simple program will convert a decimal number into equivalent binary
Code:
#include
#include
void main(void)
{
int bi,i,k; //declaring variables of integer type//
cout<<"Enter decimal number="; //asking user to prompt//
cin>>bi; //taking input//
cout<<"Its Binary Equivalent is ="; //getting the out put//
for(i=1;i<=12;i++) //executing for loop for 12 times//
{
k=bi%2; //getting the remainder//
bi=bi/2; //dividing by 2
cout<
}
cout<
getche();
}
Alternative Method
#include
#include
int main()
{
int num;
int result[12];
int i=0;
cout<<"enter the decimal number ";
cin>>num;
while(i<=12)
{
result[i]=num%2;
num=num/2;
i++;
}
for(int j=0;j<=12;j++)
cout<<>
cout<<>
system("pause");
}
Printing the Picture in C#.NET
Printing the Picture in C#.NET
Language: C#.NET
Author: Aamir Mustafa
E-Mail: aamir_mustafa2007@msn.com
Introduction:
I was looking different methods how to print a picture, so I have one way. This time I m going to tell you in C#.NET
This article will show simple method to print the picture
How to Print:
Create an empty project
On the form, add a menu bar and change its name to File
Below File menu, add these menus
mnuOpen
mnuPageSetup
mnuPrint
So we have following shape
Fileà Open, Page Setup, Print
After adding the menus
Go to Toolbox and go to Printing section and add following controls
PageSetupDialog1
We are using for setting page set up
PrintDocument1
We are using for printing document
PrintPreviewDialog1
We are using for take preview of our print
After adding all these controls, add a picture box to the form
Now we are going to add code
First of all add following code to Open menu
We will use it for opening a picture from disk
Code:
private void mnuOpen_Click(object sender, EventArgs e)
{
Bitmap m_bitmap;
OpenFileDialog openFileDlg=new OpenFileDialog();
openFileDlg.Filter = "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
if (openFileDlg.ShowDialog() == DialogResult.OK)
{
string strFileName = openFileDlg.FileName;
m_bitmap = new Bitmap(strFileName);
this.pictureBox1.Image = m_bitmap;
}
}
After adding above code , add following code in Page setup menu
We are using it for setting page setup
Code:
private void mnupageSetup_Click(object sender, EventArgs e)
{
pageSetupDialog1.Document = printDocument1;
pageSetupDialog1.ShowDialog();
}
Now we will add code in Print event click
Code:
private void mnuprint_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document=printDocument1;
printPreviewDialog1.ShowDialog();
}
At the end we will add code behind PrintPage event of PrintDocument1
So double click on it on the form or access its PageEvent in code editor and add following code
Code:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(this.pictureBox1.Image, 0, 0, this.pictureBox1.Width, this.pictureBox1.Height);
}
In the above code we are using DrawImage method of Graphics
DrawImage has five arguments
First argument which we pass is image, so here we are passing here our picture
Next argument is the x location of image and next location is y
Third is width of image, we are setting our picture width and so next is height of our image.
Draw a background with a rotating color gradient in Visual Basic .NET
| ||||||||
When the form's Timer fires, the event handler invalidates the drawing area PictureBox. The PictureBox's Paint event handler makes a LinearGradientBrush. The rectangle the gradient covers is slightly larger than the PictureBox's client rectangle. The brush uses the angle m_Theta to determine the gradient's angle. The program fills the PictureBox with the brush. It then updates m_Theta so the gradient rotates next time. Finally the program draws some text over the colored background. | ||||||||
Private m_Theta As Single = 0 |
Printing the Picture in VB.NET
| ||||||||
When the user clicks the Print button, the program calls the GetFormImage subroutine to make a Bitmap holding an image of the form's contents. It saves the result in a global variable. It then creates a PrintDocument object and calls its Print method to print the result. Subroutine GetFormImage gets a Graphics object for the form. It makes a Bitmap big enough to hold the image and gets a Graphics object for it. It then gets the device context handles (hDC) for the two Graphics objects and uses BitBlt to copy the form's image into the Bitmap. The PrintDocument's Print method uses the DrawImage method to draw the form's picture centered on the printout. | ||||||||
Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal _ |
Printing the Picture
Printing the Picture
Language: VB.NET
Author: Aamir Mustafa
E-Mail: aamir_mustafa2007@msn.com
Introduction:
I was looking different methods how to print a picture, so I have one way.
This article will show simple method to print the picture
How to Print:
Create an empty project
On the form, add a menu bar and change its name to File
Below File menu, add these menus
mnuOpen
mnuPageSetup
mnuPrint
So we have following shape
Fileà Open, Page Setup, Print
After adding the menus
Go to Toolbox and go to Printing section and add following controls
PageSetupDialog1
We are using for setting page set up
PrintDocument1
We are using for printing document
PrintPreviewDialog1
We are using for take preview of our print
After adding all these controls, add a picture box to the form
Now we are going to add code
First of all add following code to Open menu
We will use it for opening a picture from disk
Code:
Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
Try
Dim openFileDlg As New OpenFileDialog
openFileDlg.Filter = "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
With openFileDlg
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
.FilterIndex = 2
If .ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.Image = Image.FromFile(.FileName)
End If
End With
Catch ex As Exception
MessageBox.Show("Can not open file")
End Try
End Sub
After adding above code , add following code in Page setup menu
We are using it for setting page setup
Code:
Private Sub mnuPageSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PageSetupToolStripMenuItem.Click
PageSetupDialog1.Document = PrintDocument1
PageSetupDialog1.ShowDialog()
End Sub
Now we will add code in Print event click
Code:
Private Sub mnuPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
At the end we will add code behind PrintPage event of PrintDocument1
So double click on it on the form or access its PageEvent in code editor and add following code
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawImage(Me.PictureBox1.Image, 0, 0, Me.PictureBox1.Width, Me.PictureBox1.Height)
End Sub
In the above code we are using DrawImage method of Graphics
DrawImage has five arguments
First argument which we pass is image, so here we are passing here our picture
Next argument is the x location of image and next location is y
Third is width of image, we are setting our picture width and so next is height of our image.
Wellcome to Programmer Point
Welcome to all visitors
This blog is created for to give u all information about programming including C++,C# and VB.NET
There will be given codes and also links
Enjoy it