zoukankan      html  css  js  c++  java
  • oracle ReadBlobs

       private void BtnReadBlobPhoto_Click(object sender, EventArgs e)
            {
                   try
                    {
                        using (OracleConnection conn = new OracleConnection(BusinessTools.ConnectionString))
                        {
                            conn.Open();

                            string sql = "select photo from usersinfo where id=:v_id";
                            OracleCommand cmd = conn.CreateCommand();
                            cmd.CommandText = sql;
                            cmd.CommandType = CommandType.Text;

                            OracleParameter paraId = new OracleParameter();
                            paraId.ParameterName = "v_id";
                            paraId.OracleDbType = OracleDbType.Int32;
                            paraId.Direction = ParameterDirection.Input;
                            paraId.Value = Convert.ToInt32(txtUserID.Text.Trim());
                            cmd.Parameters.Add(paraId);

                            OracleDataReader dr=  cmd.ExecuteReader();

                            if(dr.Read())
                            {
                              OracleBlob orclBlob =(OracleBlob)dr.GetOracleBlob(dr.GetOrdinal("photo"));

                                System.Drawing.Image original_Img=Image.FromStream(new System.IO.MemoryStream(orclBlob.Value));

                                 // Calculate the new width and height
                                int width = original_Img.Width;
                                int height = original_Img.Height;
                                int target_width = 200;
                                int target_height = 200;
                                int new_width, new_height;

                                float target_ratio = (float)target_width / (float)target_height;
                                float image_ratio = (float)width / (float)height;

                                if (target_ratio > image_ratio)
                                {
                                    new_height = target_height;
                                    new_width = (int)Math.Floor(image_ratio * (float)target_height);
                                }
                                else
                                {
                                    new_height = (int)Math.Floor((float)target_width / image_ratio);
                                    new_width = target_width;
                                }

                                new_width = new_width > target_width ? target_width : new_width;
                                new_height = new_height > target_height ? target_height : new_height;
                                  // Create the thumbnail
                               Image thumbnail_image = original_Img.GetThumbnailImage(new_width, new_height, null, System.IntPtr.Zero);

                               pictureBox1.Image = thumbnail_image;
                               
                            }      
                        }
                    }
                    catch (Exception ex)
                    {
                        string ss = ex.Message;
                    }
            }

  • 相关阅读:
    linux下设置SSH无密码登陆
    设置sudo权限
    集群重启后启动ambari-server访问Web页面无法启动集群解决
    使用Ambari部署hadoop集群
    centos7.6安装python3.7
    Locust
    测试框架(自然语言)
    Maven之(七)pom.xml配置文件详解
    git的使用
    elastic search(es)安装
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1795292.html
Copyright © 2011-2022 走看看