Results 1 to 10 of 10

Thread: Display Canon .cr2 image file

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    46

    Display Canon .cr2 image file

    Hi , i havent touched VB for a few years i just dip into it to make stuff for whatever work im doing at the time.

    At the moment im making an image file managing app which is simple enough but i need to be able to display Canon Raw files (.cr2) in a picture box. The .cr2 image format is not included as standard in windows but if you download the Microsoft Camera Codec Pack it can be viewed in windows explorer/picture viewer/image gallery etc. So i can easily open a dialog box in VB and see thumbnailed images of .cr2 files but i want to be able to display a preview in my app from a selected file list. It doesnt have to be a full size perfect render of the .cr2 file and i dont need to be able to change any properties of the image like brightnes,color etc. I just need a small preview displayed.

    Can anyone explain how i go about displaying a .cr2 image in a picturebox on a form in VB.net 2015? Im wondering if there is some way of using the Microsoft Camera Codec Pack in my app to do it or would i have to convert it to something the picture box can display. If i have to convert it what would i use?

    Thanks guys.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Display Canon .cr2 image file

    I spent 5 seconds with a search engine and found this, which provides multiple options.

    http://stackoverflow.com/questions/4...2-files-in-net

    I'll never understand why so many people seem to think that asking a question on a forum is something you do before doing a web search.

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    46

    Re: Display Canon .cr2 image file

    Jeez dont have a heart attack fella, I was just asking for advice to the best solution. It was 4am, i was about to crash and i was hoping for a friendly person to point me in the right direction so i could get started coding first thing in the morning, but i got you instead. Thanks for that.

    Even so i managed to work it out myself about an hr later, just took ages for the post to authorized or i would have deleted it.

    I eneded up using Exiftool and fuged this code together. It might be usfull for someone

    First i made a folder on c drive for the exif tool. Apparently you cant just put it in the windows folder because it wont be located correctly.

    Code:
    Private Sub GetImage(ByVal FileName As String, ByRef PicBox As PictureBox)
    
            Dim ExifTool As New Process
    
            ExifTool.StartInfo.FileName = "C:\ExifTool\exiftool.exe" ' static file location so it be located correctly
            ExifTool.StartInfo.Arguments = "-b -previewimage" + " " + Chr(34) + FileName + Chr(34)
            ExifTool.StartInfo.UseShellExecute = False
            ExifTool.StartInfo.RedirectStandardOutput = True
            ExifTool.StartInfo.CreateNoWindow = True
            ExifTool.Start()
    
            Dim newW As Integer = PictureBox1.Width
            Dim newH As Integer = PictureBox1.Height
    
            ResacleImg(newW, newH)
            PicBox.Image = New Bitmap(ExifTool.StandardOutput.BaseStream).GetThumbnailImage(newW, newH, Nothing, Nothing)
    
            ExifTool.Close()
    
        End Sub
    I did write some code to rescale it preserving the aspect ratio but it was late and it was kinda clunky

    I based it on this example though. Im sure someone can code a better function than me with it


    Yes, this is correct – though it unnecessarily uses two divisions instead of one division and a multiplication, adjusted height = <user-chosen width> * original height / original width.

    The corresponding formula for the adjusted width is adjusted width = <user-chosen height> * original width / original height, or if you want to do it your way, adjusted width = <user-chosen height> * aspect ratio, with aspect ratio calculated as before.
    Last edited by LucasCain; Nov 6th, 2016 at 08:54 PM.

  4. #4
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    750

    Re: Display Canon .cr2 image file

    After a few minutes research I am still unsure as to whether the CR2 format includes a jpeg image, as this would probably be the easiest way to get a reasonably sized preview image. Some forums say it does not; others suggest it does. This page may help:

    http://lclevy.free.fr/cr2/

    EDIT: Somehow the OP's response didn't show up here until much later... Glad you got something sorted.
    Last edited by paulg4ije; Nov 5th, 2016 at 10:23 AM.

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    46

    Re: Display Canon .cr2 image file

    Yeah, thanks for the for the reply m8. Its all working good now

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Display Canon .cr2 image file

    Quote Originally Posted by LucasCain View Post
    Jeez dont have a heart attack fella, I was just asking for advice to the best solution.
    Nice. Make out like I'm being hysterical so that you don't have to take any responsibility.

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    46

    Re: Display Canon .cr2 image file

    Its easy to act all superior and make out the answer is easy to find if you know the right things to feed into the search engine to begin with and which one is the best solution.

    I had already spent some time searching for ways to display a .cr2 file in VB.net and was not finding the right solutions. Thats why i asked for help.

    I even went to the effort of posting the solution i worked out for the benefit of anyone else who might be trying to do the same thing.
    Last edited by LucasCain; Nov 9th, 2016 at 11:28 PM.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Display Canon .cr2 image file

    Quote Originally Posted by LucasCain View Post
    Its easy to act all superior and make out the answer is easy to find if you know the right things to feed into the search engine to begin with and which one is the best solution.
    What exactly makes you think that I have any more prior knowledge on this subject than you do? I just used the sort of keywords that should have been obvious to anyone, e.g. "vb.net load cr2 file" or something like that. You can try to avoid responsibility all you like but if I found that information then there's no good reason that you couldn't too.
    Quote Originally Posted by LucasCain View Post
    I had already spent some time searching for ways to display a .cr2 file in VB.net and was not finding the right solutions. Thats why i asked for help.
    I don't see where you explained any of that. If your question is "how do I do X" then why should we assume that you've done anything in particular? If you've already tried to do X a particular way and something unexpected and undesired happened then the best course of action is to explain that you tried to do X in a particular way and what the unexpected and undesired result was. For all you know, all that was required was a simple change but we'd never know if you don't give us all the relevant information.
    Quote Originally Posted by LucasCain View Post
    I even went to the effort of posting the solution i worked out for the benefit of anyone else who might be trying to do the same thing.
    That's good an I commend you for it. You don't need to convince me that you're not a bad person. The fact is that you didn't do what you should have. You can pretend that isn't the case or you can accept it, learn and move on. I've been in that position plenty of times myself and I'm a better developer for it. You can keep telling yourself that I'm a bad guy and I'm picking on you for no reason if you want. It's no skin off my nose either way.

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    46

    Re: Display Canon .cr2 image file

    The simple fact was you assumed i hadnt spent any time looking for an answer just because i hadnt stated that i had. It was 5am uk time when i decided to ask for help.

    I had been looking for the answer with keywords that included visual basic 2015. The solution you pointed me to was for C# and had not showed up in my searches. Not only that in the answer that was marked as the correct one by the OP it stated that he thought the BitmapDecoder didnt understand .CR2 files and he had no examples of the code he used.

    I even gave you a +1 on reputation dispite the uncalled for harsh reply you gave me. You respoded by giving me a -1 on reputation on the first thread ive made in this forum.

    If it wasnt for the fact it took many hrs for my first post to have been approved i would have been able to come back and explain id found an answer before you had replied because in the end i stayed up all night trying to get it right.
    Last edited by LucasCain; Nov 10th, 2016 at 02:16 AM.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Display Canon .cr2 image file

    Let's just end this here. It was starting to move from passive-aggressive to just aggressive. It may have been a bit harsh on both sides.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width