Hod do you make a Bitmap bigger

  • Thread starter Thread starter active
  • Start date Start date
A

active

How can I increase the size of a bitmap while preserving the image in it.

I tried (among many other things) :

b1 = New Drawing.Bitmap(b1, picData.Width, picData.Height)

and it doesn't seem to work.

I've searched the net and can find nobody that does it.

Is this a difficult thing to do? I can't seem to find the combination that
works.





Thanks for any help,

Cal
 
Hi Cal,

I'd recommend 3 products: microangelo, icon forge and icon gragger.

HTH,

Bernie Yaeger
 
Thanks but I'm talking VB.NET
cal

PS At least for a minute I thought someone had told me how - thanks for that
happy period.
 
* " active said:
How can I increase the size of a bitmap while preserving the image in it.

I tried (among many other things) :

b1 = New Drawing.Bitmap(b1, picData.Width, picData.Height)

and it doesn't seem to work.

I've searched the net and can find nobody that does it.

Is this a difficult thing to do? I can't seem to find the combination that
works.

Create a new bitmap object with the bigger size, then draw the old image
onto it. Sample for painting an image on another:

\\\
Dim b As New Bitmap(200, 200, ...)
Dim g As Graphics = Graphics.FromImage(b)
g.DrawImage(...)
g.DrawImage(...)
g.DrawImage(...)
g.DrawImage(...)
g.Dispose()
b.Save(...)
b.Dispose()
///
 
I have a bitmap, b1, that I need to enlarge while retaining the contents.
I tried to adapt your input but could not make it work.
I cut and paste to present what I have. picData is a PictureBox
I've tried creating b with the b1 in the constructor
I've tried cloning b1
I've tried everything I can think of

Private b1 As Drawing.Bitmap
Private g1 As Graphics

-snip Things like the following:
g1.DrawString( -snip Can not redo these statements to recreate bitmap

-snip Need to resize the bitmap since picData has resized - Does not work
Private Sub picData_Resize(ByVal se -snip
Dim b = New Drawing.Bitmap(picData.Width, picData.Height)
Dim g As Graphics = Graphics.FromImage(b)
g.DrawImage(b1, 0, 0)
b1 = b
g1 = Graphics.FromImage(b1)
picData.Invalidate()

Private Sub picData_Paint( -snip
e.Graphics.DrawImage(b1, 0, 0)
End Sub
 
Hi active,

You can have a look for this to the drawing encoder class
Before you do it you have to no the codec of the picture or use a codec.

Most samples are in C#

You also can visit the dotnet drawing newsgroup for this.

I hope this helps?

Cor
 
'Load the original bitmap.

dim bm as bitmap=Bitmap.FromFile("filename....")

'create a bigger one

dim bigbm as new Bitmap(bm.Width*2, bm.Height*2)

'get a graphics for the copy so you can draw on it.

dim g as Graphics=Graphics.FromImage(bigbm)

'draw the original to the graphics.

g.DrawImage(bm,new Rectangle(0,0,bigbm.Width,
bigbm.Height),0,0,bm.Width,bm.Height,GraphicsUnit.Pixel)

'dispose of the graphics.

g.Dispose()

'and the original

bm.Dispose() 'this closes the file.

'now save the bigger image...

bigbm.Save("filename...",ImageFormat.Bmp)


--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com
 
I ralize now that some of my problem was that the form containing the
Usercontrol that contained the PictureBox had a reference to the graphics
object I needed to update when I changed bitmaps.

I'll try both of your suggestions. I assume I'll be able to find the info about
the codec class in Help or MSDN since I don't understand what "Before you do it
you have to no the codec of the picture or use a codec." means.

Thanks for the info
Cal
 
The bitmap I have is the one I use to Paint the PictureBox (picData) with.
I get it like this:

Dim g As Graphics = picData.CreateGraphics

b1 = New Drawing.Bitmap(picData.Width, picData.Height, g)

g.Dispose()

g1 = Graphics.FromImage(b1)


I need to leave the resize routine with b1 and g1 set to the new values.
I think that's what I'm having trouble doing because I can't draw after.

Thanks for the input
(especially if you revise it to fit the above, which I havn't had much luck
doing),
Cal
 
Back
Top