working on it ...

Filters

Explore Public Snippets

Sort by

Found 20k snippets matching: image

    public by antlong modified Aug 10, 2015  489172  15  7  1

    Extract JPG images from a PDF

    A command line tool to extract jpg images from pdf files.
    #!/usr/bin/env python
    import sys
    
    
    def main():
        """Extract JPG's from PSD's.
        
        Usage:
          python extract.py filename.pdf
        
        Note:
          All extracted images will be saved to the directory 
          the script is initialized in.
        """
        try:
            pdf = file(sys.argv[1], "rb").read()
        except Exception:
            print "Usage: `python extract.py filename.pdf`"
            return
    
        startmark, endmark = "\xff\xd8", "\xff\xd9"
        startfix, endfix, i, njpg = 0, 2, 0, 0
    
        while True:
            istream = pdf.find("stream", i)
            if istream < 0:
                break
            istart = pdf.find(startmark, istream, istream+20)
            if istart < 0:
                i = istream+20
                continue
            iend = pdf.find("endstream", istart)
            if iend < 0:
                raise Exception("Couldn't find end of stream.")
            iend = pdf.find(endmark, iend-20)
            if iend < 0:
                raise Exception("Couldn't find end of JPG.")
         
            istart += startfix
            iend += endfix
            jpg = pdf[istart:iend]
            with open("jpg%d.jpg" % njpg, "wb") as _f:
                _f.write(jpg)
            njpg += 1
            i = iend
    
        print "Extracted %s JPG files." % njpg
    
    main()
    

    public by clsw modified Nov 21, 2014  350025  0  6  1

    Image upload to API, return direct link. (IMGUR)

    Imgur, one of the best image hosts in the world, has a fantastic API, this is a VERY simple and usable implementation of it, just pass an image to the function and it will return the direct link to yout image, heavily commented and easy to use.
    public string UploadImage(Image img)
            {
                //get a dev key from api.imgur.com, anonymous usage (no user auth) only.
                string devkey = "YOUR_CLIENT_ID (e.g. abcde1f234567g8)";
    
                //define the WebClient we'll use to communicate with Imgur.
                WebClient w = new WebClient();
                
                //adds the Header to authorize this application with Imgur, must include a valid CLIENT_ID from 'devkey' above.
                w.Headers.Add("Authorization", "Client-ID " + devkey);
    
                System.Collections.Specialized.NameValueCollection Keys = new System.Collections.Specialized.NameValueCollection();
                try
                {
                    //Converts the image to a byte array so it can be turned into a string for upload.
                    using (MemoryStream stream = new MemoryStream())
                    {
                        img.Save(stream, ImageFormat.Png);
                        Keys.Add("image", Convert.ToBase64String(stream.ToArray()));
                    }
                    
                    //uploads the string-formatted-image and waits for the response.
                    byte[] responseArray = w.UploadValues("https://api.imgur.com/3/image", Keys);
                    dynamic result = Encoding.ASCII.GetString(responseArray);
    
                    //formats the (long and technical) result into just the direct image link.
                    Regex reg = new Regex("link\":\"(.*?)\""); Match match = reg.Match(result);
                    string url = match.ToString().Replace("link\":\"", "").Replace("\"", "").Replace("\\/", "/");
    
                    //returns the online address of the image.
                    return url;
                }
                catch (Exception s) { MessageBox.Show(s.Message); return "err"; }
            }

    public by zonaro modified Nov 13, 2015  323262  2  7  0

    Crop Image on C#

    Simple snippet to Crop Image from up-left point
    public static Bitmap CropImage(this Bitmap source, Rectangle section)
           {
               Bitmap bmp = new Bitmap(section.Width, section.Height);
               Graphics g = Graphics.FromImage(bmp); 
               g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel); 
               return bmp;
           }
    

    public by sherazam modified Jul 13, 2016  184652  0  5  0

    How to Render an Image of 3D Model from the Camera inside .NET Application

    This Technical tip explains how .NET developers can render an image of 3D model from the camera inside their .NET applications. Using Aspose.3D for .NET, developers can render an image to view a realistic image of 3D model, with or without the enhanced background, textures, shadows and also adjust the image size. The Render method exposed by the Sc
    // Enter here the actual content of the snippet.            // this code example creates a camera in a 3D scene, sets its target and render an image.
    
    // [C# Code Sample]
    
    // For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
    // The path to the documents directory.
    string MyDir = RunExamples.GetDataDir();
    
    // Load scene from file
    Scene scene = new Scene(MyDir + "camera.3ds");
    // Create a camera at (10,10,10) and look at the origin point for rendering,
    // it must be attached to the scene before render
    Camera camera = new Camera();
    scene.RootNode.CreateChildNode("camera", camera);
    camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
    camera.LookAt = Vector3.Origin;
    
    // Specify the image render option
    ImageRenderOptions opt = new ImageRenderOptions();
    // Set the background color
    opt.BackgroundColor = Color.AliceBlue;
    // Tells renderer where the it can find textures
    opt.AssetDirectories.Add(MyDir + "textures");
    // Turn on shadow
    opt.EnableShadows = true;
    // Render the scene in given camera's perspective into specified png file with size 1024x1024
    scene.Render(camera, MyDir + "Render3DModelImageFromCamera_out_.png", new Size(1024, 1024), ImageFormat.Png, opt);
    
    //[VB.NET Code Sample]
    
    ' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
    ' The path to the documents directory.
    Dim MyDir As String = RunExamples.GetDataDir()
    
    ' Load scene from file
    Dim scene As New Scene(MyDir & Convert.ToString("camera.3ds"))
    ' Create a camera at (10,10,10) and look at the origin point for rendering,
    ' it must be attached to the scene before render
    Dim camera As New Camera()
    scene.RootNode.CreateChildNode("camera", camera)
    camera.ParentNode.Transform.Translation = New Vector3(10, 10, 10)
    camera.LookAt = Vector3.Origin
    
    ' Specify the image render option
    Dim opt As New ImageRenderOptions()
    ' Set the background color
    opt.BackgroundColor = Color.AliceBlue
    ' Tells renderer where the it can find textures
    opt.AssetDirectories.Add(MyDir & Convert.ToString("textures"))
    ' Turn on shadow
    opt.EnableShadows = True
    ' Render the scene in given camera's perspective into specified png file with size 1024x1024
    scene.Render(camera, MyDir & Convert.ToString("Render3DModelImageFromCamera_out_.png"), New Size(1024, 1024), ImageFormat.Png, opt)
    

    public by zonaro modified Oct 23, 2015  205407  1  7  0

    Image toBase64 String

    Extension method to convert a System.Drawing.Image to Base64 String
    public static string toBase64(this System.Drawing.Image OriginalImage)
          {
              using (MemoryStream ms = new MemoryStream())
              {
                  OriginalImage.Save(ms, OriginalImage.RawFormat);
                  byte[] imageBytes = ms.ToArray();
                  return Convert.ToBase64String(imageBytes);
              }
          }
    

    public by aknorr modified Apr 30, 2015  171891  0  3  0

    convert VHD file to RAW Image

    convert VHD file to RAW Image: vhd2raw.cmd
    qemu-img convert -O raw source.vhd output.raw
    
    

    public by sherazam modified May 18, 2016  4166  1  6  0

    How to Combine Two or Multiple Images into a Single Image inside .NET Apps

    This technical tip explains how .NET developers can combine single or multiple images inside their .NET applications. This example uses Graphics class and shows how to combine two or more images into a single complete image. To demonstrate the operation, the example creates a new Image canvas in JPEG format and draw images on the canvas surface us
    // Enter here the actual content of the snippet.            
    // Combining Images using Graphics Class
    
    //[C# Code Sample]
    
    //Create an instance of JpegOptions and set its various properties
    Aspose.Imaging.ImageOptions.JpegOptions ImageOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
    
    //Create an instance of FileCreateSource and assign it to Source property
    ImageOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"two_images_result.jpeg", false);
    
    //Create an instance of Image and define canvas size
    using (var image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600))
    {
          //Create and initialize an instance of Graphics
          var graphics = new Aspose.Imaging.Graphics(image);
    
          //Clear the image surface with white color
          graphics.Clear(Aspose.Imaging.Color.White);
    
          // Draw Image
          graphics.DrawImage(Aspose.Imaging.Image.Load(@"input1.jpg"), 0, 0, 600, 300);
          graphics.DrawImage(Aspose.Imaging.Image.Load(@"input2.jpg"), 0, 300, 600, 300);
                    
          // Call save method to save the resultant image.
          image.Save();
    }
     
    //[VB.NET Code Sample]
    
    'Create an instance of JpegOptions and set its various properties
    Dim ImageOptions As New Aspose.Imaging.ImageOptions.JpegOptions()
    
    'Create an instance of FileCreateSource and assign it to Source property
    ImageOptions.Source = New Aspose.Imaging.Sources.FileCreateSource("two_images_result.jpeg", False)
    
    'Create an instance of Image and define canvas size
    Using image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600)
    	'Create and initialize an instance of Graphics
    	Dim graphics = New Aspose.Imaging.Graphics(image)
    
    	'Clear the image surface with white color
    	graphics.Clear(Aspose.Imaging.Color.White)
    
    	' Draw Image
    	graphics.DrawImage(Aspose.Imaging.Image.Load("input1.jpg"), 0, 0, 600, 300)
    	graphics.DrawImage(Aspose.Imaging.Image.Load("input2.jpg"), 0, 300, 600, 300)
    
    	' Call save method to save the resultant image.
    	image.Save()
    End Using
    
    

    public by talaverars modified Dec 15, 2014  168544  0  4  0

    the imagestock the best way to design

    the imagestock the best way to design : gistfile1.txt
    enter www.imagestock.com.mx
    
    

    public by sherazam modified Jun 29, 2016  4251  3  5  0

    How to Crop EMF Image using Shifts or Rectangle Approaches in .NET Applications

    This technical tip explains how .NET developers can Crop an EMF Image inside their .NET applications. Image cropping usually refers to the removal of the outer parts of an image to help improve the framing. Cropping may also be used to cut out some portion of an image to increase the focus on a particular area. Aspose.Imaging for .Net API supports
    // Enter here the actual content of the snippet.            // Cropping by Shifts
    
    //[C# Code Sample]
    
    // create an instance of Rasterization options
    EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
    
    // create an instance of PNG options
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;
    
    //Declare variables to store file paths for input and output images
    string filePath = @"TestEmfBezier.emf";
    string outPath = filePath + ".pdf";
    
    //Load an existing image into an instance of EMF class
    using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
    {
      using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
      {
        //Based on the shift values, apply the cropping on image
        //Crop method will shift the image bounds toward the center of image
        image.Crop(30, 40, 50, 60);
    
        // Set height and width
        pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
        pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;
    
        //Save the results to disk
        image.Save(outputStream, pdfOptions);
      }
    }
     
    //[VB.NET Code Sample]
    
    ' create an instance of Rasterization options
    Dim emfRasterizationOptions As New EmfRasterizationOptions()
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke
    
    ' create an instance of PNG options
    Dim pdfOptions As New PdfOptions()
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions
    
    'Declare variables to store file paths for input and output images
    Dim filePath As String = "TestEmfBezier.emf"
    Dim outPath As String = filePath & Convert.ToString(".pdf")
    
    'Load an existing image into an instance of EMF class
    Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
    	Using outputStream As New FileStream(outPath, FileMode.Create)
    		'Based on the shift values, apply the cropping on image
    		'Crop method will shift the image bounds toward the center of image
    		image.Crop(30, 40, 50, 60)
    
    		' Set height and width
    		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
    		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height
    
    		'Save the results to disk
    		image.Save(outputStream, pdfOptions)
    	End Using
    End Using
    
    // Cropping by Rectangle
    
    //[C# Code Sample]
    
    // create an instance of Rasterization options
    EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
    
    // create an instance of PNG options
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;
    
    //Declare variables to store file paths for input and output images
    string filePath = @"TestEmfExtPen.emf";
    string outPath = filePath + ".pdf";
    
    //Load an existing image into an instance of EMF class
    using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
    {
        using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
        {
            //Create an instance of Rectangle class with desired size
            //Perform the crop operation on object of Rectangle class
            image.Crop(new Aspose.Imaging.Rectangle(30, 50, 100, 150));
    
            // Set height and width
            pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
            pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;
    
            //Save the results to disk
            image.Save(outputStream, pdfOptions);
        }
    }
    
    //[VB.NET Code Sample]
    
    ' create an instance of Rasterization options
    Dim emfRasterizationOptions As New EmfRasterizationOptions()
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke
    
    ' create an instance of PNG options
    Dim pdfOptions As New PdfOptions()
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions
    
    'Declare variables to store file paths for input and output images
    Dim filePath As String = "TestEmfExtPen.emf"
    Dim outPath As String = filePath & Convert.ToString(".pdf")
    
    'Load an existing image into an instance of EMF class
    Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
    	Using outputStream As New FileStream(outPath, FileMode.Create)
    		'Create an instance of Rectangle class with desired size
    		'Perform the crop operation on object of Rectangle class
    		image.Crop(New Aspose.Imaging.Rectangle(30, 50, 100, 150))
    
    		' Set height and width
    		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
    		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height
    
    		'Save the results to disk
    		image.Save(outputStream, pdfOptions)
    	End Using
    End Using
    
    

    public by sherazam modified Dec 30, 2015  2610  0  6  0

    How to Add Watermark to an Image inside .NET Applications

    // Enter here the actual content of the snippet.            
    // Adding a Watermark
    
    //[C# Code Sample]
    
    //Load an existing JPG image
    using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(myDir + "sample.jpg"))
    {
    
        //Declare a String object with Watermark Text
        String theString = "45 Degree Rotated Text";
    
        //Create and initialize an instance of Graphics class
        Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
    
        //Initialize an object of SizeF to store image Size
        Aspose.Imaging.SizeF sz = graphics.Image.Size;
    
        //Creates an instance of Font, initialize it with Font Face, Size and Style
        Aspose.Imaging.Font font = new Aspose.Imaging.Font("Times New Roman", 20, FontStyle.Bold);
    
        //Create an instance of SolidBrush and set its various properties
        Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
        brush.Color = Aspose.Imaging.Color.Red;
        brush.Opacity = 0;
    
        //Initialize an object of StringFormat class and set its various properties
        Aspose.Imaging.StringFormat format = new Aspose.Imaging.StringFormat();
        format.Alignment = Aspose.Imaging.StringAlignment.Center;
        format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces;
    
        //Create an object of Matrix class for transformation
        Aspose.Imaging.Matrix matrix = new Aspose.Imaging.Matrix();
        //First a translation
        matrix.Translate(sz.Width / 2, sz.Height / 2);
        //Then a rotation
        matrix.Rotate(-45.0f);
    
        //Set the Transformation through Matrix
        graphics.Transform = matrix;
    
        //Draw the string on Image
        graphics.DrawString(theString, font, brush, 0, 0, format);
    
        //Save output to disk
        image.Save(myDir + "output.jpg");
    }
     
    //[VB.NET Code Sample]
    
    'Load an existing JPG image
    Using image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(myDir & "sample.jpg")
    
    	'Declare a String object with Watermark Text
    	Dim theString As String = "45 Degree Rotated Text"
    
    	'Create and initialize an instance of Graphics class
    	Dim graphics As New Aspose.Imaging.Graphics(image)
    
    	'Initialize an object of SizeF to store image Size
    	Dim sz As Aspose.Imaging.SizeF = graphics.Image.Size
    
    	'Creates an instance of Font, initialize it with Font Face, Size and Style
    	Dim font As New Aspose.Imaging.Font("Times New Roman", 20, FontStyle.Bold)
    
    	'Create an instance of SolidBrush and set its various properties
    	Dim brush As New Aspose.Imaging.Brushes.SolidBrush()
    	brush.Color = Aspose.Imaging.Color.Red
    	brush.Opacity = 0
    
    	'Initialize an object of StringFormat class and set its various properties
    	Dim format As New Aspose.Imaging.StringFormat()
    	format.Alignment = Aspose.Imaging.StringAlignment.Center
    	format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces
    
    	'Create an object of Matrix class for transformation
    	Dim matrix As New Aspose.Imaging.Matrix()
    	'First a translation
    	matrix.Translate(sz.Width / 2, sz.Height / 2)
    	'Then a rotation
    	matrix.Rotate(-45.0f)
    
    	'Set the Transformation through Matrix
    	graphics.Transform = matrix
    
    	'Draw the string on Image
    	graphics.DrawString(theString, font, brush, 0, 0, format)
    
    	'Save output to disk
    	image.Save(myDir & "output.jpg")
    End Using
    
    
    • Public Snippets
    • Channels Snippets