Posts Tagged ‘How to’

How to create thumbnail of an image

Source: http://www.getdotnetcode.com/nexDotNet/020019GetThumbnailImageVB2005/GetThumbnailImageVB2005.htm

You can use the .NET 2.0 Image class’ GetThumbnailImage method to generate a scaled thumbnail of an image.

If the Image contains an embedded thumbnail image, this method retrieves the embedded thumbnail and scales it to the requested size. If the Image does not contain an embedded thumbnail image, this method creates a thumbnail image by scaling the main image.

Private Sub GetThumbnail(ByVal pathToImageFile As String, ByVal scaleToPercent As Decimal)

‘ Declare a variable named imageAjustmentPercent of type Decimal.
Dim imageAdjustmentPercent As Decimal

‘ Divide the scaleToPercent passed into this method by 100;
‘ assign the result to the imageAjustmentPercent variable.
imageAdjustmentPercent = CDec(scaleToPercent / 100)

‘ Declare two variables of type Integer named
‘ adjustedImageWidth and adjustedImageHeight.
Dim adjustedImageWidth, adjustedImageHeight As Integer

‘ Declare a variable named theImage of type Image.
Dim theImage As Image

‘ Get an image object from the image file;
‘ assign the image object to the theImage variable.
theImage = Image.FromFile(pathToImageFile)

‘ Calculate adjustedImageWidth and adjustedImageHeight using the imageAdjustmentPercent.
adjustedImageWidth = CType(theImage.Width * imageAdjustmentPercent, Integer)
adjustedImageHeight = CType(theImage.Height * imageAdjustmentPercent, Integer)

‘ Call the Image class’ GetThumbnail method to create a new scaled
‘ image object from the orginal image object. Assign it to theImage varable.
theImage = theImage.GetThumbnailImage(adjustedImageWidth, adjustedImageHeight, Nothing, Nothing)

‘ Assign theImage to DemoPicturebox.
Me.DemoPictureBox.Image = theImage

End Sub
Attached is a Visual Studio 2005 Windows Forms Visual Basic solution that demonstrates how to generate scaled thumbnail images from image files.

mike mcintyre http://www.getdotnetcode.com

, , ,

No Comments


How to Load Bitmap into the Picturebox

mports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Printing

Private sub LoadBitmapImage()
Me.PictureBox1.Image = New System.Drawing.Bitmap(“c:\mypic.bmp”)
End Sub

, ,

No Comments


How to Load Image into Picture Box from File

1. Add OpenFileDialog

2. Copy and Paste the code below

Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Printing

 

Private Sub LoadImageFrom()

 

 With Me.openPic

            .InitialDirectory = “C:\”

            .Filter = “Images(*.jpg, *.gif, *.png)|*.jpg; *.gif; *.png” 

            .FilterIndex = 0

            .ShowDialog()

 

            If .FileName <> “” Then

                Try

                    Dim patientPic As Image

                    patientPic = Image.FromFile(.FileName)

                    Me.picPatient.Image = patientPic

                Catch ex As Exception

                    MessageBox.Show(String.Format(“LoadImageFrom : {0}”, ex.Message), mCaption, MessageBoxButtons.OK, MessageBoxIcon.Error)

                End Try

            End If

        End With

End Sub

 



, ,

No Comments


How to create vb.net class script from table in T-SQL

/*

params:

@dbType – holds the data type defined in the table structure

@fldName – field/column name

@len – storage length of the column if data type is varchar/char etc.

@precision – numeric

@scale – numeric

@newType – equivalent data type in vb.net; ex. varchar -> string

@struct – script

@tablename – table name

*/

DECLARE @dbType VARCHAR(50)

DECLARE @fldName VARCHAR(50)

DECLARe @len smallint

DECLARE @precision smallint

DECLARE @scale smallint

DECLARE @newType VARCHAR(20)

DECLARE @class VARCHAR(MAX)

DECLARE @tablename VARCHAR(20)

DECLARE @tmpVar VARCHAR(MAX)

DECLARE @tmpVarpfx VARCHAR(3)

SET @tablename = ‘tblExchangeDocument’

SET @newType = ”

SET @tmpVar = ”

SET @class = ”–’Public Class ‘ + RIGHT(@tablename, LEN(@tablename) – 3)

SET @tmpVarpfx = ”

DECLARE rs CURSOR FOR

SELECT sys.columns.[name] as fldname, sys.types.name as dbtype,  sys.columns.[max_length], sys.columns.[precision], sys.columns.[scale]

FROM sys.columns INNER JOIN sys.types ON sys.columns.system_type_id = sys.types.system_type_id

