working on it ...

Filters

Explore Public Snippets

Sort by

Found 14k snippets matching: convert

    public by MarcoDeMagistris  558959  64  7  0

    Converts Unicode string to Ansi String

    Converts Unicode string to Ansi String
    public static string ConvertUnicodeToAnsi(String s)
            {
                /// <summary>
                /// Description: Converts Unicode string to Ansi String
                ///              
                /// </summary>
                /// <exception cref="ArgumentNullException"></code></exception>
                /// <exception cref="EncoderExceptionFallback"></exception>
                /// <exception cref="DecoderExceptionFallback"></exception>
                /// <exception cref="ArgumentException"></exception>
                try
                {
                    byte[] unicodeBytes = Encoding.Unicode.GetBytes(s);
                    byte[] ansiBytes = Encoding.Convert(Encoding.Unicode, Encoding.Default, unicodeBytes);
                    return Encoding.Default.GetString(ansiBytes).ToString();
                }
                catch {
                    throw;
                }
            }

    public by antlong  489192  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 aknorr  171896  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 zonaro  205412  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 Geometry  109524  0  5  0

    FromRGB: Convert from RGB to YCbCr color space (Rec 601-1 specification).

    Convert from RGB to YCbCr color space (Rec 601-1 specification). Source color in RGB color space. Destination color in YCbCr color space.
    /// <summary>
    /// Convert from RGB to YCbCr color space (Rec 601-1 specification). 
    /// </summary>
    /// 
    /// <param name="rgb">Source color in <b>RGB</b> color space.</param>
    /// <param name="ycbcr">Destination color in <b>YCbCr</b> color space.</param>
    /// 
    public static void FromRGB(RGB rgb, YCbCr ycbcr)
    {
        float r = (float)rgb.Red / 255;
        float g = (float)rgb.Green / 255;
        float b = (float)rgb.Blue / 255;
    
        ycbcr.Y = (float)(0.2989 * r + 0.5866 * g + 0.1145 * b);
        ycbcr.Cb = (float)(-0.1687 * r - 0.3313 * g + 0.5000 * b);
        ycbcr.Cr = (float)(0.5000 * r - 0.4184 * g - 0.0816 * b);
    }

    public by Geometry  148395  0  3  0

    GetCommandBuffer: Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket using the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;b...

    Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket using the The command to be converted. The buffer containing the bytes representing the command. The command must be terminated by \r\n. The Nagle algorithm is disabled on the socket to speed things up, so it's
    C#
    using System;
    using System.IO;
    using System.Text;
    using System.Collections.Generic;
    
    /// <summary>
    /// Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket
    /// using the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;byte&gt;&gt;)"/>
    /// </summary>
    /// <param name="value">The command to be converted.</param>
    /// <returns>The buffer containing the bytes representing the command. The command must be terminated by \r\n.</returns>
    /// <remarks>The Nagle algorithm is disabled on the socket to speed things up, so it's recommended to convert a command into a buffer
    /// and use the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;byte&gt;&gt;)"/> to send the command and the additional buffers in one transaction.</remarks>
    public unsafe static IList<ArraySegment<byte>> GetCommandBuffer(string value)
    {
    	var data = new ArraySegment<byte>(Encoding.ASCII.GetBytes(value));
    
    	return new ArraySegment<byte>[] { data };
    }

    public by lbottaro  21540  349  8  0

    How to programmatically convert the Visual Studio coverage file to coveragexml by command line tool in csharp

    This code shows how to programmatically export and convert the coverage data ( .coverage) generated by Visual Studio into a readable xml file (.coveragexml). The xml file can be used to generated a code coverage report, eg using the ReportGenerator tool. The conversion is done using the CoverageInfo and CoverageDS objects and invoking the metho
    using Microsoft.VisualStudio.Coverage.Analysis;
    
    namespace CodeCoverageConverter
    {
        class Program
        {
            static void Main(string[] args)
            {
                if (args == null || args.Length != 3 || args[0] == null || args[1] == null ||  args[2] == null ||
                    string.IsNullOrEmpty(args[0]) || string.IsNullOrEmpty(args[1]) || string.IsNullOrEmpty(args[2]))
                {
                    help();
                    return;
                }
                string coverageFileName = args[0];
                string dllFileName = args[1];
                string coverageXmlFileName = args[2];
                Console.WriteLine("args[0] = " + coverageFileName);
                Console.WriteLine("args[1] = " + dllFileName);
                Console.WriteLine("args[2] = " + coverageXmlFileName);
    
                using (CoverageInfo info = CoverageInfo.CreateFromFile(coverageFileName, new string[] { dllFileName }, new string[] { }))
                {
                    CoverageDS data = info.BuildDataSet();
    
                    data.WriteXml(coverageXmlFileName);
                }
            }
    
            static private void help()
            {
                Console.WriteLine("Help!");
                Console.Write(@"
                    Arguments
                        Args[0]: data coverage file name (data.coverage)
                        Args[1]: DLL to use (myProject.dll)
                        Args[2]: coveragexml file name to be generated (converted.coveragexml)
                     ");
    
            }
    
        }
    }

    public by sherazam  2867  3  5  0

    How to Convert PDF Pages to TIFF Image inside .NET Applications

    This technical tip shows how to convert PDF pages to TIFF image inside .NET Applications. The TiffDevice class allows you to convert PDF pages to TIFF images. This class provides a method named Process which allows you to convert all the pages in a PDF file to a single TIFF image. To convert a particular page in a PDF file to a TIFF image, use an
    // Enter here the actual content of the snippet.            
    //The following code snippet shows how to convert all the PDF pages to a single TIFF image.
    
    //[C# Code Sample]
     
    
    // Open document
    Document pdfDocument = new Document("input.pdf");
    
    // Create Resolution object
    Resolution resolution = new Resolution(300);
    
    // Create TiffSettings object
    TiffSettings tiffSettings = new TiffSettings();
    tiffSettings.Compression = CompressionType.None;
    tiffSettings.Depth = ColorDepth.Default;
    tiffSettings.Shape = ShapeType.Landscape;
    tiffSettings.SkipBlankPages = false;
    
    // Create TIFF device
    TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
    
    // Convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, "output.tif");
    
    //[VB.NET Code Sample]
     
    
    'Open document
    Dim pdfDocument As New Document("input.pdf")
    
    'Create Resolution object
    Dim resolution As New Resolution(300)
    
    'Create TiffSettings object
    Dim tiffSettings As New TiffSettings()
    tiffSettings.Compression = CompressionType.None
    tiffSettings.Depth = ColorDepth.Default
    tiffSettings.Shape = ShapeType.Landscape
    tiffSettings.SkipBlankPages = False
    
    'Create TIFF device
    Dim tiffDevice As New TiffDevice(resolution, tiffSettings)
    
    'Convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, "output.tif")
    
    
    //Convert One Page to TIFF Image
    
    //[C# Code Sample]
     
    
    // Open document
    Document pdfDocument = new Document("input.pdf");
    
    // Create Resolution object
    Resolution resolution = new Resolution(300);
    
    // Create TiffSettings object
    TiffSettings tiffSettings = new TiffSettings();
    tiffSettings.Compression = CompressionType.None;
    tiffSettings.Depth = ColorDepth.Default;
    tiffSettings.Shape = ShapeType.Landscape;
    tiffSettings.SkipBlankPages = false;
    
    // Create TIFF device
    TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
    
    
    // Convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, 1, 1, "output.tif");
    
    
    //[VB.NET Code Sample]
     
    
    'Open document
    Dim pdfDocument As New Document("input.pdf")
    
    'Create Resolution object
    Dim resolution As New Resolution(300)
    
    'Create TiffSettings object
    Dim tiffSettings As New TiffSettings()
    tiffSettings.Compression = CompressionType.None
    tiffSettings.Depth = ColorDepth.Default
    tiffSettings.Shape = ShapeType.Landscape
    tiffSettings.SkipBlankPages = False
    
    'Create TIFF device
    Dim tiffDevice As New TiffDevice(resolution, tiffSettings)
    
    'Convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, 1, 1, "output.tif")
    
    //Use Bradley algorithm during conversion
    
    //[C# Code Sample]
     
    
    string outputImageFile = @"c:\resultant.tif";
    string outputBinImageFile = @"c:\37116-bin.tif";
    //open document
    Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"c:\input.pdf");
    //create Resolution object
    Resolution resolution = new Resolution(300);
    //create TiffSettings object
    TiffSettings tiffSettings = new TiffSettings();
    tiffSettings.Compression = CompressionType.LZW;
    tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp;
    //create TIFF device
    TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
    //convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, outputImageFile);
    
    using (FileStream inStream = new FileStream(outputImageFile, FileMode.Open))
    {
           using (FileStream outStream = new FileStream(outputBinImageFile, FileMode.Create))
           {
                  tiffDevice.BinarizeBradley(inStream, outStream, 0.1);
           }
    }
    
    //[VB.NET Code Sample]
     
    
    Dim outputImageFile As String = "c:\resultant.tif"
    Dim outputBinImageFile As String = "c:\37116-bin.tif"
    'open document
    Dim pdfDocument As Aspose.Pdf.Document = New Aspose.Pdf.Document("c:\input.pdf")
    'create Resolution object
    Dim resolution As Aspose.Pdf.Devices.Resolution = New Aspose.Pdf.Devices.Resolution(300)
    'create TiffSettings object
    Dim tiffSettings As TiffSettings = New TiffSettings()
    tiffSettings.Compression = CompressionType.LZW
    tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp
    'create TIFF device
    Dim tiffDevice As TiffDevice = New TiffDevice(resolution, tiffSettings)
    'convert a particular page and save the image to stream
    tiffDevice.Process(pdfDocument, outputImageFile)
    
    Using inStream As FileStream = New FileStream(outputImageFile, FileMode.Open)
    
        Using outStream As FileStream = New FileStream(outputBinImageFile, FileMode.Create)
            tiffDevice.BinarizeBradley(inStream, outStream, 0.1)
        End Using
    End Using
    
    

    public by sherazam  3159  0  6  0

    How to Convert a Visio Shape to Other File Formats inside .NET Applications

    // Enter here the actual content of the snippet.            The code snippets below show the complete source code for adding new shapes to a Visio diagram.
    
    // [C# Code Sample]
    
    double shapeWidth = 0;
    double shapeHeight = 0;
    
    // load Visio diagram
    Diagram srcVisio = new Diagram("C:/temp/MyVisio.vsd");
    // get Visio page
    Aspose.Diagram.Page srcPage = srcVisio.Pages[1];
    // remove background page
    srcPage.BackPage = null;
    
    // get hash table of shapes, it holds id and name
    Hashtable remShapes = new Hashtable();
    //Hashtable<Long, String> remShapes = new Hashtable<Long, String>();
    foreach (Aspose.Diagram.Shape shape in srcPage.Shapes)
        // for the normal shape
        remShapes.Add(shape.ID, shape.Name);
    
    // iterate through the hash table
    foreach (DictionaryEntry shapeEntry in remShapes)
    {
        long key = (long)shapeEntry.Key;
        string val = (string)shapeEntry.Value;
        Aspose.Diagram.Shape shape = srcPage.Shapes.GetShape(key);
        // check of the shape name
        if (val.Equals("GroupShape1"))
        {
            // move shape to the origin corner
            shapeWidth = shape.XForm.Width.Value;
            shapeHeight = shape.XForm.Height.Value;
            shape.MoveTo(shapeWidth * 0.5, shapeHeight * 0.5);
            // trim page size
            srcPage.PageSheet.PageProps.PageWidth.Value = shapeWidth;
            srcPage.PageSheet.PageProps.PageHeight.Value = shapeHeight;
        }
        else
        {
            // remove shape from the Visio page and hash table
            srcPage.Shapes.Remove(shape);
        }
    }
    remShapes.Clear();
    
    // specify saving options
    Aspose.Diagram.Saving.PdfSaveOptions opts = new Aspose.Diagram.Saving.PdfSaveOptions();
    // set page count to save
    opts.PageCount = 1;
    // set starting index of the page
    opts.PageIndex = 1;
    // save it
    srcVisio.Save("C:/temp/Output.pdf", opts);
    
    
    // [VB.NET Code Sample]
    
    Dim shapeWidth As Double = 0
    Dim shapeHeight As Double = 0
    
    ' load Visio diagram
    Dim srcVisio As New Diagram("C:/temp/MyVisio.vsd")
    ' get Visio page
    Dim srcPage As Aspose.Diagram.Page = srcVisio.Pages(1)
    ' remove background page
    srcPage.BackPage = Nothing
    
    ' get hash table of shapes, it holds id and name
    Dim remShapes As New Hashtable()
    'Hashtable<Long, String> remShapes = new Hashtable<Long, String>();
    For Each shape As Aspose.Diagram.Shape In srcPage.Shapes
        ' for the normal shape
        remShapes.Add(shape.ID, shape.Name)
    Next
    
    ' iterate through the hash table
    For Each shapeEntry As DictionaryEntry In remShapes
        Dim key As Long = CLng(shapeEntry.Key)
        Dim val As String = DirectCast(shapeEntry.Value, String)
        Dim shape As Aspose.Diagram.Shape = srcPage.Shapes.GetShape(key)
        ' check of the shape name
        If val.Equals("GroupShape1") Then
    	' move shape to the origin corner
    	shapeWidth = shape.XForm.Width.Value
    	shapeHeight = shape.XForm.Height.Value
    	shape.MoveTo(shapeWidth * 0.5, shapeHeight * 0.5)
    	' trim page size
    	srcPage.PageSheet.PageProps.PageWidth.Value = shapeWidth
    	srcPage.PageSheet.PageProps.PageHeight.Value = shapeHeight
        Else
    	' remove shape from the Visio page and hash table
    	srcPage.Shapes.Remove(shape)
        End If
    Next
    remShapes.Clear()
    
    ' specify saving options
    Dim opts As New Aspose.Diagram.Saving.PdfSaveOptions()
    ' set page count to save
    opts.PageCount = 1
    ' set starting index of the page
    opts.PageIndex = 1
    ' save it
    srcVisio.Save("C:/temp/Output.pdf", opts)
    
    

    public by Geometry  93315  0  5  0

    Convert: Converts a signed 16-bit integer sample into a 32-bit signed integer sample.

    Converts a signed 16-bit integer sample into a 32-bit signed integer sample. The original sample. The resulting sample.
    /// <summary>
    ///   Converts a signed 16-bit integer sample
    ///   into a 32-bit signed integer sample.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(Int16 from, out Int32 to)
    {
        to = (byte)(((from) >> 8) + 128);
    }
    • Public Snippets
    • Channels Snippets