Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 11-18 of 18 total

Java - rotate -90°/90°

   1  
   2  public BufferedImage rotate90DX(BufferedImage bi)
   3  	{
   4  		int width = bi.getWidth();
   5  		int height = bi.getHeight();
   6  		
   7  		BufferedImage biFlip = new BufferedImage(height, width, bi.getType());
   8  		
   9  		for(int i=0; i<width; i++)
  10  			for(int j=0; j<height; j++)
  11  				biFlip.setRGB(height-1-j, width-1-i, bi.getRGB(i, j));
  12  		
  13  		return biFlip;
  14  	}


   1  
   2  	public BufferedImage rotate90SX(BufferedImage bi)
   3  	{
   4  		int width = bi.getWidth();
   5  		int height = bi.getHeight();
   6  		
   7  		BufferedImage biFlip = new BufferedImage(height, width, bi.getType());
   8  		
   9  		for(int i=0; i<width; i++)
  10  			for(int j=0; j<height; j++)
  11  				biFlip.setRGB(j, i, bi.getRGB(i, j));
  12  		
  13  		return biFlip;
  14  	}

Java - HalfFlipH / HalfFlipW

   1  
   2  	public BufferedImage halfFlipW(BufferedImage bi)
   3  	{
   4  		int width = bi.getWidth();
   5  		int height = bi.getHeight();
   6  		
   7  		BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
   8  		
   9  		for(int i=0; i<width; i++)
  10  			for(int j=0; j<height/2; j++)
  11  			{
  12  				biFlip.setRGB(i, j, bi.getRGB(i, j));
  13  				biFlip.setRGB(i, (height-1)-j, bi.getRGB(i, j));
  14  			}
  15  		
  16  		return biFlip;
  17  	}


   1  
   2  	public BufferedImage halfFlipH(BufferedImage bi)
   3  	{
   4  		int width = bi.getWidth();
   5  		int height = bi.getHeight();
   6  		
   7  		BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
   8  		
   9  		for(int i=0; i<width/2; i++)
  10  			for(int j=0; j<height; j++)
  11  			{
  12  				biFlip.setRGB(i, j, bi.getRGB(i, j));
  13  				biFlip.setRGB((width-1)-i, j, bi.getRGB(i, j));
  14  			}
  15  		
  16  		return biFlip;
  17  	}

Java - FlipH / FlipW

   1  
   2  public BufferedImage flipH(BufferedImage bi)
   3  	{
   4  		int width = bi.getWidth();
   5  		int height = bi.getHeight();
   6  		
   7  		BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
   8  		
   9  		for(int i=0; i<width; i++)
  10  			for(int j=0; j<height; j++)
  11  				biFlip.setRGB((width-1)-i, j, bi.getRGB(i, j));
  12  		
  13  		return biFlip;
  14  	}


   1  	
   2  	public BufferedImage flipW(BufferedImage bi)
   3  	{
   4  		int width = bi.getWidth();
   5  		int height = bi.getHeight();
   6  		
   7  		BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
   8  		
   9  		for(int i=0; i<width; i++)
  10  			for(int j=0; j<height; j++)
  11  				biFlip.setRGB(i, (height-1)-j, bi.getRGB(i, j));
  12  		
  13  		return biFlip;
  14  	}

Acceder a la fecha en la que una foto fue tomada en VB .NET

//Función a la que se le pasa el archivo jpg o jpge y devuelve la fecha en la que fue tomada

   1  
   2      Public Function ObtieneFecha(ByVal RutaArchivo As String) As Date
   3  
   4          Dim image As New Bitmap(RutaArchivo)
   5          Dim propItems As System.Drawing.Imaging.PropertyItem() = image.PropertyItems
   6  
   7          Dim encoding As New System.Text.ASCIIEncoding
   8  
   9          For i As Integer = propItems.GetLowerBound(0) To propItems.GetUpperBound(0)
  10              If propItems(i).Id.ToString = "36868" Then
  11                  Dim strAux1() As String = Split(encoding.GetString(propItems(i).Value), " ")
  12                  Dim strAux2() As String = Split(strAux1(0), ":")
  13                  Dim strAux3() As String = Split(strAux1(1), ":")
  14                  Return CDate(strAux2(0) & "/" & strAux2(1) & "/" & strAux2(2) & " " & strAux3(0) & ":" & strAux3(1) & ":" & strAux3(2))
  15              End If
  16          Next
  17          image.Dispose()
  18      End Function

Java - ZoomOUT image

   1  
   2  public BufferedImage zoomOut(BufferedImage bi, int scale)
   3  	{
   4  		int width = bi.getWidth() / scale;
   5  		int height = bi.getHeight() / scale;
   6  		
   7  		BufferedImage biScale = new BufferedImage(width, height, bi.getType());
   8  		
   9  		for(int i=0; i<width; i++)
  10  			for(int j=0; j<height; j++)
  11  				biScale.setRGB(i, j, bi.getRGB(i*scale, j*scale));
  12  		
  13  		return biScale;
  14  	}

Java - ZoomIN Image

   1  
   2  public BufferedImage zoomIn(BufferedImage bi, int scale)
   3  	{
   4  		int width = scale * bi.getWidth();
   5  		int height = scale * bi.getHeight();
   6  		
   7  		BufferedImage biScale = new BufferedImage(width, height, bi.getType());
   8  		
   9                  // Cicla dando un valore medio al pixel corrispondente
  10  		for(int i=0; i<width; i++)
  11  			for(int j=0; j<height; j++)
  12  				biScale.setRGB(i, j, bi.getRGB(i/scale, j/scale));
  13  		
  14  		return biScale;
  15  	}

Bash - Creare una galleria di mini immagini

// Prende le immagini di una cartella e ne crea delle copie
// della dimensione di 320x240

   1  
   2  #!/bin/sh
   3  
   4  for i in `ls *.jpg`;
   5  do
   6  	convert -geometry 320x240 $i galleria-$i
   7  done

Create a single JPG gallery from an image archive

The following comes from Jason Scott and is posted here with permission under the Creative Commons Attribution-ShareAlike License.

The script expands a zip or rar archive of images, makes thumbnails, and compiles the thumbnails into a single JPG to represent what's in the archive. Requires ImageMagick.

Code:
   1  
   2  #!/bin/sh
   3  # GALLERATE: Turn a zip of images into a gallery.
   4  # From Jason Scott. http://ascii.textfiles.com/archives/000137.html
   5  if [ -f "$1" ]
   6     then
   7     rm -rf .galleryworld
   8     echo "[%] Preparting to squat out $1...."
   9     mkdir .galleryworld
  10     cd .galleryworld
  11     unzip -j "../$1"
  12     unrar e -ep "../$1"
  13     echo "[%] WHY DOES IT HURT!!!!"
  14     montage +frame +shadow +label -tile 7 *.JPG *.GIF *.gif *.jpg *.bmp *.png *.PNG *.BMP "../$1.jpg"
  15     cd ..
  16     rm -rf .galleryworld
  17     ls -l "$1.jpg"
  18    else
  19    echo "No such file, assmaster."
  20  fi


Usage:
   1  
   2  GALLERATE [file]

where [file] is the zip or rar archive of images to be processed.
« Newer Snippets
Older Snippets »
Showing 11-18 of 18 total