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

  • 相关阅读:
    前端向后端发送数据时,有时需要转数据格式,但是有时会得到意外的false数据
    js字符串处理,把img标签包裹在p标签里
    antd 对话框、上传图片、轮播图结合在一起
    JavaScript 交换数组元素位置
    codeforces 803 F. Coprime Subsequences (莫比乌斯反演)
    UVa 12716 GCD XOR (数论+bitmask)
    codeforces 1556D
    codeforces 1556 E. Equilibrium (线段树)
    codeforces 1556F
    UVa 1502 GRE Words (DP+AC自动机+jry线段树)
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1795292.html
Copyright © 2011-2022 走看看