Posts Tagged ‘image’

How to convert .net Form to Image
  1. Public Class Form1
  2.  
  3.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  4.         CreateBitmap(Me)
  5.     End Sub
  6.  
  7.     Private Sub CreateBitmap(ByVal con As Control)
  8.         'Dim g As Graphics = Me.CreateGraphics()
  9.  
  10.         Dim b As Bitmap = New Bitmap(Me.Width, Me.Height)
  11.         Me.DrawToBitmap(b, New Rectangle(0, 0, Me.Width, Me.Height))
  12.  
  13.         b.Save("test.jpg", Imaging.ImageFormat.Jpeg)
  14.         b.Dispose()
  15.         'g.Dispose()
  16.     End Sub
  17. End Class

, ,

No Comments


Save, resize image using php
image_type = $image_info[2];
      if( $this->image_type == IMAGETYPE_JPEG ) {
         $this->image = imagecreatefromjpeg($filename);
      } elseif( $this->image_type == IMAGETYPE_GIF ) {
         $this->image = imagecreatefromgif($filename);
      } elseif( $this->image_type == IMAGETYPE_PNG ) {
         $this->image = imagecreatefrompng($filename);
      }
   }
   function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this->image,$filename,$compression);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image,$filename);
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image,$filename);
      }
      if( $permissions != null) {
         chmod($filename,$permissions);
      }
   }
   function output($image_type=IMAGETYPE_JPEG) {
      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this->image);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image);
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image);
      }
   }
   function getWidth() {
      return imagesx($this->image);
   }
   function getHeight() {
      return imagesy($this->image);
   }
   function resizeToHeight($height) {
      $ratio = $height / $this->getHeight();
      $width = $this->getWidth() * $ratio;
      $this->resize($width,$height);
   }
   function resizeToWidth($width) {
      $ratio = $width / $this->getWidth();
      $height = $this->getheight() * $ratio;
      $this->resize($width,$height);
   }
   function scale($scale) {
      $width = $this->getWidth() * $scale/100;
      $height = $this->getheight() * $scale/100;
      $this->resize($width,$height);
   }
   function resize($width,$height) {
      $new_image = imagecreatetruecolor($width, $height);
      imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
      $this->image = $new_image;
   }
}
?>

source

, , , , , ,

No Comments


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



SetPageWidth