C# winform 本地选择图片把路径上传到数据库,怎么把绝对地址装换成相对地址?
在picturebox下面有个选择本地的按钮,将在本地选择的图片显示在picturebox里面,将路径保存到数据库中,但保存的是绝对地址,怎么换成相对地址呢?

解决方案 »

  1.   

    因为想把数据库的图片路径显示成图片放在datagridview中,绝对路径不行,想换成相对的。比如:我的程序是放在E盘(程序目录下有个images文件),我选了D盘里的一张图片,怎么把它复制到images文件中呢?这样图片的路径是不是就成了相对的了?问题就是在我打开本地选择后,选择了图片,怎么把图片复制到images文件中?求救求救!
      

  2.   

    不是啊,我知道截取啊,可是每张图片的路径都不一样长,难道我要每个路径都截取,那如果有一千张怎么办,substring不行,split也不行
      

  3.   

    你可以看看字符串属性和pictureBox控件的知识 
      

  4.   


    (1)复制该文件到image (C# 把文件拷贝到指定文件夹 )
                    
    if(!System.IO.Directory.Exists(@"d:\你程序\imgage")) 

    // 目录不存在,建立目录 
    System.IO.Directory.CreateDirectory(@"d:\你程序\imgage"); 
    }String sourcePath = "e:\\源文件目录\\图片文件";String targetPath = "d:\你程序\imgage";bool isrewrite=true; // true=覆盖已存在的同名文件,false则反之System.IO.File.Copy(sourcePath, targetPath, isrewrite);(2)得到本地路径文件
     string fullNameNotExtName = System.Windows.Forms.Application.StartupPath.ToString() + "\\images" + 图片名称;
      

  5.   

    选择文件的过程:
    private void rmiAddPics_Click(object sender, System.EventArgs e)
    {
    System.Windows.Forms.OpenFileDialog  openFileDialog = new OpenFileDialog();
    openFileDialog.Filter =  "JPG files (*.JPG)|*.JPG|BMP files (*.BMP)|*.BMP" ;
    openFileDialog.FilterIndex = 1 ;

    string strFile ="";
    string strDiy = "";
    if(openFileDialog.ShowDialog() == DialogResult.OK)
    {
    strFile=openFileDialog.FileName.ToString();

    string fullNameNotExtName=System.IO.Path.GetFileNameWithoutExtension(strFile); strDiy=System.IO.Path.GetDirectoryName(strFile);
    //FileInfo fi = new FileInfo(strFile); System.Drawing.Image image = Image.FromFile(strFile);

    this.pictureBox1.Image=image;
    MemoryStream ms = new MemoryStream();
    image.Save(ms,image.RawFormat);
    byte[] serializedObject = ms.GetBuffer(); Imgname=this.comboBox1.Text=fullNameNotExtName.Trim();                    
    Imgpath=strFile.Trim();
    Imgcode=serializedObject; ms.Close(); this.comboBox1 .Enabled=false;
    openFileDialog.OpenFile().Close();
    openFileDialog.OpenFile().Flush();
    }
    }
      

  6.   

    [size=16px]想知道是怎么实现显示相对地址的[/size]