Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Sorry.... this is another how to save question.

I have looked in every forum for a solution, and I think I have tried every solution with no success.

I guess I'm a complete idiot or old...same thing I guess.

I'm attempting to perform some simple image manipulation using a simple form with simple controls and 2 images. Image on left is unmodified, image on right is the modified "preview". any changes to the control (slider etc) invalidate the form calling onpaint. So far so good - nice simple UI , preview works nice .......... until I try to save. Then I get the same old "my changes are not being saved".

Well...my changes are not being saved.

No, I am not using picture boxes , and yes I am creating a bitmap and writing to that as opposed to the control.

No...I am not drawing silly little lines or arcs etc on the picture, and YES I have looked at every bit of GDI documentation I could find (most of which is junk!).

Please point out my stupid blunder:

Private Sub Frm_GDI_SUX_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Dim ArrayPts As Single()() = {New Single() {1, 0, 0, 0, 0}, _
         New Single() {0, 1, 0, 0, 0}, _
         New Single() {0, 0, 1, 0, 0}, _
         New Single() {0, 0, 0, tpVal, 0}, _
         New Single() {0, 0, 0, 0, 1}}
       Dim colorMat As New ColorMatrix(ArrayPts)
       Dim Attrib As New ImageAttributes()
       Attrib.SetColorMatrix(colorMat, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)
       Dim ModImg As Image = Image.FromFile(GetFileName(Active_Ctl))
       Dim bmp As New Bitmap(ModImg)
       e.Graphics.FromImage(bmp)
       e.Graphics.DrawImage(bmp, New Rectangle(265, 10, 200, 200), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, Attrib)
       bmp.Save("c:\GDI_sux.bmp")
End Sub

 

Please forgive my ignorance as I normally write code that does something bigger than playing with silly little pictures or worse..games.

My wife has requested a small app to manipulate some images...I wisely replied with a "Yes dear"....here we are....

Help me..... the sooner I can get this thing behind me the sonner I can get out of this silly GDI thing,.

Edited by Volte
  • *Experts*
Posted
Graphics.FromImage() returns a Graphics object. You need to change the last few lines of code to this:
Dim bmp As New Bitmap(ModImg)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(bmp, New Rectangle(265, 10, 200, 200), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, Attrib)
bmp.Save("c:\blah.bmp")

Posted

Thanks...but been there done that (but tried it again anyway)

The graphics do not draw, and the save throws "Object reference not set to an instance of an object"

 

I understand what you are saying and have tried it (and various combinations) countless times.

If I use e.graphics, everything runs, but does not save.

As soon as I create a different graphics object..it blows up.

Makes no sense to me.....

 

Thanks for trying

Posted

The object refence error was my bad...had a stray on my OK button.

However the following still shows no image and saves the original:

 

Private Sub FrmImgModify_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

'Dim curImage As Image = Image.FromFile(GetFileName(Active_Ctl))

'e.Graphics.DrawImage(curImage, 10, 10, 200, 200)

Dim ArrayPts As Single()() = {New Single() {1, 0, 0, 0, 0}, New Single() {0, 1, 0, 0, 0}, New Single() {0, 0, 1, 0, 0}, New Single() {0, 0, 0, tpVal, 0}, New Single() {0, 0, 0, 0, 1}}

Dim colorMat As New ColorMatrix(ArrayPts)

Dim Attrib As New ImageAttributes()

Attrib.SetColorMatrix(colorMat, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)

Dim ModImg As Image = Image.FromFile(GetFileName(Active_Ctl))

Dim bmp As New Bitmap(ModImg)

Dim g As Graphics = Graphics.FromImage(bmp)

g.DrawImage(bmp, New Rectangle(265, 10, 200, 200), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, Attrib)

bmp.Save("c:\blah.bmp")

End Sub

 

Thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...