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
175 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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