473,804 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(cFileNam e)
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.Sa ve(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(cFil eName, 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.Sa ve(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 8642
saveBmp = new bitmap (width,height, PixelFormat.For mat24bppRgb)

OR

Dim fs As New System.IO.FileS tream("c:\key30 .bmp", IO.FileMode.Ope n)
Dim bm As New Bitmap(fs)

fs.Close()

Dim g As Graphics = Graphics.FromIm age(bm)
g.FillEllipse(B rushes.Red, 10, 10, 100, 100)

g.Dispose()

bm.Save("C:\key 30.bmp", Imaging.ImageFo rmat.Bmp)

OR

"CSH" <cs*@csh4uNOSPA M.nl> wrote in message
news:P6******** ************@ze elandnet.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(cFileNam e)
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.Sa ve(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(cFil eName, 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.Sa ve(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
"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> schreef in bericht

Dim fs As New System.IO.FileS tream("c:\key30 .bmp", IO.FileMode.Ope n)
Dim bm As New Bitmap(fs)

fs.Close()

Dim g As Graphics = Graphics.FromIm age(bm)
g.FillEllipse(B rushes.Red, 10, 10, 100, 100)

g.Dispose()

bm.Save("C:\key 30.bmp", Imaging.ImageFo rmat.Bmp)


Thanks scorpion, this did it for me. But leave out this line:
g.FillEllipse(B rushes.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*@csh4uNOSPA M.nl> wrote in message
news:Yo******** ************@ze elandnet.nl:
"scorpion53 061" <ad***@nospamhe rekjmsolutions. com> schreef in bericht

Dim fs As New System.IO.FileS tream("c:\key30 .bmp", IO.FileMode.Ope n)
Dim bm As New Bitmap(fs)

fs.Close()

Dim g As Graphics = Graphics.FromIm age(bm)
g.FillEllipse(B rushes.Red, 10, 10, 100, 100)

g.Dispose()

bm.Save("C:\key 30.bmp", Imaging.ImageFo rmat.Bmp)


Thanks scorpion, this did it for me. But leave out this line:
g.FillEllipse(B rushes.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
556
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
7177
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 multiply the width and the height by 24 or just the width?. I tried to multiply the width by 24 but the value is too large?.....what can i do?. The 1bpp data is at resolution 600dpi.....can i just use the set resolution function to change it to 96dpi...
3
17398
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), it doesn't bother bringing the alpha along with it. All of the pixels just show "255" as their alpha value and Bitmap.IsAlphaPixelFormat() returns false. I know that the alpha does exist physically and has worked with this exact image in other...
0
3611
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 into byte from a stream. Exception (System.ArgumentException: Invalid parameter used) occurs when reading from byte over a memory-stream back to the Bitmap object. Please help, I'm really stuck here! Here's the code I use (Sorry for a long...
3
2311
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
2230
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 bitmap.save() to a file instead of a stream it works just fine. Dim bm As Bitmap = System.Drawing.Image.FromStream(fs) Dim newHeight As Integer = 40 Dim newWidth As Integer = (newHeight / bm.Height) * bm.Width
0
305
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
6199
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 process. I narrowed it down to the conversion to IPictureDisp by first loading and saving the icon as a bitmap with no problems; and then repeating the process but adding the step of converting to an IPictureDisp as well. The first operation...
1
5603
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 working fine. My aim is to double click the picture box and the desired image will be drawn at the mouse position. This works fine unless I scroll or minimise the form because the image isnt repainted after movement. I looked up drawing the image to...
0
10343
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7633
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
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
3
3001
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.