Exemple #1
1
        public static System.Drawing.Bitmap GetBitmapFromWebServer(string path)
        {
            System.Drawing.Bitmap bitmap = null;
            byte[] contents = RetrieveFile(path);
            if (contents == null)
                bitmap = null;
            else
            {
                System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter();
                System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(contents);
                bitmap = (System.Drawing.Bitmap)img;
            }

            return bitmap;
        }
        private string GetCaptcha()
        {
            Form       capt  = new Form();
            PictureBox pbx   = new PictureBox();
            TextBox    txtbx = new TextBox();
            Button     btn   = new Button();

            btn.Text   = "Okay";
            txtbx.Dock = DockStyle.Right;
            btn.Dock   = DockStyle.Bottom;

            Hashtable response  = SendPOST("uh=" + m_modhash, m_domain + APIPaths.new_captcha);
            ArrayList respAlist = (ArrayList)response["jquery"];
            string    captAddrs = ((ArrayList)((ArrayList)respAlist[respAlist.Count - 1])[3])[0] as string;

            byte[] pngImage = jsonGet.DownloadData(m_domain + APIPaths.captcha + captAddrs + ".png");
            System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter();
            pbx.Image = (System.Drawing.Image)ic.ConvertFrom((object)pngImage);
            capt.Controls.Add(pbx);
            capt.Controls.Add(txtbx);
            capt.Controls.Add(btn);
            btn.Click += delegate(object sender, EventArgs e)
            {
                capt.Close();
            };
            capt.ShowDialog();
            return(string.Format("{0}&iden={1}", txtbx.Text, captAddrs));
        }
Exemple #3
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //ExifManager exm = new ExifManager();
            //exm.GetExifByImage("../../img.JPG");

            string imgPath = "../../img.JPG";

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(imgPath);


            foreach (System.Drawing.Imaging.PropertyItem item in bmp.PropertyItems)
            {
                if (item.Id == 0x501B)
                {
                    System.Drawing.ImageConverter ic    = new System.Drawing.ImageConverter();
                    System.Drawing.Image          thumb = (System.Drawing.Image)ic.ConvertFrom(item.Value);

                    thumb.Save("../../test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                    continue;
                }
                if (item.Id == 0x5090)
                {
                    string val = System.Text.Encoding.ASCII.GetString(item.Value);
                    val = val.TrimEnd(new char[] { '\0' });
                    Console.WriteLine(val);
                }

                switch (item.Type)
                {
                case 1:
                case 3:
                case 4:
                case 9:
                    Console.Write("{0:X}:{1}:", item.Id, item.Type);
                    foreach (byte b in item.Value)
                    {
                        Console.Write("{0:X}", b);
                    }
                    Console.WriteLine();
                    break;

                case 2:
                    //case 5:
                    //case 7:
                    //case 10:
                    string val = System.Text.Encoding.ASCII.GetString(item.Value);
                    val = val.Trim(new char[] { '\0' });
                    Console.WriteLine("{0:X}:{1}:{2}", item.Id, item.Type, val);
                    break;

                default:
                    Console.WriteLine("{0:X}:{1}:{2}", item.Id, item.Type, item.Len);
                    break;
                }
            }
            bmp.Dispose();
        }
Exemple #4
0
        public static System.Drawing.Bitmap GetBitmapFromWebServer(string path)
        {
            System.Drawing.Bitmap bitmap = null;
            byte[] contents = RetrieveFile(path);
            if (contents == null)
            {
                bitmap = null;
            }
            else
            {
                System.Drawing.ImageConverter ic  = new System.Drawing.ImageConverter();
                System.Drawing.Image          img = (System.Drawing.Image)ic.ConvertFrom(contents);
                bitmap = (System.Drawing.Bitmap)img;
            }

            return(bitmap);
        }
Exemple #5
0
        protected FileResult CreateImageFileResult(byte[] image)
        {
            if (image == null)
            {
                throw new OrgException("No image was set");
            }

            string contentType = "";

            System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();

            using (System.Drawing.Image img = (System.Drawing.Image)converter.ConvertFrom(image))
            {
                string imageType = ImageHelper.GetImageFormat(img);
                if (imageType != null)
                {
                    contentType = "image/" + imageType.ToLower();
                }
            }

            return(File(image, contentType));
        }
