Bitmap Class

J

Jarod_24

Can the Bitmap Class take all types of images (.bmp, jpg, jpeg, gif, eps
ect...) and resize them or does i just work with bmp images (and hence the
name)?

What image types does the Bitmap class support?
The description below (msdn) dosen't tell my that much.

"Encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics
image and its attributes. A Bitmap object is an object used to work with
images defined by pixel data."
 
H

Herfried K. Wagner [MVP]

* "Jarod_24 said:
Can the Bitmap Class take all types of images (.bmp, jpg, jpeg, gif, eps
ect...) and resize them or does i just work with bmp images (and hence the
name)?

It will work with some file formats, at least BMP, JPEG, GIF, and PNG.
 
J

Jarod_24

Herfried K. Wagner said:
It will work with some file formats, at least BMP, JPEG, GIF, and PNG.


I tried resizing some .jpg images and when i used the "Windows Picture and
Fax Viewer" they showed up like normal.
But when i tried to use Paint Shop Pro it said that the image wasn't a valid
JPEG image.

I then opened the original image and the resized image in Notepad, and saw
that the resized image had the text "PNG" on the first line (m3 l33t
haxx0R).
I then gave the resized image the .png ending and then it opened up without
a hitch in Paint Shop Pro.

I tried resizing a .gif and .bmp and they ended up beign saved as png-format
too.
My idea from the beginning was to resize the images but not change the fomat
they were saved in, so is there anything i can do in the code to prevent it
from doing this?
 
J

Jarod_24

Jarod_24 said:
I tried resizing some .jpg images and when i used the "Windows Picture and
Fax Viewer" they showed up like normal.
But when i tried to use Paint Shop Pro it said that the image wasn't a valid
JPEG image.

I then opened the original image and the resized image in Notepad, and saw
that the resized image had the text "PNG" on the first line (m3 l33t
haxx0R).
I then gave the resized image the .png ending and then it opened up without
a hitch in Paint Shop Pro.

I tried resizing a .gif and .bmp and they ended up beign saved as png-format
too.
My idea from the beginning was to resize the images but not change the fomat
they were saved in, so is there anything i can do in the code to prevent it
from doing this?

Here's the code i use for resizing (Herfried gave it to me)

Dim imgOrg As New Bitmap(strSource) 'originalbildet
Dim imgNew As New Bitmap(W, H) 'Imaging.PixelFormat.Format24bppRgb) 'dunno
what this commented part does

Dim g As Graphics = Graphics.FromImage(imgNew)
'g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic'and
what does this do?
g.DrawImage(imgOrg, 0, 0, imgNew.Width, imgNew.Height) 'resize

g.Dispose()
imgNew.Save(strTarget)
 
H

Herfried K. Wagner [MVP]

* "Jarod_24 said:
I tried resizing some .jpg images and when i used the "Windows Picture and
Fax Viewer" they showed up like normal.
But when i tried to use Paint Shop Pro it said that the image wasn't a valid
JPEG image.

I then opened the original image and the resized image in Notepad, and saw
that the resized image had the text "PNG" on the first line (m3 l33t
haxx0R).
I then gave the resized image the .png ending and then it opened up without
a hitch in Paint Shop Pro.

Post code! Are you sure you specified the 'ImageFormat' when calling
the bitmap's 'Save' method?
 
J

Jarod_24

Herfried K. Wagner said:
Post code! Are you sure you specified the 'ImageFormat' when calling
the bitmap's 'Save' method?

I figured out myself.
I needed to say that the format i was saving in were supposed to be the same
as the one i read in.

imgNew.Save(sTarget, imgOrg.RawFormat)

(see my reply post to myself for the rest of the code)
 
J

Jarod_24

Jarod_24 said:
Here's the code i use for resizing (Herfried gave it to me)

Dim imgOrg As New Bitmap(strSource) 'originalbildet
Dim imgNew As New Bitmap(W, H) 'Imaging.PixelFormat.Format24bppRgb) 'dunno
what this commented part does

Dim g As Graphics = Graphics.FromImage(imgNew)
'g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic'and
what does this do?
g.DrawImage(imgOrg, 0, 0, imgNew.Width, imgNew.Height) 'resize

g.Dispose()
imgNew.Save(strTarget)

Hehe, the answer the my problem was to use another Save method that allowed
you to specify what format to save the image in

imgNew.Save(sTarget, imgOrg.RawFormat)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top