473,581 Members | 2,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trying to save image after modification

Joe
does anyone know why this source code throws an error??
Dim myBitmap As System.Drawing. Bitmap
Dim myGraphics As Graphics
myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
myGraphics = PictureBox1.Cre ateGraphics
Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
myGraphics.Draw Image(myBitmap, destRectangle1, expansionRectan gle,
GraphicsUnit.Pi xel)
PictureBox1.Ima ge.Save("c:\xx. tif")
myGraphics.Disp ose()
myBitmap.Dispos e()
myBitmap = Nothing
myGraphics = Nothing

Jul 8 '07 #1
13 2284
On Sun, 08 Jul 2007 00:29:12 -0700, Joe <jo*****@tlen.p lwrote:
>does anyone know why this source code throws an error??
Dim myBitmap As System.Drawing. Bitmap
Dim myGraphics As Graphics
myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
myGraphics = PictureBox1.Cre ateGraphics
Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
myGraphics.Dra wImage(myBitmap , destRectangle1, expansionRectan gle,
GraphicsUnit.P ixel)
PictureBox1.Im age.Save("c:\xx .tif")
myGraphics.Dis pose()
myBitmap.Dispo se()
myBitmap = Nothing
myGraphics = Nothing
What error does it throw??

--
http://bytes.thinkersroom.com
Jul 8 '07 #2
Joe wrote:
does anyone know why this source code throws an error??
Dim myBitmap As System.Drawing. Bitmap
Dim myGraphics As Graphics
myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
myGraphics = PictureBox1.Cre ateGraphics
That doesn't get a graphics object for the image in the picture box, it
gets a graphics object for the screen. There is no specific
CreateGraphics method for the picture box control, you are using the
method inherited from the Control class.
Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
myGraphics.Draw Image(myBitmap, destRectangle1, expansionRectan gle,
GraphicsUnit.Pi xel)
PictureBox1.Ima ge.Save("c:\xx. tif")
Have you even put an image in the picture box? There is no code for it here.
myGraphics.Disp ose()
myBitmap.Dispos e()
myBitmap = Nothing
myGraphics = Nothing
--
Göran Andersson
_____
http://www.guffa.com
Jul 8 '07 #3
Joe
On Jul 8, 8:13 am, Göran Andersson <g...@guffa.com wrote:
Joe wrote:
does anyone know why this source code throws an error??
Dim myBitmap As System.Drawing. Bitmap
Dim myGraphics As Graphics
myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
myGraphics = PictureBox1.Cre ateGraphics

That doesn't get a graphics object for the image in the picture box, it
gets a graphics object for the screen. There is no specific
CreateGraphics method for the picture box control, you are using the
method inherited from the Control class.
Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
myGraphics.Draw Image(myBitmap, destRectangle1, expansionRectan gle,
GraphicsUnit.Pi xel)
PictureBox1.Ima ge.Save("c:\xx. tif")

Have you even put an image in the picture box? There is no code for it here.
myGraphics.Disp ose()
myBitmap.Dispos e()
myBitmap = Nothing
myGraphics = Nothing

--
Göran Andersson
_____http://www.guffa.com
yes, the picture is displayed.
ok, maybe I am little confused; I am just trying to load TIF file
(whatever object it may be in), select some rectangle area and copy it
and save it into separate TIFF file.
how hord is it to do?
thanks for your help.

Jul 8 '07 #4
Joe wrote:
On Jul 8, 8:13 am, Göran Andersson <g...@guffa.com wrote:
>Joe wrote:
>>does anyone know why this source code throws an error??
Dim myBitmap As System.Drawing. Bitmap
Dim myGraphics As Graphics
myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
myGraphics = PictureBox1.Cre ateGraphics
That doesn't get a graphics object for the image in the picture box, it
gets a graphics object for the screen. There is no specific
CreateGraphi cs method for the picture box control, you are using the
method inherited from the Control class.
>>Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
myGraphics.Dr awImage(myBitma p, destRectangle1, expansionRectan gle,
GraphicsUnit. Pixel)
PictureBox1.I mage.Save("c:\x x.tif")
Have you even put an image in the picture box? There is no code for it here.
>>myGraphics.Di spose()
myBitmap.Disp ose()
myBitmap = Nothing
myGraphics = Nothing
--
Göran Andersson
_____http://www.guffa.com

yes, the picture is displayed.
Yes, of course it's displayed. You are drawing it on the screen where
the picture box happens to be. It doesn't change anything about the
picture box, though.
ok, maybe I am little confused; I am just trying to load TIF file
(whatever object it may be in), select some rectangle area and copy it
and save it into separate TIFF file.
how hord is it to do?
Just create another Bitmap object, create a Graphics object for it and
use that to draw on the image. Then you can save it.