Exemple #6
0
        private string GetCaptcha()
        {
            Form capt = new Form();
            PictureBox pbx = new PictureBox();
            TextBox txtbx = new TextBox();
            Button btn = new Button();
            btn.Text = "Okay";
            txtbx.Dock = DockStyle.Right;
            btn.Dock = DockStyle.Bottom;

            Hashtable response = SendPOST("uh=" + m_modhash, m_domain + APIPaths.new_captcha);
            ArrayList respAlist = (ArrayList)response["jquery"];
            string captAddrs = ((ArrayList)((ArrayList)respAlist[respAlist.Count - 1])[3])[0] as string;

            byte[] pngImage = jsonGet.DownloadData( m_domain + APIPaths.captcha + captAddrs + ".png");
            System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter();
            pbx.Image = (System.Drawing.Image)ic.ConvertFrom((object)pngImage);
            capt.Controls.Add(pbx);
            capt.Controls.Add(txtbx);
            capt.Controls.Add(btn);
            btn.Click += delegate(object sender, EventArgs e)
            {
                capt.Close();
            };
            capt.ShowDialog();
            return string.Format("{0}&iden={1}", txtbx.Text, captAddrs);
        }
Exemple #7
0
 public static System.Drawing.Image ByteArrayToImage(byte[] b)
 {
     System.Drawing.ImageConverter imgconv = new System.Drawing.ImageConverter();
     System.Drawing.Image          img     = (System.Drawing.Image)imgconv.ConvertFrom(b);
     return(img);
 }
        /// <summary>
        /// Gets the image.
        /// </summary>
        /// <param name="imageAsByteArray">The image as byte array.</param>
        /// <returns>
        /// Returns an image.
        /// </returns>
        private BitmapImage GetImage(byte[] imageAsByteArray)
        {
            BitmapImage bi = new BitmapImage();

            try
            {
                bi.CacheOption = BitmapCacheOption.OnLoad;
                MemoryStream ms = new MemoryStream(imageAsByteArray);
                ms.Position = 0;
                bi.BeginInit();
                bi.StreamSource = ms;
                bi.EndInit();
            }
            catch
            {
                try
                {
                    //If it fails the normal way try it again with a convert, possible quality loss.
                    System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter();
                    System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(imageAsByteArray);
                    System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap(img);
                    MemoryStream ms = new MemoryStream();
                    bitmap1.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    ms.Position = 0;
                    bi = new BitmapImage();
                    bi.CacheOption = BitmapCacheOption.OnLoad;
                    bi.BeginInit();
                    bi.StreamSource = ms;
                    bi.EndInit();
                }
                catch
                {
                    ShowMessage("Could not load image.");
                }
            }

            return bi;
        }
        private void FolderClickedHandler(object sender, EventArgs e)
        {
            SWF.OpenFileDialog selImg = new SWF.OpenFileDialog()
            {
                AddExtension = true,
                CheckFileExists = true,
                CheckPathExists = true,
                Filter = "Image Files|*.png;*.bmp;*.jpg;*.jpeg;*.tiff;*.tif",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures),
                Multiselect = false,
                SupportMultiDottedExtensions = false,
                ValidateNames = true,
                Title = "Select an Image to Upload",
            };

            Entry.PreventNotifyDisplay = true;
            var result = selImg.ShowDialog();
            Entry.PreventNotifyDisplay = false;

            if (result == SWF.DialogResult.OK)
            {

                FileStream imgFs = null;
                System.Drawing.Image img = null;
                try
                {
                    imgFs = System.IO.File.OpenRead(selImg.FileName);
                    byte[] imgBytes = new byte[imgFs.Length];
                    imgFs.Read(imgBytes, 0, imgBytes.Length);

                    System.Drawing.ImageConverter imgConv = new System.Drawing.ImageConverter();
                    img = imgConv.ConvertFrom(imgBytes) as System.Drawing.Image;

                    UploadAndClipboardStore(img);
                }
                catch (UnauthorizedAccessException)
                {
                    Notifications.Raise(
                        "Could not open the specified file due to inadequate permissions.",
                        NotificationType.Error
                    );
                }
                catch (PathTooLongException)
                {
                    Notifications.Raise(
                        "Could not open the specified file as the path was too long.",
                        NotificationType.Error
                    );
                }
                catch (FileNotFoundException)
                {
                    Notifications.Raise(
                        "The specified file does not exist.",
                        NotificationType.Error
                    );
                }
                catch (DirectoryNotFoundException)
                {
                    Notifications.Raise(
                        "The specified directory does not exist.",
                        NotificationType.Error
                    );
                }
                catch (IOException)
                {
                    Notifications.Raise(
                        "A generic I/O exception occurred when opening the file.",
                        NotificationType.Error
                    );
                }
                finally
                {
                    if (imgFs != null)
                    {
                        imgFs.Close();
                        imgFs.Dispose();
                        img.Dispose();
                    }
                }
            }
        }