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
174 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Dov_B
Comment Utility
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
Comment Utility
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
Comment Utility
It works for me in Express too...

Can you show me your FULL code as it is now?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Dov_B
Comment Utility

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
Comment Utility
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
Comment Utility
=(

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
Comment Utility
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
Comment Utility
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
Comment Utility
My only guess is that the gif file is corrupt somehow?...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now