DOBON.NETプログラミング道掲示板

■35323 / 7階層)  複数のPictureBox画像を複数のファイルへ保存したい
□投稿者/ ま〜 一般人(42回)-(2023/01/12(Thu) 14:13:11)
  • アイコンいつもありがとうございます
    フィールド変数の件は棚ぼたです。出来ないと思ってました。助かります。

    本題ですが先のコードでわDisposeした方が良いのか程度で書いてました
    Form LoadでDisposeしてますがボタンクリックでTextBoxから画像を生成して各PictureBoxに書いてますので問題ないと解釈していました
    今二つの問題に当たっています。スレッドを分けなかったのは同じ要因かなと思ってです。

    流れ RichTextBoxへ文字入力 ⇒生成⇒ PictureBox16 ⇒サイズを変えてコピー⇒ 各PictureBox ⇒ すべてのPictureBoxの画像をファイル保存


    ――――――――ボタン@――――――――ー
    Dim bmp = CreateBitmapFromControl(Rbox(PageNo))
    If PictureBox16.Image IsNot Nothing Then
      PictureBox16.Image.Dispose()
    End If

    ‘P PageNo←どのPictureBoxを操作するか
    PictureBox16.Image = bmp ← 自動生成されたイメージが入っている
    ‘ピクチャ1−15へ各個転送
    Dim Picture() As PictureBox = {PictureBox1, PictureBox2, PictureBox3, ・・・・・PictureBox15} 
    Picture(PageNo).Image = PictureBox16.Image

    これは同じ画像を各PictureBoxへ書いたと同じ扱いになりますか?一旦PictureBox16経由で各PictureBoxへ作画されています
    これがやっては駄目な事でしょうか?

    最後の書いたPictureBoxをBで保存する事は出来ました。
    それ以外のPictureBox以外でBのコードを実行するエラーとなる

    ―――――――Bエラーになる箇所――――――――――
    Picture(PageNo).Image.Save(PicturePath"MojiGAZou1.bmp",System.Drawing.Imaging.ImageFormat.Bmp)


    Imageは使わない方がよいのでしょうか?

    ―――――――――ボタンA――――――――――――
    試してみました

    Dim Picture() As PictureBox = {PictureBox1, PictureBox2, PictureBox3, PictureBox4, PictureBox5}
    For i As Byte = 0 To 4
    Picture(i).Size = New Size(Picture(i).Size.Width, 320)
    Picture(i).Size = New Size(Picture(i).Size.Height, 160)
    Picture(i).SizeMode = PictureBoxSizeMode.Zoom
    Picture(i).Image = Image.FromFile(PicturePath + "MojiGAZou" & CStr(i + 1) & ".bmp")
    Next

    Me.PictureBox1.Image.Save(PicturePath + "MojiGAZou1.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
    Me.PictureBox2.Image.Save(PicturePath + "MojiGAZou2.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
    Me.PictureBox3.Image.Save(PicturePath + "MojiGAZou3.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
    Me.PictureBox4.Image.Save(PicturePath + "MojiGAZou4.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
    Me.PictureBox5.Image.Save(PicturePath + "MojiGAZou5.bmp", System.Drawing.Imaging.ImageFormat.Bmp)

    これもPictureBox1.のSaveの所でエラーとなります。こんな事は出来ない?

    以下はエラーの内容です

    System.Runtime.InteropServices.ExternalException
    HResult=0x80004005
    Message=GDI+ で汎用エラーが発生しました。
    Source=System.Drawing
    スタック トレース:
    at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
    at System.Drawing.Image.Save(String filename, ImageFormat format)
    at Test.文字編集Form.Button18_Click(Object sender, EventArgs e) in C:\Users\userMM\OneDrive\Test\文字編集Form.vb:line 232
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    at Test.My.MyApplication.Main(String[] Args) in :line 83


    Disposeする必要は無いので何か良い方法はありますか?

    あと

    >No35282 の KOZ さんの実装パターンに相当しますね。
    >
    > PictureBox1.Image?.Dispose() '処分
    > PictureBox1.Image = Nothing '解放

    とありますがこれはどの様な意味ですか?

    以上、長々とすみません

違反を報告
削除キー/

前の記事(元になった記事) 次の記事(この記事の返信)
←Re[6]: PictureBoxの画像を連続保存 /魔界の仮面弁士 →Re[8]: 複数のPictureBox画像を複数のファイルへ保存したい /魔界の仮面弁士
 
上記関連ツリー

Nomalアイコン PictureBoxの画像を連続保存 / ま〜 (23/01/10(Tue) 19:41) #35316
Nomalアイコン Re[1]: PictureBoxの画像を連続保存 / 魔界の仮面弁士 (23/01/10(Tue) 20:23) #35317
  └Nomalアイコン Re[2]: PictureBoxの画像を連続保存 / ま〜 (23/01/11(Wed) 13:59) #35318
    └Nomalアイコン Re[3]: PictureBoxの画像を連続保存 / 魔界の仮面弁士 (23/01/11(Wed) 14:06) #35319
      └Nomalアイコン Re[4]: PictureBoxの画像を連続保存 / ま〜 (23/01/11(Wed) 16:06) #35320
        └Nomalアイコン Re[5]: PictureBoxの画像を連続保存 / ま〜 (23/01/11(Wed) 16:49) #35321
          └Nomalアイコン Re[6]: PictureBoxの画像を連続保存 / 魔界の仮面弁士 (23/01/11(Wed) 17:36) #35322
            └Nomalアイコン 複数のPictureBox画像を複数のファイルへ保存したい / ま〜 (23/01/12(Thu) 14:13) #35323 ←Now
              └Nomalアイコン Re[8]: 複数のPictureBox画像を複数のファイルへ保存したい / 魔界の仮面弁士 (23/01/12(Thu) 16:00) #35324
                └Nomalアイコン Re[9]: 複数のPictureBox画像を複数のファイルへ保存したい / ま〜 (23/01/16(Mon) 14:20) #35330
                  └Nomalアイコン Re[10]: 複数のPictureBox画像を複数のファイルへ保存したい / 魔界の仮面弁士 (23/01/16(Mon) 16:14) #35331
                    └Nomalアイコン Re[11]: 複数のPictureBox画像を複数のファイルへ保存したい / ま〜 (23/01/20(Fri) 12:55) #35340 解決み!

All 上記ツリーを一括表示 / 上記ツリーをトピック表示
 
上記の記事へ返信

Mode/  Pass/


- Child Tree -