WHERE object_id = OBJECT_ID(@tablename)

OPEN rs

FETCH NEXT FROM rs

INTO @fldname, @dbType, @len, @precision, @scale

WHILE @@FETCH_STATUS = 0

BEGIN

IF @dbType = ‘varchar’ or @dbType = ‘char’

BEGIN

SET @tmpVarpfx = ‘str’

SET @newType = ‘String’

END

IF @dbType = ‘bigint’

BEGIN

SET @tmpVarpfx = ‘lng’

SET @newType = ‘long’

END

IF @dbType = ‘int’

BEGIN

SET @tmpVarpfx = ‘int’

SET @newType = ‘Integer’

END

IF @dbType = ‘datetime’

BEGIN

SET @tmpVarpfx = ‘dat’

SET @newType = ‘date’

END

SET @tmpVar = @tmpVar + char(13)+ char(9) + ‘Private ‘+  @tmpVarpfx + @fldname + ‘ AS ‘ + @newType

SET @class = @class + char(13) + char(9) + ‘Public Property ‘ + @fldname + ‘() AS ‘ + @newType

SET @class = @class + char(13) + char(9) + char(9) +’GET’

SET @class = @class + char(13) + char(9) + char(9) + char(9)  +’return ‘ + @tmpVarpfx + @fldname

SET @class = @class + char(13) + char(9) + char(9) +’END GET’

SET @class = @class + char(13) + char(9) + char(9) +’SET (value AS ‘+ @newType +’)’

SET @class = @class + char(13) + char(9) + char(9) + char(9)  + @tmpVarpfx + @fldname + ‘ = ‘ + ‘value’

SET @class = @class + char(13) + char(9) + char(9) +’END SET’

SET @class = @class + char(13) + char(9) + ‘END Property’

FETCH NEXT FROM rs

INTO @fldName, @dbType, @len, @precision, @scale

END

CLOSE rs

DEALLOCATE rs

SET @class = @tmpVar + char(13) + @class

SET @class = ‘Public Class ‘ + RIGHT(@tablename, LEN(@tablename) – 3)  + @class

SET @class = @class + char(13) + ‘ End Class’

print @class

, , ,

No Comments


How to create a vb.net structure from table using T-SQL script

/*

params:

@dbType – holds the data type defined in the table structure

@fldName – field/column name

@len – storage length of the column if data type is varchar/char etc.

@precision – numeric

@scale – numeric

@newType – equivalent data type in vb.net; ex. varchar -> string

@struct – script

@tablename – table name

*/

DECLARE @dbType VARCHAR(50)

DECLARE @fldName VARCHAR(50)

DECLARe @len smallint

DECLARE @precision smallint

DECLARE @scale smallint

DECLARE @newType VARCHAR(20)

DECLARE @struct VARCHAR(MAX)

DECLARE @tablename VARCHAR(20)

SET @tablename = ‘tblExchangeDocument’

SET @newType = ”

SET @struct = ‘Public Class ‘ + RIGHT(@tablename, LEN(@tablename) – 3)

DECLARE rs CURSOR FOR

SELECT sys.columns.[name] as fldname, sys.types.name as dbtype,  sys.columns.[max_length], sys.columns.[precision], sys.columns.[scale]

FROM sys.columns INNER JOIN sys.types ON sys.columns.system_type_id = sys.types.system_type_id

WHERE object_id = OBJECT_ID(@tablename)

OPEN rs

FETCH NEXT FROM rs

INTO @fldname, @dbType, @len, @precision, @scale

WHILE @@FETCH_STATUS = 0

BEGIN

IF @dbType = ‘varchar’

SET @newType = ‘String’

IF @dbType = ‘bigint’

SET @newType = ‘long’

IF @dbType = ‘int’

SET @newType = ‘Integer’

IF @dbType = ‘datetime’

SET @newType = ‘date’

SET @struct = @struct + ”

SET @struct = @struct + char(13) + char(9) + ‘ Public ‘ + @fldname + ‘ AS ‘ + @newType

FETCH NEXT FROM rs

INTO @fldName, @dbType, @len, @precision, @scale

END

CLOSE rs

DEALLOCATE rs

SET @struct = @struct + char(13) + ‘ End Class’

print @Struct

, , ,

No Comments


How to Print ASCII characters in SQL Server (T-SQL)

Use char(intValue)

Param: intValue = Is an integer from 0 through 255. NULL is returned if the integer expression is not in this range.

Control character Value

Tab

char(9)

Line feed

char(10)

Carriage return

char(13)


, , , , ,

No Comments



SetPageWidth