Example #1
0
        private void cmdLocalizarLogo_Click(object sender, EventArgs e)
        {
            if (this.foFile_Open.ShowDialog() == DialogResult.OK)
            {
                //-- Localiza e abre o arquivo em Steam
                FileStream fs = new FileStream(this.foFile_Open.FileName
                                               , FileMode.OpenOrCreate
                                               , FileAccess.Read);

                //-- Converte o arquivo para Binario.
                byte[] MyData = new byte[fs.Length];
                fs.Read(MyData, 0, Convert.ToInt32(fs.Length));
                fs.Close();

                TrataImagem  t         = new TrataImagem(150, 50, TrataImagem.Tipos_Redicionamento.Proporcional);
                MemoryStream ms        = new MemoryStream(MyData);
                Image        img_Final = t.Redimencionar(Image.FromStream(ms));
                this.pictureBox1.Image = img_Final;
                img_Final.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

                //-- Atualiza registro.
                DataRowView RowView = (DataRowView)this.BindingSource[this.MainTabela].Current;
                img_Final.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                RowView.Row["Logo_Banco"] = ms.ToArray();
            }
        }
Example #2
0
        private void cmdAbrirImagem_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog fd = new OpenFileDialog();
                fd.AutoUpgradeEnabled = true;
                fd.CheckFileExists    = true;
                fd.CheckPathExists    = true;
                fd.Filter             = "Todos os arquivos de imagem|*.jpg;*.bmp;*.png;*.gif|Arquivos Jpg|*.jpg|Arquivos Bmp|*.bmp|Arquivo Png|*.png|Arquivos Gif|*.gif";
                fd.Title         = "Encontra imagem do produto";
                fd.ValidateNames = true;

                if (fd.ShowDialog() == DialogResult.OK)
                {
                    Image img = Bitmap.FromFile(fd.FileName);
                    CompSoft.Tools.TrataImagem ti = new TrataImagem(TrataImagem.Tipos_Redicionamento.Proporcional);
                    ti.Width  = 240;
                    ti.Height = 240;
                    Image newImg = ti.Redimencionar(ref img);

                    this.picProduto.Image = newImg;

                    //-- Adiciona imagem no dataset.
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    newImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    this.CurrentRow["Imagem"] = ms.ToArray();

                    ms.Close();
                    newImg.Dispose();
                    img.Dispose();
                }
                else
                {
                    this.CurrentRow["Imagem"] = DBNull.Value;
                }
            }
            catch (Exception ex)
            {
                MsgBox.Show(ex.Message);
            }
        }