Watermark of images

Posted by Venkat | Labels: ,

We are going to discuss about watermarking the image , the importance of doing the watermark is protected and not to be redistributed , Suppose if you take some online gallery images , like arts,some site which selling photos are restricted his site image. They might be not to allow users to save image by right click on image , or saving the web page.


'Creating Dynamic Watermark on image
Dim objImage As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("~/images/" & "Management.jpg"))
'From File
Dim height As Integer = objImage.Height
'Actual image width
Dim width As Integer = objImage.Width
'Actual image height
Dim bitmapimage As New System.Drawing.Bitmap(objImage, width, height)
' create bitmap with same size of Actual image
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bitmapimage)
'Creates a System.Drawing.Color structure from the four ARGB component
'(alpha, red, green, and blue) values. Although this method allows a 32-bit value
' to be passed for each component, the value of each component is limited to 8 bits.
'create Brush
Dim brush As New SolidBrush(Color.FromArgb(113, 255, 255, 255))
'Adding watermark text on image
g.DrawString("Copywright", New Font("Arial", 18, System.Drawing.FontStyle.Bold), brush, 0, 100)
'save image with Watermark image/picture
'bitmapimage.Save("watermark-image.jpg"); //if u want to save image
Response.ContentType = "image/jpeg"
bitmapimage.Save(Server.MapPath("~/images/Copy.jpg"), ImageFormat.Jpeg)
bitmapimage.Dispose()
objImage.Dispose()

Resize an image using asp.net (vb.net) - Method 2

Posted by Venkat | Labels:

This is the second method of dynamically resizing the image ,


Resize an image using asp.net (vb.net) while uploading it into the server
======================Copy following code to Invoke upload======================

Dim fileExt = System.IO.Path.GetExtension(FileUpload.FileName).ToLower()
Dim previewName As String = Me.txtName.Text & "_preview" & fileExt
If fileExt.ToString.ToLower = ".jpeg" Or fileExt.ToString.ToLower = ".jpg" Or
fileExt.ToString.ToLower = ".gif" Then
Dim previewPic As Bitmap = (ResizeImage(FileUpload.PostedFile.InputStream, 500,
695))
previewPic.Save(Server.MapPath("Images/preview/") & previewName,
ImageFormat.Jpeg)
previewPic.Dispose()
End If
==================Copy following Function for resizing image====================
Function ResizeImage(ByVal streamImage As Stream, ByVal maxWidth As Int32, ByVal
maxHeight As Int32) As Bitmap

Dim originalImage As New Bitmap(streamImage)
Dim newWidth As Int32 = originalImage.Width
Dim newHeight As Int32 = originalImage.Height
Dim aspectRatio As Double = Double.Parse(originalImage.Width) /
Double.Parse(originalImage.Height)
If (aspectRatio <= 1 And originalImage.Width > maxWidth) Then
newWidth = maxWidth
newHeight = CInt(Math.Round(newWidth / aspectRatio))
Else
If (aspectRatio > 1 And originalImage.Height > maxHeight) Then
newHeight = maxHeight
newWidth = CInt(Math.Round(newHeight * aspectRatio))
End If
End If
Dim newImage As New Bitmap(originalImage, newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(newImage)
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear
g.DrawImage(originalImage, 0, 0, newImage.Width, newImage.Height)
originalImage.Dispose()
Return newImage
End Function

Resize Image using asp.net Method - 1

Posted by Venkat | Labels: ,

Here We have to discuss, how to dynamically resize the images using asp.net , generally we used two image one as Thumbnail and another one is big image , so if you upload the big image , we can set the default height and width on code to resize that image , at the same while we upload small image , on resizing the image it will be stretched to the specified height and width and also not seen qualify of image is not good ,

so here , we calculate the width , as per we resize the image

I would prefer this method.

this is the First Method , for this place one fileupload control and button on you design form


Dim thumbWidth As Integer = 132
Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream)
'Create a System.Drawing.Bitmap with the desired width and height of the thumbnail.
Dim srcWidth As Integer = image.Width
Dim srcHeight As Integer = image.Height
Dim thumbHeight As Integer = (srcHeight / srcWidth) * thumbWidth
Dim bmp As New Bitmap(thumbWidth, thumbHeight)
'Create a System.Drawing.Graphics object from the Bitmap which we will use to draw the high quality scaled image
Dim gr As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)
'Set the System.Drawing.Graphics object property SmoothingMode to HighQuality
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
'Set the System.Drawing.Graphics object property CompositingQuality to HighQuality
gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
'Set the System.Drawing.Graphics object property InterpolationMode to High
gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High

' Draw the original image into the target Graphics object scaling to the desired width and height
Dim rectDestination As New System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight)
gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel)

'Save to destination file
bmp.Save(Server.MapPath("~/images/" & FileUpload1.PostedFile.FileName))

' dispose / release resources
bmp.Dispose()
image.Dispose()

Get the directories

Posted by Venkat | Labels:

Here is the code how to get all directories and save them to a List:


//Path with all directories in

String Path = Server.MapPath("Folder1\\"); //Declare List

List<String> GetThreads = new List<String>();

//Get all direcotories

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Path);

foreach (System.IO.DirectoryInfo file in dir.GetDirectories())

{

//This saves all Direcory names like "Folder1", "Folder2", "Folder3", "Folder4";

GetThreads.Add(file.Name);

}

PayOffers.in