--
Göran Andersson
_____
http://www.guffa.com
Jul 8 '07 #5
Joe
On Jul 8, 1:40 pm, Göran Andersson <g...@guffa.com wrote:
Joe wrote:
On Jul 8, 8:13 am, Göran Andersson <g...@guffa.com wrote:
Joe wrote:
does anyone know why this source code throws an error??
Dim myBitmap As System.Drawing. Bitmap
Dim myGraphics As Graphics
myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
myGraphics = PictureBox1.Cre ateGraphics
That doesn't get a graphics object for the image in the picture box, it
gets a graphics object for the screen. There is no specific
CreateGraphics method for the picture box control, you are using the
method inherited from the Control class.
>Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
myGraphics.Dra wImage(myBitmap , destRectangle1, expansionRectan gle,
GraphicsUnit.P ixel)
PictureBox1.Im age.Save("c:\xx .tif")
Have you even put an image in the picture box? There is no code for ithere.
>myGraphics.Dis pose()
myBitmap.Dispo se()
myBitmap = Nothing
myGraphics = Nothing
--
Göran Andersson
_____http://www.guffa.com
yes, the picture is displayed.

Yes, of course it's displayed. You are drawing it on the screen where
the picture box happens to be. It doesn't change anything about the
picture box, though.
ok, maybe I am little confused; I am just trying to load TIF file
(whatever object it may be in), select some rectangle area and copy it
and save it into separate TIFF file.
how hord is it to do?

Just create another Bitmap object, create a Graphics object for it and
use that to draw on the image. Then you can save it.

--
Göran Andersson
_____http://www.guffa.com- Hide quoted text -

- Show quoted text -
thanks Goran, but how can I select rectangle from the first Bitmap
object, copy it content and paste it to the second bitmap box?

any ideas?

Jul 8 '07 #6
Joe wrote:
>>yes, the picture is displayed.
Yes, of course it's displayed. You are drawing it on the screen where
the picture box happens to be. It doesn't change anything about the
picture box, though.
>>ok, maybe I am little confused; I am just trying to load TIF file
(whatever object it may be in), select some rectangle area and copy it
and save it into separate TIFF file.
how hord is it to do?
Just create another Bitmap object, create a Graphics object for it and
use that to draw on the image. Then you can save it.

--
Göran Andersson
_____http://www.guffa.com- Hide quoted text -

- Show quoted text -

thanks Goran, but how can I select rectangle from the first Bitmap
object, copy it content and paste it to the second bitmap box?

any ideas?
Do as you did in the original code. Just forget about the picture box
and use a Bitmap object.

--
Göran Andersson
_____
http://www.guffa.com
Jul 8 '07 #7
Joe
On Jul 8, 4:10 pm, Göran Andersson <g...@guffa.com wrote:
Joe wrote:
>yes, the picture is displayed.
Yes, of course it's displayed. You are drawing it on the screen where
the picture box happens to be. It doesn't change anything about the
picture box, though.
>ok, maybe I am little confused; I am just trying to load TIF file
(whatever object it may be in), select some rectangle area and copy it
and save it into separate TIFF file.
how hord is it to do?
Just create another Bitmap object, create a Graphics object for it and
use that to draw on the image. Then you can save it.
--
Göran Andersson
_____http://www.guffa.com-Hide quoted text -
- Show quoted text -
thanks Goran, but how can I select rectangle from the first Bitmap
object, copy it content and paste it to the second bitmap box?
any ideas?

Do as you did in the original code. Just forget about the picture box
and use a Bitmap object.

--
Göran Andersson
_____http://www.guffa.com- Hide quoted text -

- Show quoted text -

I tried; it gives "unknown error":

' open test and cut a slice
Dim myBitmap As New Bitmap("C:\TEST .TIF")
Dim expansionRectan gle As New Rectangle(135, 10,
myBitmap.Width, myBitmap.Height )

Dim myGraphics As Graphics
Dim image As Image
Dim point As Point

myGraphics.Draw Image(myBitmap, expansionRectan gle)
myGraphics.Save ()
myGraphics.Disp ose()

' create another bitmap
Dim bitmap As Bitmap
bitmap = New Bitmap(100, 100)
Dim g As Graphics
' copy slice from 1. to 2.
g = Graphics.FromIm age(bitmap)
g.DrawImage(myB itmap, expansionRectan gle)
g.Dispose()
' save to disk as 111.tif
bitmap.Save("c: \111.tif")

Jul 8 '07 #8
Joe wrote:
>Do as you did in the original code. Just forget about the picture box
and use a Bitmap object.

