Category: Soft/Programming

  • C#: generate image thumbnail

    //create the thumbnail 
    int image_width = 96; 
    int image_height = 96; 
    Image imgThumbnail = imgOriginal.GetThumbnailImage(image_width, image_height, null, IntPtr.Zero); 
    
    //save to file 
    imgThumbnail.Save(Path.GetDirectoryName(AFileName) + @"\a2.bmp", ImageFormat.Bmp);

    or

            private bool ThumbnailCallback()
            {
                return false;
            }
    
            private void ProcessImage(Image imgOriginal)
            {
                //create the thumbnail
                int image_width = 96;
                int image_height = 96;
                Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                Image imgThumbnail = imgOriginal.GetThumbnailImage(image_width, image_height, myCallback, IntPtr.Zero);
    
                //save to files
                imgThumbnail.Save(Path.GetDirectoryName(AFileName) + @"\a2.png");
            }
    
  • C#: random file name

    string path = Path.GetRandomFileName();
    
  • C# and MS SQL Server: add System.Drawing assembly

    Working with images in SQL Server 2005 is not easy because the System.Drawing.dll is not included in the assemblies with SQL Server.

    This library was not added because it does not pass the CLR Verifier, and it has not been fully tested in SQL Server hosted environment (i.e. it could damage the stability and security of SQL Server). Careful consideration should be taken when attempting to manipulate images (or even load images from a file system or webservice).

    To add the System.Drawing.dll assembly to SQL Server use the new create assembly statement. The database you are adding this assembly to must have its TrustWorthy property turned on. The following code demonstrates how to add System.Drawing.dll to the ImageGen database.

    ALTER DATABASE yourDatabase
    SET TRUSTWORTHY ON
    GO
    CREATE ASSEMBLY [System.Drawing]
    FROM 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll'
    WITH PERMISSION_SET = UNSAFE
    GO
    

    Now a managed stored procedure can be created that uses the System.Drawing.dll assembly as shown below (although do not forget to add the assembly reference in the VS project).

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
    using Microsoft.SqlServer.Server;
    using System.Drawing;
    using System.Drawing.Imaging;
    
  • C#: password characters for property in Property Grid

    To not show your passwords in plain text on a propertygrid, just use the PasswordPropertyText attribute:

    [DisplayName("Password"), Category("Authentication"), PasswordPropertyText(true)] 
    public string Password 
    { 
       … 
    }
    
  • C#: image to byte array

        private byte[] ImageToByteArray(Image img) 
        { 
            // stream to save the image to byte array 
            Stream ms = new MemoryStream(); 
            img.Save(ms, img.RawFormat); 
    
            // read to end 
            byte[] imgBytes = new byte[ms.Length-1]; 
            ms.Position = 0; 
            ms.Read(imgBytes, 0, imgBytes.Length); 
            ms.Close(); 
    
            return imgBytes; 
        }
  • ShareIt: new control panel

    ShareIt сегодня запустили уже всем свою новую контрольную панель (v7.0).

    Может я и консерватор, но старая мне больше нравилась. Если бы они еще какой-то новый функционал прикрутили, я бы понял. А так просто изменили весь GUI. По сути старое дерево навигации запихнули в меню+выпадающие окошки. Пока первое впечатление скорее отрицательное…

  • Protected Storage Viewer

    http://www.scalabium.com/psv

    Today I added the possibility to view the storages of Internet Explorer 7.x/8.x

  • SMLog suite v1.7

    Yesterday I changed the default error dialog in SMLog suite

    Error dialog in SMLog v1.7

    The format of log file now is text or XML (see the new Formatting property)

    Also a few minor bugs fixed (list of all graphic adapters, computer name in Windows XP etc)

  • C#: получить имя юнита и номер строки с ошибкой

    Если в сборку включена отладочная информация, то:

    string currentFile = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); 
    int currentLine = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
    
  • ShareIt currency conversion

    I do not understand what currency exchange used in ShareIt for online purchases.

    The license price for our Viewer for MS Outlook Messages is 20 EUR

    Yesterday customer from USA ordered the license and payed $27.44 (he sent to me the pdf with invoice). But as I see from online reports in ShareIt Control Panel the same transaction counted as $24.21

    1. $24.21 is more “correct” due current exchange rates
    2. but why they charged the customer for additionally $3.23 ????

    This is not first time when I see the incorrect transactions in invoices. But still now I do not understand the algorithm for currency exchange in ShareIt:-(