473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Bitmap problems in VB.net

CSH
Hi all,

I've run into a small problem opening and saving bitmaps. Concider the
following code:

Dim oBM as Bitmap
Dim cFileName as String

... some code to get the filename etc...

oBM = New Bitmap(cFileName)
oPanel.image = oBM ' <- oPanel is a panel object on my form.

This works like I expect it to, but with a twist. When I try to save the
bitmap again like such:

oPanel.image.Save(cFileName)

It generated a runtime error since the file is still open/in use. The file
stays in use even after disposing of the object holding the bitmap. I have
to close my application to release the file. Saving to a different filename
does work btw, but that's not what I need at the moment.

Now I've tried it another way using a filestream:
Dim oBM as Bitmap
Dim cFileName as String
Dim s as FileStream

... some code to get the filename etc...

s = New FileStream(cFileName, FileMode.Open)
oBM = New Bitmap(s)
s.Close()
oPanel.image = oBM

After this my panel correctly shows the image and the file isn't in use
anymore (hurray). But when I try to save the bitmap to a file now I get a
"generic GDI+ error" not matter if I save to a (different) filename or try
it using a stream.

oPanel.image.Save(cFileName) '<-- this is where it crashes.

Any ideas on what I'm doing wrong here? Getting the image via the filestream
is working for me in the way that the file is not locked afterwards. But I
need to save that image again.

Rinze van Huizen


Nov 21 '05 #1
3 8598
saveBmp = new bitmap (width,height, PixelFormat.Format24bppRgb)

OR

Dim fs As New System.IO.FileStream("c:\key30.bmp", IO.FileMode.Open)
Dim bm As New Bitmap(fs)

fs.Close()

Dim g As Graphics = Graphics.FromImage(bm)
g.FillEllipse(Brushes.Red, 10, 10, 100, 100)

g.Dispose()

bm.Save("C:\key30.bmp", Imaging.ImageFormat.Bmp)

OR

"CSH" <cs*@csh4uNOSPAM.nl> wrote in message
news:P6********************@zeelandnet.nl:
Hi all,

I've run into a small problem opening and saving bitmaps. Concider the
following code:

Dim oBM as Bitmap
Dim cFileName as String

.. some code to get the filename etc...

oBM = New Bitmap(cFileName)
oPanel.image = oBM ' <- oPanel is a panel object on my form.

This works like I expect it to, but with a twist. When I try to save the
bitmap again like such:

oPanel.image.Save(cFileName)

It generated a runtime error since the file is still open/in use. The
file
stays in use even after disposing of the object holding the bitmap. I
have
to close my application to release the file. Saving to a different
filename
does work btw, but that's not what I need at the moment.

Now I've tried it another way using a filestream:
Dim oBM as Bitmap
Dim cFileName as String
Dim s as FileStream

.. some code to get the filename etc...

s = New FileStream(cFileName, FileMode.Open)
oBM = New Bitmap(s)
s.Close()
oPanel.image = oBM

After this my panel correctly shows the image and the file isn't in use
anymore (hurray). But when I try to save the bitmap to a file now I get
a
"generic GDI+ error" not matter if I save to a (different) filename or
try
it using a stream.

oPanel.image.Save(cFileName) '<-- this is where it crashes.

Any ideas on what I'm doing wrong here? Getting the image via the
filestream
is working for me in the way that the file is not locked afterwards. But
I
need to save that image again.

Rinze van Huizen


Nov 21 '05 #2
csh
"scorpion53061" <ad***@nospamherekjmsolutions.com> schreef in bericht

Dim fs As New System.IO.FileStream("c:\key30.bmp", IO.FileMode.Open)
Dim bm As New Bitmap(fs)

fs.Close()

Dim g As Graphics = Graphics.FromImage(bm)
g.FillEllipse(Brushes.Red, 10, 10, 100, 100)

g.Dispose()

bm.Save("C:\key30.bmp", Imaging.ImageFormat.Bmp)


Thanks scorpion, this did it for me. But leave out this line:
g.FillEllipse(Brushes.Red, 10, 10, 100, 100)
and it bombs with the generic GDI error.
So now I've just drawn an elipse with an immense radius. Which turns out
doesn't draw anything, but it somehow does the trick and lets me save the
image again.

That leaves me to wonder why I need to draw the elipse in order to be able
to save it again? My immideate problem is now solved, but this still leaves
me a bit confused.

Rinze van Huizen
Nov 21 '05 #3
I am glad your immediate problem is solved.

"csh" <cs*@csh4uNOSPAM.nl> wrote in message
news:Yo********************@zeelandnet.nl:
"scorpion53061" <ad***@nospamherekjmsolutions.com> schreef in bericht

Dim fs As New System.IO.FileStream("c:\key30.bmp", IO.FileMode.Open)
Dim bm As New Bitmap(fs)

fs.Close()

Dim g As Graphics = Graphics.FromImage(bm)
g.FillEllipse(Brushes.Red, 10, 10, 100, 100)

g.Dispose()

bm.Save("C:\key30.bmp", Imaging.ImageFormat.Bmp)


Thanks scorpion, this did it for me. But leave out this line:
g.FillEllipse(Brushes.Red, 10, 10, 100, 100)
and it bombs with the generic GDI error.
So now I've just drawn an elipse with an immense radius. Which turns out
doesn't draw anything, but it somehow does the trick and lets me save
the
image again.

That leaves me to wonder why I need to draw the elipse in order to be
able
to save it again? My immideate problem is now solved, but this still
leaves
me a bit confused.

Rinze van Huizen


Nov 21 '05 #4

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

Similar topics

7
by: Prashant | last post by:
Hi, I have a huge problem. I have a data file which looks something like this -: ..1 .5 .9 -1 .2 .5 ...... ..2 .9 .1 .4 .3 -1 ...... ..2 .4 .5 .7 .6 .2 ...... ........
8
by: James Dean | last post by:
I have 1 bit per pixel information and i have the width and height of this data.Each bit corresponds to a 24 bit colour value. I want to convert this to 24bit per pixel bitmap. Do i need to...
3
by: instruo | last post by:
I'm using the System.Drawing.Bitmap class for loading a 32-bit bmp file which includes an alpha channel. The problem is, when it gets loaded (just using the Bitmap(string filename) constructor),...
0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
3
by: Mats Boberg | last post by:
Hi, I have problems with saving a bitmap to hdd from my asp.net page I get the following error: "A generic error occurred in GDI+." Code: Bitmap bmp = new Bitmap(240,120);
2
by: creepwood | last post by:
I'm trying to load and image into a DB and alongside the image also a thumbnailed version of the image, but somewhere in my code, the stream doesn't take the thumbnail data. When I just change toe...
0
by: CSH | last post by:
Hi all, I've run into a small problem opening and saving bitmaps. Concider the following code: Dim oBM as Bitmap Dim cFileName as String ... some code to get the filename etc...
2
by: Map Reader | last post by:
Greetings, I am converting an old VB6 application to use .NET. One of the old controls loads icons from the disk and displays them. However, the transparent color turns to blue somewhere in the...
1
by: martinsmith160 | last post by:
Hi all I am trying to create a level builder tool for a final year project and im having some problems drawing. I have placed a picture box within a panel so i can scroll around the image which is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.