すいません、VB4しかやってないんです、VBAはやったけど(ぼそ) チラシの裏だって立派な書き込み空間なんだからねっ!資源の有効活用なんだからねっ!とか偉そうに言ってるけど、実は色々と書き残したいだけ

だからなに? どうしろと? くるみサイズの脳みそしかないあやしいジャンガリアンベムスターがさすらう贖罪蹂躙(ゴシックペナルティ)

ホーム 連絡をする 同期する ( RSS 2.0 ) Login
投稿数  632  : 記事  35  : コメント  11675  : トラックバック  143

ニュース


片桐 継 は
こんなやつ

かたぎり つぐ ってよむの

大阪生まれ河内育ちなんだけど
関東に住みついちゃったの
和装着付師だったりするの
エセモノカキやってたりするの
VBが得意だったりするの
SQL文が大好きだったりするの
囲碁修行中だったりするの
ボトゲ好きだったりするの
F#かわいいよF#

正体は会った人だけ知ってるの

空気読まなくてごめんなさいなの


わんくまリンク

C#, VB.NET 掲示板
C# VB.NET掲示板

わんくま同盟
わんくま同盟Blog


WindowsでGo言語
WindowsでGo言語


ネット活動


SNSは疲れました

記事カテゴリ

書庫

日記カテゴリ

ギャラリ

イベント活動

プログラムの活動

おもわずツッコンでしまった。反省はしていない。

やりたかったこと=「一辺が3000ピクセルとかでかいサイズの写真をちっちゃくしてやんよ!」

勉強がてら作ってみるぜ!ってことで、VisualSudio2008で作ってみたサンプル。

 image

画面こんな感じ。InとOut用のファイルダイアログと、ボタン2つとピクチャボックス

Public Class Form1

    Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
        '読み込みボタン処理

        Dim myFile As String

        'マイドキュメントをみてやんよ!
        openDialog.InitialDirectory = _
            Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

        If openDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then

            'ファイルとってきたら、イメージ変換だぜ!
            myFile = openDialog.FileName

            'オリジナルのサイズで読み込み
            Dim orgImage As Image = Image.FromFile(myFile)

            Dim newBitmap As New Bitmap(orgImage)

            'ちっちゃくするサイズ決定(今回は横200px固定)
            Dim setW As Integer = 200
            Dim setH As Integer = Int(newBitmap.Height * (setW / newBitmap.Width))

            'ちっちゃくするイメージ準備
            Dim convBitmap As New Bitmap(setW, setH)

            Dim convGraphics = Graphics.FromImage(convBitmap)
            convGraphics.DrawImage(orgImage, New Rectangle(0, 0, setW, setH))

            'ちっちゃくできたら、オリジナルはサヨウナラ
            orgImage.Dispose()

            '画面にサンプルイメージ表示
            convPicture.Width = setW
            convPicture.Height = setH
            convPicture.SizeMode = PictureBoxSizeMode.StretchImage

            convPicture.Image = convBitmap
            convPicture.Tag = IO.Path.GetExtension(myFile)

        End If

    End Sub

    Private Sub btnDo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDo.Click
        'ほぞん処理

        'マイドキュメントにいれてやんよ!
        SaveDialog.InitialDirectory = _
            Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

        SaveDialog.Filter = String.Format("(*{0})|*{0}", convPicture.Tag)
        SaveDialog.DefaultExt = convPicture.Tag

        If SaveDialog.ShowDialog = Windows.Forms.DialogResult.OK Then

            'JPGとBMPでいれちゃうよー

            If convPicture.Tag.ToString.ToLower = ".jpg" Then

                convPicture.Image.Save(SaveDialog.FileName, Imaging.ImageFormat.Jpeg)

            ElseIf convPicture.Tag.ToString.ToLower = ".bmp" Then

                convPicture.Image.Save(SaveDialog.FileName, Imaging.ImageFormat.Bmp)

            End If

        End If

    End Sub
End Class

ソースはこれで全部。

「よみこみ」ボタン押して「ほぞん」ボタン押すだけの簡単なお仕事。

でも、ここに至るまでが大変だったの。

  • 行32~33にDisposeを入れて使ったImageクラスは破棄、
  • PictureBoxコントロールへFromFileで処理していた部分をBitmapクラスから読み込むように変更

をしておかないと、

「GDI+ で汎用エラーが発生しました。」なんて言われて、行61~69のSave処理で叱られまする。

(ほかにも色々といじったような気もするけど<おい。とにかく、このソースでは出なくなったのでw)

Image.FromFile メソッド (String, Boolean) (System.Drawing)
http://msdn.microsoft.com/ja-jp/library/4sahykhd(vs.80).aspx

image 

↑ なんとなく気になった記述。原因となったのかどうかは判んないけど。確かに、これの対処したら、出なくなった。

