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

  • 相关阅读:
    梯度下降算法 (转)
    机器学习
    杭电1097-A hard puzzle
    动态规划初步习题(紫书)
    4.21考试题解
    【bzoj4445 scoi2015】小凸想跑步
    【bzoj4444 scoi2015】国旗计划
    【bzoj4443 scoi2015】小凸玩矩阵
    【luogu P4007 清华集训2017】小Y和恐怖奴隶主
    【luoguP4006 清华集训2017】小Y和二叉树
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1795292.html
Copyright © 2011-2022 走看看