现在的位置: 首页 > 综合 > 正文

oracle ReadBlobs

2012年01月04日 ⁄ 综合 ⁄ 共 2769字 ⁄ 字号 评论关闭

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

抱歉!评论已关闭.