Range.CopyPicture question

Gokhan Aycan

Active Member
Joined
Aug 8, 2021
Messages
460
Office Version
  1. 365
Platform
  1. Windows
Is there a limit on how many rows that can be copied or an image size limit? Or some other setting etc I need to check?

When the range is 6000 rows by 20 columns, the resulting image is around 1600 rows (just short of 25000 points).

Essentially using:

VBA Code:
rng.CopyPicture xlScreen, xlPicture

rng2.PasteSpecial

xlPrinter is even less, 200ish rows (I guess Print Area comes into play here).
xlBitmap has worse resolution and file size impact is almost double.
 
I am using ffmpeg for creating the WF image programmatically from the audio files, and it needs to have good enough resolution. Charters do use them for tempo mapping and the sort. If you check the size of the waveform PNGs in the folder it is 100,000 x 300 ( 2MB for horizontal and 700kb for vertical). I haven't tried to create a GIF, JPEG but as far as I get it, they also require some decompression algoritm to be drawn on a bitmap?

Actually it doesn't have to be transparent as it has its own column, but I need a way to put it on the compatible bitmap. GDI+ painting is much slower than GDI BitBlt it seems. Also, there may be multiple waveforms for different instruments.

I am working on a new test which will have multiple tracks just to see how memory will be affected, and to see the performance. 6000 rows for this song can actually be considered small. So I need to do proper testing and see if I will hit a limit somewhere (like max size a bitmap can have or similar) before starting changes on the app itself.

I will put an updated file when I finish with it.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Ahh - where have you defined the constant SRCCOPY?
 
Upvote 0
It is in mdlGlobals

VBA Code:
Public Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
 
Upvote 0
Oh ok - good, I guess. I was hoping that was the issue - that's what tripped me up at first, I completely glossed over the vbSrcCopy, thinking it would make sense to VBA, but no...
 
Upvote 0
Oh yes I definitely do. One of my big projects is a 32bit->64bit converter, because I haven't the patience to sit here and look up the API Declarations! It's a work in progress!
I've been giving it some more thought, but I don't think that what I've come up with is entirely on-point: one option was perhaps you could leverage a transparent webbrowser contro/HTML to do the image rendering for you; an off-shoot of the webbrowser control is the AtlAxWin class that featured in a few of Jaafar's projects recently. Alternatively, have you explored how the WIA COM Object might be able to help? My understanding is that it is simple a wrapper for GDI+ anyway.
 
Upvote 0
@Dan_W Hey Dan,

I was unable to make GDI+ work as I wanted, so went with having a bmp waveform image instead (actually was working on it when you asked on Friday). I didn't have the time to check out WIC to load a png as bitmap. However, I did reduce the size of the bitmap size to 30MBs since I only needed 80 pixels wide. The final version will need some other solution than just slapping the bitmap on, as waveform is created with equal time ticks, yet my rows time vary with repect to beats-per-minute. That is a later problem to solve though.

Another big change was instead of having one large memory bitmap (which works the fastest, but the memory needed might become enormous depending, I had around 2 GB impact even with this song. As it seems you can see the impact on memory in performance tab of Task Manager if it is large enough) I am now creating a bitmap that is userform size which has very little memory requirement (waveform being in memory at all times is the highest single memory consumer, but this wouldn't change even if I can load a png, so that works).

With this change I also create (paint) a single row while playback, using a copy of the TrackDC. This works for this particular song but will be slow for faster tempo ones, so I have an idea of creating more than one row each time needed, i.e., 5 rows at a time which will possibly take longer than a row's time. However, I can see the most time is lost while selecting/deselecting objects (bitblt usually is 1-2 ms each). So idea here is creating rows in bulk to get hit by overhead once instead of each row scroll. I still need to test this one.

Next I want to work on an overview/summary of the song (beats-per-minute, time signature, section markers etc) which I will use as a scroller (I will possibly put a transparent label under it and using mouse move/up/down events and also mouse wheel code from Jaafar) instead of a scroll bar which is limited by max value anyway.

Finally, since notes will need some additional formatting (a note can have couple of states depending on how you play in game), so I also wonder if maybe I can use pre-created pattern brushes, and just slap them on but that is a thought atm. Drawing rectangles are fast enough it seems.

I have uploaded a new gdi test.7z file (11 MB download).

GDrive - gdi test.7z

1644184525951.png



And you can slide the instruments this time with the scroll bar above (toggle button is non-functional atm).

1644184591387.png
 
Upvote 0
Frankly, I think you're doing an amazing job. That it can run so smoothly on my computer is a testament, I think, to your coding.

I was just thinking - MrExcel is great (of course!), but have you posted these questions/updates to any other forum? Because I'm thinking that you would get some further useful feedback/ideas from members using other platforms - I'm specifically thinking of VBForums and Reddit for any technical questions, and in one of the Codebanks of VBForums for the the finished product.

Also, looking at your code, I just wanted to say: (1) it's very clear and seemingly effortless - it's great; and (2) I've learnt a number of new things about the functionality available with mciSendString - thank you very much!

Finally, you really should prevent the user from letting the speed drop to anywhere near 400 or lower - it's absolutely terrifying listening to vocals at that speed.
 
Upvote 0
Hey, thanks :) Glad I am giving something back to the community.

Most stuff I am doing atm is just some calculations/ratios and timing/optimizing the steps involved. I may end up using other forums as well for the png -> bmp part. I have been struggling to get the bmp to align properly the last day, and only now noticed that ffmpeg outputs a somewhat elongated/shortened image (bmp size being constant 80x100,000) depending on the resampling number. Trying to understand that one at the moment. Will see how that goes.

I will post how you can put a video on a userform with mci later when I have the time. And if you have a real codec pack (i.e., K-lite, and not a wrapper one) you can use pretty much any format audio/video not just wav/mp3 and asf (perhaps a few more ancient formats).

At those speeds it is not for listening to the song actually, but to see/hear better if the notes are aligned to the sound. Less than 250 and above 4000 (you can speed it up also, just not needed in this case) it starts skipping or no sound at all.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,862
Members
449,052
Latest member
Fuddy_Duddy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top