Results 1 to 10 of 10

Thread: [RESOLVED] Getting Clipboard Data to an Image File

  1. #1

    Thread Starter
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Resolved [RESOLVED] Getting Clipboard Data to an Image File

    This is kind of a twisted method so please forgive the lack of conciseness:

    I have been using a VBA program in Excel in which one of the stages it captures a range of cells to the clipboard. The VBA program then launches AutoCAD and a LISP program pastes the data from the clipboard to an OLE object in the model space of the drawing. All of this happened on the same computer and it worked well and the resolution of the OLE object in AutoCAD is crisp and clear.

    We have modified this process such that user starts Excel and the VBA code captures the range to a jpg file which is saved on the server. Another computer in the IT room launches AutoCAD and prepares the drawing and in then imports this jpg file. This too works well but the resolution of the graphic is degraded substantially.

    Would there be a way to use VBA or VB.NET to somehow capture this clipboard data to a file and forgo the jpg file creation. We compared the two methods this morning and there is a severe drop-off in resolution which makes the image look not too professional.

    If I had to I could save the Excel file temporarily on the server and then have a VB.NET program probe it to get the range into the clipboard on the IT room computer and repeat the paste process which results in true OLE object which comes into AutoCAD so much crisper and clearer.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Getting Clipboard Data to an Image File

    Is there a reason for choosing .jpg when what you clearly need is an uncompressed format like .bmp?

  3. #3

    Thread Starter
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Re: Getting Clipboard Data to an Image File

    I would agree with you. Here is the code I'm using. I can change jpg to png and that works, but if I change it to bmp I get an Run-time error 1004: Method 'Export' of object_Chart failed.

    Code:
    If SaveName <> False Then
             With wks.Range(MyAddress)
                .CopyPicture Appearance:=xlScreen, Format:=xlBitmap
                Hi = .Height + 4
                Wi = .Width + 4
             End With
             MakeAndSizeChart container, ih:=Hi, iv:=Wi
             With container
                .Paste
                .Export Filename:=LCase(SaveName), FilterName:="bmp"
                .Pictures(1).Delete

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Getting Clipboard Data to an Image File

    I've done a bit of reading up on this and it seems that it doesn't actually matter what the target file type is the copy method basically sends a .gif version to the clipboard, hence the poor quality. Doesn't seem to be any way round it (thank-you Microsoft!)

  5. #5
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Getting Clipboard Data to an Image File

    Looks like you can do it if you copy the picture of the range into an empty chart and then export that.

    http://www.mrexcel.com/forum/showthr...save-as-a-file
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Getting Clipboard Data to an Image File

    Quote Originally Posted by MattP View Post
    Looks like you can do it if you copy the picture of the range into an empty chart and then export that.
    I think that's what he's doing already!

  7. #7
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Getting Clipboard Data to an Image File

    Yeah, not sure how MakeAndSizeChart differs from post #3. The thread I linked to seemed to suggest that exporting to .bmp was successful.
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Getting Clipboard Data to an Image File

    Quote Originally Posted by MattP View Post
    Yeah, not sure how MakeAndSizeChart differs from post #3. The thread I linked to seemed to suggest that exporting to .bmp was successful.
    It should be but it differs from machine to machine apparently (don't ask me why!) But even so, you're getting a gif to bmp conversion not a pure bmp so the quality problem stubbornly remains.

  9. #9

    Thread Starter
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Re: Getting Clipboard Data to an Image File

    Thanks all. And yes, that is the way I'm doing it. I (ahem) plagiarized some code from a site I found and made some slight adjustments to it. I call the subroutine snapshot, although I wanted to call it slapshot. It creates a new workbook on the fly, shoves the image into it and then exports it to a file, then dumps the newly created workbook. All happens in an instant and it's pretty good but the resolution ends up being low. And when I say low I mean it's ok but not compared to the other method I was using which requires the operation in both the VBA program and AutoCAD be on the same machine. I use this VBA code in Excel to capture the screen to the clipboard:

    Code:
    Sheets("SUMMARY").Select
      Range("B1:I97").Copy
    Simple, it puts the range into the clipboard on the local machine and then when AutoCAD opens it runs a LISP program which pastes the clipboard data into the model space of the drawing file. The image we get with this is crisp and very high res. Just wonder if there would be someway to do the same but instead of keeping the high-res data in the clipboard, export it to a file with higher resolution.

  10. #10
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Getting Clipboard Data to an Image File

    Would this be useful (i didn't read it in depth)? http://www.codeproject.com/Articles/...g-NET-Remoting

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