• 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;
                    }
            }

  • 相关阅读:
    net start mongodb 提示:发生系统错误 5,拒绝访问。
    jquery下载所有版本
    国内优秀开源镜像站汇总
    bootstrap导航条报错 Uncaught TypeError: Cannot convert object to primitive value
    null的坑 和 比较运算符、相等运算符的隐式转换问题 (在javascript中,null>=0 为真,null<=0 为真,null==0却为假,null到底是什么?)
    关于 圣杯布局(双飞翼布局)的一些想法
    如何制作图标字体(如何将svg转换为css可用的图标字体)
    VirtualBox-虚拟硬盘扩容-win7
    前端JS导出表格
    JS判断是否是IE浏览器
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1795292.html
Copyright © 2020-2023  润新知