--
Göran Andersson
_____http://www.guffa.com

I tried; it gives "unknown error":
The complete error message would be helpful. That would tell where the
error message is coming from and where it occured.
' open test and cut a slice
Dim myBitmap As New Bitmap("C:\TEST .TIF")
Dim expansionRectan gle As New Rectangle(135, 10,
myBitmap.Width, myBitmap.Height )
So far so good.
Dim myGraphics As Graphics
Dim image As Image
Dim point As Point

myGraphics.Draw Image(myBitmap, expansionRectan gle)
myGraphics.Save ()
myGraphics.Disp ose()
What's this code doing here? You haven't created any Image object or any
Graphics object, so you are just working with null references.
' create another bitmap
Dim bitmap As Bitmap
bitmap = New Bitmap(100, 100)
Dim g As Graphics
' copy slice from 1. to 2.
g = Graphics.FromIm age(bitmap)
g.DrawImage(myB itmap, expansionRectan gle)
g.Dispose()
' save to disk as 111.tif
bitmap.Save("c: \111.tif")
That looks ok. Just remove that code in the middle, and it should work
just fine.

Don't forget to dispose the bitmaps.

--
Göran Andersson
_____
http://www.guffa.com
Jul 8 '07 #9
Joe
On Jul 8, 7:30 pm, Göran Andersson <g...@guffa.com wrote:
That looks ok. Just remove that code in the middle, and it should work
just fine.

Don't forget to dispose the bitmaps.
here's the code:

Dim myBitmap As New Bitmap("C:\TEST .TIF")
Dim expansionRectan gle As New Rectangle(135, 10,
myBitmap.Width, myBitmap.Height )

Dim bitmap As Bitmap
bitmap = New Bitmap(100, 100)
Dim g As Graphics

g = Graphics.FromIm age(bitmap)
g.DrawImage(myB itmap, expansionRectan gle)
g.Dispose()

bitmap.Dispose( )

bitmap.Save("c: \111.tif",
System.Drawing. Imaging.ImageFo rmat.Tiff)
and error comes from the last line: bitmap.Save("c: \111.tif") ; it is
"Paremeter is not Valid."
any ideas?? (I've tried with Jpeg file; it is not a tiff/jpeg bitmap
format problem)
Jul 9 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
626
by: F. Hall | last post by:
If I read a bitmap image from one file and save it to another the save operation is slow unless I draw on the image. In other words, Image inputImage = Image.FromFile( @"c:\temp\source.bmp" ); using ( Graphics g = Graphics.FromImage( inputImage ) ) { g.DrawLine( new Pen(Brushes.White), 0, 0, 1, 1 ); } inputImage.Save( @"c:\temp\sink.bmp",...
5
4008
by: George | last post by:
This program need to draw the some triangles into a 512 × 512 buffer (in memory). Or save it to a file. #include "project3.h" Image::Image(int xres, int yres): xres(xres), yres(yres) { image =new Color*; for (int i=0;i<yres;i++)
0
4125
by: prakash | last post by:
Dear Friends I am new guy to Visual C++.NET I've program to save website as a image vc++.net . It have a function "SaveSnapshot" to save the webpage as an image On that function ifor saving as a image it uses image.Save method() This image.Save function have two overloaded form's first one is file name
12
3082
by: Ron Weldy | last post by:
I have a test server runinng 2003/IIS 6 with a mixture of asp and asp.net files. On my workstation I have a share set up to the folder where the web files reside. I am just doing quick and dirty asp editing (like I used to be able to do with 2K/IIS5) where I use VS.NET, open an asp file, make changes, save and refresh my browser. Problem...
25
4046
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
1
6788
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image file during specific events in the script execution? image format doesnt matter. thanks! christine
0
1128
by: jleiva | last post by:
Hi Everyone, I created a word template, now I want to add a macro or vb programming that will do the following. After a user create a new document from a template (not Normal.dot), the user should be allow to save the new document in a folder of his choice. Once the document has been saved, The Save As should be disable so the user can make...
4
5536
by: =?Utf-8?B?ZG1idXNv?= | last post by:
I have an Access database with a table named 'tblMedia'. In tblMedia I have a field named 'Media' that is defined as an 'OLE Ojbect' field. In this Media field, I have pictures, they are jpegs. I'm using VB.NET 2005 and I would like to open the Access database and write the OLE Objects to the file system. Here's what I got and it's not...
0
1494
by: yomkippur18 | last post by:
Is it possible to disable "Save as " in a picture editor using Vbscript? We want to disable the "save as" command to avoid modification of image.
0
7882
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7808
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8312
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6564
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5683
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1145
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.