Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > Graphics/GDI+

Graphics/GDI+ Graphics discussion for VB.NET applications, Winforms, Web, Compact Framework, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2009, 9:53 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Jun 2007
Posts: 7
Reputation: 0
scdevils2 is on a distinguished programming path ahead
Default Are Cloned Images Disjoint From original Image?

If I set CloneFirst =True, the image is displayed as expected. If i Set CloneFirst =False the image is displayed pixelated. Can someone please explain to me why this is happening.

Code:
    Private Const FILE_PATH As String = "staticmap.jpeg"
    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        Dim imageFile As New IO.FileInfo(FILE_PATH)
        Dim newBitMap As Bitmap = CType(Bitmap.FromStream(imageFile.OpenRead), Bitmap)
        Dim clonedBitMap As Bitmap

        clonedBitMap = getBitMap(newBitMap, ckbCloneFirst.Checked)
        pbImage.Image = clonedBitMap



    End Sub


    Private Function getBitMap(ByVal BottomImage As Bitmap, ByVal CloneFirst As Boolean) As Bitmap

        Dim CopiedBottomImage As Bitmap = DirectCast(BottomImage.Clone(), Bitmap)
        Dim CopiedImageGraphics As Graphics
        Dim otherImage As Bitmap


        If CloneFirst Then
            otherImage = DirectCast(BottomImage.Clone(), Bitmap)
            CopiedImageGraphics = Graphics.FromImage(CopiedBottomImage)
        Else
            CopiedImageGraphics = Graphics.FromImage(CopiedBottomImage)
            otherImage = DirectCast(BottomImage.Clone(), Bitmap)
        End If

        'otherImage.Dispose()
        'BottomImage.Dispose()
        '' secondImage.Dispose()
        'CopiedImageGraphics.Dispose()

        Return CopiedBottomImage
    End Function
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-09-2009, 10:57 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,173
Reputation: 1273
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Quote:
If I set CloneFirst =True, the image is displayed as expected. If i Set CloneFirst =False the image is displayed pixelated.
I don't see how, your getBitMap method returns BottomImage.Clone no matter what CloneFirst parameter is.
Quote:
Are Cloned Images Disjoint From original Image?
Yes.

You have commented out some Dispose calls here, Graphics instances created from FromImage must be disposed when done using them, image/bitmap objects must also be disposed after use. So otherImage.Dispose() and CopiedImageGraphics.Dispose() is needed in getBitMap method. In btnDisplay_Click method you need to dispose the image object held by newBitMap variable, and if pbImage.Image already contains an image you must dispose that before assigning it a new image object. imageFile.OpenRead returns a FileStream object, you have to close/dispose this when done using it also. In general you have to analyse your code to make sure you don't open/create objects and just leave them in memory after last reference is released without disposing/closing them properly.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-09-2009, 11:07 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Jun 2007
Posts: 7
Reputation: 0
scdevils2 is on a distinguished programming path ahead
Default

yes, I know you have to dispose of the image after the use, I was commenting out the code trying to figure out what was going on.

So I tried Saving the Image to demonstrate what I am seeing, however, when i save the image, the image does not display incorrectly any more.

Code:
    Private Function getBitMap(ByVal BottomImage As Bitmap, ByVal CloneFirst As Boolean) As Bitmap

        Dim CopiedBottomImage As Bitmap = DirectCast(BottomImage.Clone(), Bitmap)
        Dim CopiedImageGraphics As Graphics
        Dim otherImage As Bitmap


        If CloneFirst Then
            otherImage = DirectCast(BottomImage.Clone(), Bitmap)
            CopiedImageGraphics = Graphics.FromImage(CopiedBottomImage)
        Else
            CopiedImageGraphics = Graphics.FromImage(CopiedBottomImage)
            otherImage = DirectCast(BottomImage.Clone(), Bitmap)
        End If

        otherImage.Dispose()
        CopiedImageGraphics.Dispose()
        'Fixes the Problem
        CopiedBottomImage.Save(SAVE_IMAGE_PATH)
        Return CopiedBottomImage
    End Function
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-09-2009, 11:15 AM
VB.NET Forum Newbie
.NET Framework: .NET 2.0
 
Join Date: Jun 2007
Posts: 7
Reputation: 0
scdevils2 is on a distinguished programming path ahead
Default

Here is what i am seeing, when I dont have the save code in there
Attached Images
File Type: jpg imageNormal.JPG (69.8 KB, 4 views)
File Type: jpg imagePixelated.JPG (36.8 KB, 4 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 1:10 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.