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
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 86

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 86

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 86

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 86

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 86

Expert Comment

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

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 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