Solved

Dear Idle mind the new partial piece of the original file is bigger than the original larger picture

Posted on 2009-05-14
12
176 Views
Last Modified: 2012-05-07
how do I make the file size of the piece of the orignal samller I am doing bmp.sav("file.gif")
but the resulting piece is bigger than the original
0
Comment
Question by:Dov_B
  • 7
  • 5
12 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24389906
That's because the default FORMAT for Save() is a Bitmap.  So...what you actually did was save a Bitmap with a ".gif" extension.  ;)

You would need to tell the desired format using the second parameter to Save():

    bmp.Save("file.gif", System.Drawing.Imaging.ImageFormat.Gif)
0
 

Author Comment

by:Dov_B
ID: 24389970
sorry to keep bothering you but...
I just tried that and ended up with a blackbox not the picture I copied
I will upload the picture file

abacus.gif
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24390165
It's working perfectly for me...  =\

            ' ...do something with bmp...
            Dim FileName As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "abacus2.gif")
            bmp.Save(FileName, System.Drawing.Imaging.ImageFormat.Gif)

Are you writing to a new file?...or overwriting an existing one?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Dov_B
ID: 24390438
sorry but I just I copied the above code and wound up with a black box
I am writing to a new file
0
 

Author Comment

by:Dov_B
ID: 24390483
its this part of the code which is messing it up
System.Drawing.Imaging.ImageFormat.Gif
I am using vb.net 2008 express perhaps that is the problem?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24390557
It works for me in Express too...

Can you show me your FULL code as it is now?
0
 

Author Comment

by:Dov_B
ID: 24390945

here goes after my mother you are the most patient person I know
Private RC As Rectangle
    Private screenPtA, screenPtB As Point
 
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Dim pb As PictureBox = CType(sender, PictureBox)
            Cursor.Clip = pb.RectangleToScreen(pb.ClientRectangle)
            screenPtA = Cursor.Position
            screenPtB = screenPtA
            RC = NormalizedRC(screenPtA, screenPtB)
            ControlPaint.DrawReversibleFrame(RC, Color.Black, FrameStyle.Dashed)
        End If
    End Sub
 
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ControlPaint.DrawReversibleFrame(RC, Color.Black, FrameStyle.Dashed)
            screenPtB = Cursor.Position
            RC = NormalizedRC(screenPtA, screenPtB)
            ControlPaint.DrawReversibleFrame(RC, Color.Black, FrameStyle.Dashed)
        End If
    End Sub
 
    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Cursor.Clip = Nothing
            Dim pb As PictureBox = CType(sender, PictureBox)
            RC = pb.RectangleToClient(RC)
 
            Dim bmp As New Bitmap(RC.Width, RC.Height)
            Dim g As Graphics = Graphics.FromImage(bmp)
            g.DrawImage(PictureBox1.Image, 0, 0, RC, GraphicsUnit.Pixel)
            g.Dispose()
            Dim FileName As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "abacus782.bmp")
            bmp.Save(FileName, System.Drawing.Imaging.ImageFormat.Bmp)
            ' ...do something with bmp...
            PictureBox2.Image = bmp
        End If
    End Sub
 
    Public Function NormalizedRC(ByVal ptA As Point, ByVal ptB As Point) As Rectangle
        Return New Rectangle(Math.Min(ptA.X, ptB.X), Math.Min(ptA.Y, ptB.Y), Math.Abs(ptA.X - ptB.X), Math.Abs(ptA.Y - ptB.Y))
    End Function

Open in new window

0
 

Author Comment

by:Dov_B
ID: 24391016
I have tried bmp.Save(FileName, System.Drawing.Imaging.ImageFormat.Bmp)
bmp.Save(FileName, System.Drawing.Imaging.ImageFormat.gif
bmp.Save(FileName, System.Drawing.Imaging.ImageFormat.jpeg
all of them give me a black box
but if I do it without the System.Drawing.Imaging.ImageFormat.whatever
just plain bmp.Save(FileName)
no matter what the extension I get the picture just with a large file size
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24391062
=(

I posted that code into a Form with Two PictureBoxes.  Then I set the Image() Property of PictureBox1 to the "abacus.gif" (the one you uploaded earlier).  I changed the save code to this:

            Dim FileName As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "abacus782.gif")
            bmp.Save(FileName, System.Drawing.Imaging.ImageFormat.Gif)

Everything else remains the same.

Below is a screenshot of the actual rubberband operation so you can see what I selected.  The second image is the actual resulting file from the Save() operation:
RubberbandCrop.jpg
abacus782.gif
0
 

Author Comment

by:Dov_B
ID: 24391621
it suddenly occured to me to try it with a different file and it worked
I dont know why it would not work with the abacus file
0
 

Author Comment

by:Dov_B
ID: 24391654
hmmm I originaly loaded the abacus file into the picture box in form1.design by clicking on the arrow and choosing local resource
then I did it using
PictureBox1.Image = New System.Drawing.Bitmap("C:\Documents and Settings\Dov\My Documents\My Pictures\abacus.gif")
and it still would not work
then I tried the same thing with a different file and it worked
then I tried putting the file in the picturebox the original way through the designer and I just got the following error
A generic error occurred in GDI+.
any Idea what gives?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24391738
My only guess is that the gif file is corrupt somehow?...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question