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
177 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

735 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