投稿日時 : 2010年5月20日 18:33

コメント

# doxycycline 50 mg https://doxycyline1st.com/
online doxycycline 2022/02/26 9:48 Jusidkid
doxycycline 50 mg https://doxycyline1st.com/
online doxycycline

# clomid coupons https://clomiden.fun/ 2022/04/12 13:02 Clomids
clomid coupons https://clomiden.fun/

# 1 mg prednisone daily http://prednisonefast.site/ 2022/04/16 22:57 Prednisone
1 mg prednisone daily http://prednisonefast.site/

# lasix 100mg https://buylasix.icu/
lasix side effects 2022/06/24 17:14 LasixRx
lasix 100mg https://buylasix.icu/
lasix side effects

# clomiphene for sale https://clomidonline.icu/ 2022/07/08 13:43 Clomidj
clomiphene for sale https://clomidonline.icu/

# ivermectin lice https://stromectolbestprice.com/ 2022/07/30 0:37 BestPrice
ivermectin lice https://stromectolbestprice.com/

# non prescription ed pills: https://medrxfast.com/ 2022/08/03 19:14 MedsRxFast
non prescription ed pills: https://medrxfast.com/

# metformin purchase https://glucophage.top/
generic metformin prescription mexico 2022/08/23 7:58 Niujsdkj
metformin purchase https://glucophage.top/
generic metformin prescription mexico

# pills for erection https://ed-pills.xyz/
pills for ed 2022/09/15 19:18 EdPills
pills for erection https://ed-pills.xyz/
pills for ed

# can we buy amoxcillin 500mg on ebay without prescription https://antibiotic.best/ 2022/10/08 3:50 Antibiotic
can we buy amoxcillin 500mg on ebay without prescription https://antibiotic.best/

# doxycycline 50 mg https://buydoxycycline.icu/ 2022/10/08 11:58 Doxycycline
doxycycline 50 mg https://buydoxycycline.icu/

# prednisone cream https://prednisonepills.site/
prednisone purchase canada 2022/11/30 0:58 Prednisone
prednisone cream https://prednisonepills.site/
prednisone purchase canada

# natural remedies for ed https://edpills.science/
ed meds online 2023/01/07 8:46 Edpills
natural remedies for ed https://edpills.science/
ed meds online

# Read here. Get warning information here.
https://edonlinefast.com
Learn about the side effects, dosages, and interactions. Get warning information here. 2023/02/18 15:45 EdOnline
Read here. Get warning information here.
https://edonlinefast.com
Learn about the side effects, dosages, and interactions. Get warning information here.

# Comprehensive side effect and adverse reaction information. Get information now.
https://canadianfast.com/
Prescription Drug Information, Interactions & Side. Drug information. 2023/02/20 6:01 CanadaBest
Comprehensive side effect and adverse reaction information. Get information now.
https://canadianfast.com/
Prescription Drug Information, Interactions & Side. Drug information.

# doors2.txt;1 2023/03/14 15:30 gtEWqzyqIwT
doors2.txt;1

# over the counter anxiety meds https://overthecounter.pro/# 2023/05/08 23:15 OtcJikoliuj
over the counter anxiety meds https://overthecounter.pro/#

# cheap erectile dysfunction pills: https://edpills.pro/# 2023/05/15 15:43 EdPillsPro
cheap erectile dysfunction pills: https://edpills.pro/#

# prednisone 20 mg without prescription https://prednisonepills.pro/# - prednisone buying 2023/06/04 21:36 Prednisone
prednisone 20 mg without prescription https://prednisonepills.pro/# - prednisone buying

# cure ed https://edpill.pro/# - cures for ed 2023/06/27 14:56 EdPills
cure ed https://edpill.pro/# - cures for ed

# paxlovid covid https://paxlovid.pro/# - paxlovid generic 2023/07/02 17:37 Paxlovid
paxlovid covid https://paxlovid.pro/# - paxlovid generic

# ï»¿paxlovid https://paxlovid.life/# paxlovid for sale 2023/07/25 20:47 Paxlovid
paxlovid https://paxlovid.life/# paxlovid for sale

# buy cytotec pills https://cytotec.ink/# - buy cytotec online fast delivery 2023/07/26 14:46 PillsFree
buy cytotec pills https://cytotec.ink/# - buy cytotec online fast delivery

# sweetie fox cosplay https://sweetiefox.pro/ - sweetie fox full
2024/03/06 22:16 SwitieFox
sweetie fox cosplay https://sweetiefox.pro/ - sweetie fox full


# gates of olympus oyna demo - https://gatesofolympus.auction/ gates of olympus slot 2024/03/27 20:49 Olympic
gates of olympus oyna demo - https://gatesofolympus.auction/ gates of olympus slot

Post Feedback

タイトル
名前
Url:
コメント