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

  • 相关阅读:
    Web Site 与 Web Application 的区别
    Jquery获取text,areatext,radio,checkbox,select值
    C#怎么样操作world文档中的文字型窗体域?
    DataFormatString 用法
    overload和override的区别
    Apollo安装
    工控机基础
    CAN总线技术基础
    dd命令_Linux dd命令:复制(拷贝)文件,并对原文件进行转换
    Unity2021零基础入门教程
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1795292.html
Copyright © 2011-2022 走看看