2017-05-09 11 views
-2

コードが実行中です。ファイルからイメージを取得し、それを暗号化します。それを保存します。暗号化されたイメージを取得し、復号化して保存した後。しかし、画像はpicturebox3には見えませんでした3。どのようにpicturebox3の画像を復号化して見るのですか?WindowsフォームアプリケーションのC#画像処理

はありがとう マイデクリプションコード:

public string DecryptPassword(String ImageUrl) 
{ 
    byte[] ImageBytes; 

    ImageBytes = File.ReadAllBytes(ImageUrl); 

    for (int i = 0; i < ImageBytes.Length; i++) 
    { 
     ImageBytes[i] = (byte)(ImageBytes[i]^5); 
    } 

    File.WriteAllBytes(ImageUrl, ImageBytes);   

    return ImageUrl; 
} 

コールを

private void button3_Click(object sender, EventArgs e) 
{ 
    open.DefaultExt = "jpg"; 
    open.ShowDialog(); 
    DecryptPassword(open.FileName); 
} 
+2

コードが見つからない限り、あなたの 'ピクチャボックス(PictureBox) 'はコードなしで画像を表示することはできません。 – auhmaan

+0

' pictureBox3.Image = new Bitmap(open.FileName);のようなものを試してみてください。 'DecryptPassword(open.FileName)'を呼び出します。 – adv12

+0

解読したファイルをディスクに保存して、元のファイルを上書きすることにも注意してください。これは、あなたの望むことですか? – adv12

答えて

0

オーケー方法は、あなたがここに貼り付けたコードは、あなたの完全コードであると仮定しましょう、あなたは「ドン画像をPictureBoxに設定する方法を知っています。そのような場合、我々はあなたのbutton3_Clickイベントを取得し、次の操作を行って、そこPictureBox画像を設定することができます。

private void button3_Click(object sender, EventArgs e) { 
    open.DefaultExt = "jpg"; 
    open.ShowDialog(); 

    // Since you're returning the image path, we can grab it here 
    String 
     imageFilepath = DecryptPassword(open.FileName); 

    // Create a new Bitmap with the image path returned from earlier 
    Bitmap 
     imageBitmap = new Bitmap(imageFilepath); 

    // Set the Bitmap to your PictureBox 
    pictureBox3.Image = (Image) imageBitmap; 
} 

これはあなたのPictureBoxに画像を設定するのに十分でなければなりません。


注意

adv12が指摘したように、あなたは復号化された画像を保存するために使用されるファイル名を変更したい場合があります。

+0

イメージが追加されました。 –