1. Can you please provide screenshot? What dll exactly?
2. It isn't implemented yet. The article how to do it here.
Printable View
1. Can you please provide screenshot? What dll exactly?
2. It isn't implemented yet. The article how to do it here.
in my system win7 32 chinese . have error
can you fix?
Attachment 159365
Progress.
xxdoc123, baka there is the bug in Direct2D on some OS.
ID2D1GeometrySink inherits ID2D1SimplifiedGeometrySink but if you call QueryInterface(ID2D1GeometrySink, IID_ID2D1SimplifiedGeometrySink) it raises the type mismatch error. I've fixed that error by manually casting types.
questions:
Im trying to use 2 render hwnd.
one I call cTarget and is set to be rendered in picturebox1
and the other cTargetSys on picturebox2
I have tried with different approaches but always giving me the error: automation error (runtime error "-2003238891" (88990015)
first I render cTarget first, using the .presentOptions = D2D1_PRESENT_OPTIONS_NONE, with begin to end.
after that I call cTargetSys, that i using .presentOptions = D2D1_PRESENT_OPTIONS_IMMEDIATELY to make it immediately.
but I get the error.
are there any way to 2 hwnd or do I need to make it on 1 hwnd only?
Attach the project please.
here the source: https://www80.zippyshare.com/v/RywqEggN/file.html
i also use a typelib (custom) that includes a bunch of API im using. i added the ODL if you want to look into it.
Updation.
Fixed bug with "Compile Error, Error in Loading DLL".
Added example with embedded fonts collection.
https://s8.hostingkartinok.com/uploa...d1eea3cf53.png
baka you use the resources from different render target (D2DERR_WRONG_RESOURCE_DOMAIN). You should use either the compatible resources (bitmaps created by the same render target) or use D2D1_RENDER_TARGET_TYPE_SOFTWARE flag.
review of the latest build:
- SaveImage
try to run or make I get:
Unexpected error (32810)
at "Private Sub Form_Load()"
everything else works! the old errors are fixed. also, I can change the target flag to either SOFTWARE or HARDWARE and both works! :D
Please show the screenshot.Quote:
try to run or make I get:
Unexpected error (32810)
at "Private Sub Form_Load()"
original: https://postimg.cc/gallery/3geeungqk/
Attachment 159389Attachment 159391
also, the demo CustomFont loads from the resource file, how to load from external file?
baka, i can't produce that error on all my VM.
It doesn't matter you can load it to a byte array from a file instead the resources.Quote:
also, the demo CustomFont loads from the resource file, how to load from external file?
Here's a harder one, save an image from a render target using Windows 7 interfaces. (MSDN only shows the windows 8+ interfaces)
edit: also thanks for all the hard work on this Trick. I won't be releasing a typelib for a long time. If I do it will most likely be a large all in one typelib, including all of DirectX, sort of like SharpDX/SlimDX for VB6.
You should either replace tlbs or re-register them.Quote:
Still shows error "load dll error"
Yes, but CreateWicBitmapRenderTarget works since Vista SP2. It's look like a compiler error (bug?).Quote:
Here's a harder one, save an image from a render target using Windows 7 interfaces. (MSDN only shows the windows 8+ interfaces)
Okay, then maybe i'll post that sources on CodeBank (after i add comments, fix bugs, and make more examples).Quote:
also thanks for all the hard work on this Trick. I won't be releasing a typelib for a long time. If I do it will most likely be a large all in one typelib, including all of DirectX, sort of like SharpDX/SlimDX for VB6.
BTW, i accept the suggestions for the new demos.
what kind of termination/unload should be applied for direct2d?
right now I just use Set variable$ = Nothing.
the same when I unload a picture, and re-use the bitmap, as :
Set Image(0) = LoadImageEx(Filename) that is a ID2D1Bitmap
and when Im unloading it I use:
Set Image(0) = Nothing
is this enough of do I need to do more?
I notice that direct2d is not stable in IDE. if Im running a few times and do some changes in the project (like adding a picturebox) the IDE can crash (need to save the project before running)
baka, i don't know the reason why you have the crashes. If you provide me the project caused the crash i can see.
ok, just run it once in IDE, click the "X" to quit, and add a textbox anywhere and run again. it will crash.
https://www30.zippyshare.com/v/FwjwVIvf/file.html
but if you run it again without adding anything it will run without crashing.
that is why im asking if there a termination/unload procedure.
I asked in one of my previously post about the refresh rate, since D2D1_PRESENT_OPTIONS is following the monitor refresh-rate, i think its useless to calculate fps.
sure, the fps could fluctuate a bit, but nothing i want to monitor, the user need to take responsibility to not overuse the cpu/gpu when running the game, or change the refresh rate during play.
the easiest way is to use the API GetDeviceCaps with the parameter VREFRESH.
it's working on my machine and im running windows 7.
my questions, is this compatible with all windows version, also 10? any other method that can be used?
Hi Baka,
I haven't started messing with Direct2D. But, as I'm sure you know, I managed to get a fairly substantial Direct3D project going, using The Trick's typelib.
One of the early problems I ran into was my FPS being faster than my monitor's refresh rate. By default, Direct3D refreshes the screen at the monitor's refresh rate as the fastest it'll go.
However, with some digging, I found the PresentationInterval item of the D3DPRESENT_PARAMETERS structure (UDT), which is used to initialize a IDirect3DDevice9 device. By default, it's PresentationInterval is set to D3DPRESENT_INTERVAL_DEFAULT, which won't go faster than the monitor's refresh rate. However, if you explicitly set PresentationInterval to D3DPRESENT_INTERVAL_IMMEDIATE, the Direct3D refresh rate becomes completely detached from the monitor's refresh rate, allowing you to render frames as fast as your CPU/GPU will do it for you. You must do this as you're instantiating your IDirect3DDevice9 device.
That solved a huge problem for me, and allowed me to make perfect sense of my FPS.
I don't know for certain, but I have to believe there's a similar setting in the Direct2D system.
Good Luck,
Elroy
in D2D we got .presentOptions in the D2D1_HWND_RENDER_TARGET_PROPERTIES, where we can choose:
NONE, IMMEDIATELY and RETAIN_CONTENTS.
right now Im using "NONE", that seems to follow the monitor refresh rate (that is 60 for me)
with IMMEDIATELY it will not pause at all, and that most be the same as D3DPRESENT_INTERVAL_IMMEDIATE for D3D.
im not done with the conversion of the game, theres a lot more to do, but if i need more fps i will definitely use IMMEDIATELY and create the fps of my choosing.
but using NONE, i think theres no need to calculate fps each second, instead i use the API i mentioned before and make the calculation one time before start (the speed factor)
as i dont know the refresh-rate, and the only way to get it is by running 1 time and that could give me 59-61 instead of 60, i think GetDeviceCaps is quite useful.
another issue.
i just started the project in another computer, now the aspect ratio is wrong. the same project using GDI i dont get this behavior.
it seems that the DrawBitmap is not following pixel but DPI, and will render it incorrectly. the dimension of the target picturebox is not considered.
so, if I set 800x600 the picturebox, DrawBitmap will render like 1000x750 (or something), going outside the boundaries.
looking at the code, if I enter cTarget.Resize and use 1000x750 the aspect it almost correct, but the picturebox is only 800x600
how can I let direct2d use the picturebox dimension?
ha. i was about to edit/post something but you where faster.
i wanted to ask about this:
where the original size is 800x600 and X/Y will return 120/120 (in this monitor) and it seemed to work, but a faster fix as you posted is to simply:Code:cTarget.GetDpi X, Y
oSize.Width = 8 * X
oSize.Height = 6 * Y
cTarget.Resize oSize
thanks! :)Code:cTarget.SetDpi 96, 96
another thing i would like to ask/discuss is the cleanup procedure.
while coding and "testing" i get too often crashes.
right now i use "set x = nothing" to cleanup for the images and everything else.
even so sometimes when i "try again" to run, after some changes, the IDE crashes.
i need to save everytime i run. its good practice anyway but its quite annoying that it crashes.
so, if I run, and close, run and close, no crashes.
but if I run, and close, add something, and run it crashes (but not always)
Was just reading through this thread for the first time, just wanted to note types can be cross-tlb compatible in almost all cases, it's almost always acceptable to simply change the UDT argument to a long and pass VarPtr(udt).
I feel bad now for not finishing WIC last year; that's a lot of work and there's a half converted unincluded source file sitting in all the oleexp zips forever now.
would be nice to be able to remove oleexp.tbl and only use wicvb.tbl and d2dvb.tbl.
right now oleexp.tbl is needed to run, where i move it down in the priority list and its conflicting against my custom tbl.
if i try to copy the part needed from the oleexp.tbl to my custom tbl it doesn't work.
baka, you can get around conflicts by explicitly declaring types. Put oleexp at the bottom of the priority list, then whenever you're using something from it that's also in your custom tlb, define the module specifically; e.g. Dim var As oleexp.IWhatever -- and not just interfaces, types, enums, etc too.
thx fafalone, i knew about that i could write the typelib's name to specify which one to use, but i think that a better typelib for the wic package should be complete without the need to use the oleexp.
another thing.
we have D2D1_INTERPOLATION_MODE to specify the algorithm used to scale the image.
we have:
D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
and its supported from 7, Vista SP2, so unfortunately no xp support.
reading in the docs, I notice that we have more algorithms
D2D1_INTERPOLATION_MODE_CUBIC
D2D1_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR
D2D1_INTERPOLATION_MODE_ANISOTROPIC
D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC
but are only supported from windows 8 and Platform Update for Windows 7 [desktop apps | UWP apps]
not sure what this Platform Update is, but its nothing I have.
maybe an update would be nice, even if Im still on windows 7 I will eventually move to 10 and to have 4 more
another thing about this. changing the interpolation modes doesn't seem to do much. it seems to be identical.
so I read that
D2D1_BITMAP_INTERPOLATION_MODE
has 2 modes while
D2D1_INTERPOLATION_MODE
has 6 modes
the latter is Direct2D 1.1 and should be available in windows 7 from a patch, but no vista/xp support.
the second mode require ID2D1DeviceContext and its DrawBitmap and DrawImage while the one available uses ID2D1RenderTarget : DrawBitmap
any way to add the other method?
I'm was doing the typelib which works on Win7 (because i have this one).
fair enough, maybe its better to be compatible for now! :)
a question:
I have trouble to make the interpolation work. I know from the demo you created that it should work but not for me:
I add inside a class:
Dim InterPolationMode As D2D1_BITMAP_INTERPOLATION_MODE
Sub Quality(ByVal Interpolation As D2D1_BITMAP_INTERPOLATION_MODE)
InterPolationMode = Interpolation
End Sub
everything works, but no matter what Interpolation Im using its always D2D1_BITMAP_INTERPOLATION_MODE_LINEAR it seems.Code:the rendering loop is:
cTarget.BeginDraw
cTarget.Clear ClsRGB
----------------
- any amount of:
cTarget.DrawBitmap ui(index), dRect, 1, InterPolationMode, sRect
----------------
cTarget.EndDraw ByVal 0&, ByVal 0&
in the class_initialize It doesnt matter what I choose with in InterPolationMode, its always the same anyway.
maybe its the dRect/sRect as Im cutting parts of the graphics into a specific position.
they are both D2D1_RECT_F
also, I have a "default" pixelsize in HwndRenderTargetProperties set to 800x600 (thats the default size I use)
when I maximize the form, Im not changing anything in dRect/sRect, I let direct2d upscale. I also set cTarget.SetDpi 96, 96 so it will always use the same dpi.
Please make the small demo that produces the error.
Attachment 161959
heres the project.
the rendering will show:
cut and paste, using D2D1_RECT_F
direct rendering using SetTransform to skip D2D1_RECT_F (byval 0&)
and SetTransform using a bit of rotation and no D2D1_RECT_F
only when rotation is involved the interpolation works.
Seems all is correct. You draw the picture with original size, what's the behavior do you expect? For example if you change aspect/or sizes you can see interpolation:
https://s8.hostingkartinok.com/uploa...b7804839e2.jpg
hm. in my testing I get this:
Attachment 161965
if I resize the window I get this (Linear up and Nearest down)
Attachment 161967
so I dont get the same as you!
as you can see in the picture, only the "rotated" pictures show different, the other 4 pictures are identical-
original pictures: (seems that the insert image is converting the pics)
https://i.postimg.cc/13fJnqsh/Image2.png
https://i.postimg.cc/Kj1Rrxzz/Image3.png
The interpolation mode is related to bitmap drawing. You should use the Resize method to ensure the proper backbuffer size. If you want to use the fixed screen (500x300) and stretch it to a window you can use an additional compatible render target in which you can draw the bitmaps. Finally you can draw the produced bitmap to the window with the needed interpolation mode (don't forget call Resize method!).
https://s8.hostingkartinok.com/uploa...b722ed4536.jpg
hm, im trying to figure out where to put CreateCompatibleRenderTarget.
but no matter what im doing i get errors or nothing happens. the resize works, but it will not stretch the image.
lets say the small project that i shared. what do I do to have a fixed screen (500x300) and let i stretch using interpolation with the CreateCompatibleRenderTarget.?
https://s8.hostingkartinok.com/uploa...f7b86d98cd.jpgCode:Option Explicit
Dim mcFactory As ID2D1Factory
Dim mcHwndTarget As ID2D1HwndRenderTarget
Dim mcMemTarget As ID2D1BitmapRenderTarget
Private Sub Form_Load()
Dim cBrush As ID2D1SolidColorBrush
Me.ScaleMode = vbPixels
Set mcFactory = D2D1.CreateFactory()
Set mcHwndTarget = mcFactory.CreateHwndRenderTarget(D2D1.RenderTargetProperties(D2D1.PixelFormat()), _
D2D1.HwndRenderTargetProperties( _
Me.hWnd, D2D1.SizeU(100, 100)))
Set mcMemTarget = mcHwndTarget.CreateCompatibleRenderTarget(ByVal 0&, ByVal 0&, ByVal 0&, D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE)
Set cBrush = mcMemTarget.CreateSolidColorBrush(D2D1.ColorF(BurlyWood), ByVal 0&)
' // Paint to mem target
mcMemTarget.BeginDraw
mcMemTarget.DrawEllipse D2D1.Ellipse(D2D1.Point2F(30, 30), 15, 15), cBrush, 3
mcMemTarget.DrawLine 0, 0, 80, 90, cBrush
mcMemTarget.EndDraw ByVal 0&, ByVal 0&
End Sub
Private Sub Form_Paint()
' // Draw to hwnd
mcHwndTarget.BeginDraw
mcHwndTarget.DrawBitmap mcMemTarget.GetBitmap, D2D1.RectF(0, 0, Me.ScaleWidth, Me.ScaleHeight), _
, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, ByVal 0&
mcHwndTarget.EndDraw ByVal 0&, ByVal 0&
End Sub
Private Sub Form_Resize()
mcHwndTarget.Resize D2D1.SizeU(Me.ScaleWidth, Me.ScaleHeight)
End Sub
its working! thanks a lot! i didnt think that i could use a memory-bitmap, its like i do with gdi, i thought that i could do it without. i think its quite odd that they created an automatic stretch feature but didnt include interpolation.
im doing it a bit different, without paint-event as im using a loop, but its working nevertheless.
i just replace all DrawBitmap with the memory-bitmap and at the very end, im adding:
where cTarget is the memory-bitmap.Code:Sub RenderDC()
cTarget.EndDraw ByVal 0&, ByVal 0&
hTarget.BeginDraw
hTarget.DrawBitmap cTarget.GetBitmap, oRect, 1, InterPolationMode, ByVal 0&
hTarget.EndDraw ByVal 0&, ByVal 0&
End Sub
oRect contains the width and height of the picturebox (im using that to render, as the form itself, when maximized will retain the aspect ratio)
problem with:
Run-time Error '-2003238900 (8899000c)'
Automation Error
and it happens here: hTarget.EndDraw ByVal 0&, ByVal 0&
it occurs when I use "ctrl+alt+del" in windows 7 to bring up the "login menu"
im inside a "loop" to render animations in monitor-refresh rate.
it happens both IDE and compiled.
if I try with "On Error Resume Next" it will not work.
I also tried the GetForegroundWindow to only render when the form is active, but don't work.
any ideas?
https://docs.microsoft.com/en-us/win...2d-error-codes
https://docs.microsoft.com/en-us/win...-with-direct2dQuote:
D2DERR_RECREATE_TARGET
0x8899000C
A presentation error has occurred that may be recoverable. The caller needs to re-create the render target then attempt to render the frame again.
Quote:
While your program is running, the graphics device that you are using might become unavailable. For example, the device can be lost if the display resolution changes, or if the user removes the display adapter. If the device is lost, the render target also becomes invalid, along with any device-dependent resources that were associated with the device. Direct2D signals a lost device by returning the error code D2DERR_RECREATE_TARGET from the EndDraw method. If you receive this error code, you must re-create the render target and all device-dependent resources.
To discard a resource, simply release the interface for that resource.
ok, thanks for that info, i will try to create a function that will reset everything if that happens! :D
i added 1 more loop,
do while state = 0
do while state = 0
- game & rendering -
loop
cleanup/unload
if state=1, I do another loop waiting for GetForegroundWindow=Form.Hwnd. when, it will restart direct2d and load all resources. and set state to 0
loop
terminate
in the render function Im adding a "On Error Resume Next", and CheckWindowState, if "1" D2D1_WINDOW_STATE_OCCLUDED, I know something is wrong. state is the variable I store this.
when I exit normally, with the "x" close button, i add state=2 and it will exit both loops.
Hi, i am begginer, i not know this libraries, Direct2d, Direct3D, is open-source?
someone know or can make a GraphicsLibary Pure VB6 like Aforge?
the base of library with cornersDetectors, EdgeDEtectors, Thereshould, some scientifc algorithms, and next, add more features?
the algorithms of geometry in VB6 is more easy found in web, but the base of library not.
cheers!
duplicated
Hi xman2000,
I took a look at the AForge library, and it looks like it would take quite a bit of work to build an interface for it for a VB6 program. However, you might be better off if you just ask for the specific functions/algorithms you want. I know that you said, "cornersDetectors, EdgeDEtectors, Thereshould, some scientifc algorithms", but maybe you could be more specific ... especially if you're trying to get some VB6 program written and need something specific. These forums are quite rich with many graphics and scientific algorithm solutions.
Also, when asking for these things, you may do better to start your own thread (or even start your own thread when discussing AForge).
Good Luck,
Elroy
for more info about direct2d just google and check microsoft's direct2d page.
The trick created this "typelib", that need to be included in the "references" to work.
The trick created samples to try so there should be enough to get started.
theres a lot of functions to use for geometry and other things, but like any other library theres limitations so you need to create your own functions/formulas, but direct2d is enough to do any kind of graphic work and its fast, u can control dpi and it can do all the upscaling automatically. theres typelibs for directx9 as well if u want to work with 3d u can find them in this forum.
its not open source, but the typelibs are "free" and do not require dependencies except os requirements for that directx version and should be already installed.
Hi Elroy, I'm trying to motivate people to create a ImageComputerVision in PureVB6, and know about if someone done it.
Aforge.net is C# and a good start to make a VB6 library, but my intention is PureVB6 and not a wrapper, wrapper have in web like this:
Professional Image Modifier 2 Dave A. Gordon
https://code.msdn.microsoft.com/vstu...hId=1920673660
"https://code.msdn.microsoft.com/vstudio/Professional-Image-280a2421/sourcecode?fileId=107118&pathId=1920673660"
this example with Aforge.net use SUSAN Corners Detector and VB.NET and some examples have source-code others the compiled dll.
Elroy you can convert Algoritms of other Languague like C#, C++ , Python, Java, Jscript or Matlab to VB6?
i found many open-source image libraries on the web, greate alogrithms or samples, but not can convert to vb6.
I think if you can make the basis of Libary with 2 or 4 algorithms in a free to commercial use open-source, other people can add more features.
i am like corners detectors: SUSAN, FAST, AGAST
edge detection: SUSAN, CANNY, SOBEL
contour DualContour (DC) : DualContouring
image: KNN nearest neighbor, kmeans, image segmentation, image clustering
thereshould: otsu thereshould, diferentialThereshould, others
i can put the list here antoher moment, the ACCORD.NET have more algorithms that AForge.net (Accord is other version of Aforge)
if you look the source-code of ACCORD.NET you understand, but i can speak the name of most important algorithms not found in VB6 on the web.
thanks.
Hmmm, I must be in a cantankerous mood this morning.
But, as I see it, a hijack by any other name is still a hijack.
And I just don't understand why you don't start your own thread. I suspect many of us have been quite motivated by trying to address clear questions in the starting post of a new thread.
Hi Elroy, i am not have too many knowlegde and conditions now to manage the project, but if you start a thread and start the project i am follow you or other people.
I am not able to create the basis of a Library and not to convert of other programming languages entire algorithms, but i know many others things about image procesing an the most important algorithms, i have the vision about this.
i am not found powerfull ImageLibrary in pure VB6 open-source like have in other languagues like C# Aforge.net.
i think the key is create the small structured hierarchy with few algorithms and in the future add more.
cheers!
See that project. There is the convolution-based algorithms you can use for the start point:
https://i.ibb.co/cyjm0Mf/testwqw.jpg
Hi The Trick, i have many source-code i am collecting and yours code too.
but some algorithms i am not found in VB6 and not able to convert to VB6, i am try but gives error like illegal words (online translator).
i am begginer programmer, not professional, but i know many things about programming and image procesing.
If one people make the Basis Struture with Hierarchy and few algorithms, then, other people will translate algorithms and add to library. Aforge.net the people translate to many other language programming.
i to my personal purpose need more CornersDetectors, DualContouring and Thereshould algorithms, but, to use to more professional cases, need a more complete library.
i am not understand the reason community of VB6 and VB.net not make a VisionLibrary like other communities.
the big problema of VB6 is not open-source and outdated.
then, is a greate think make the librarys open-source to make the language possible to update with new features and not outdated.
The trick, thanks for your contibution, se i can, i will start the project next year, but if someone want, please start the thread, leader the project.
thanks.
edit: The trick, please a compiled exe version of this sample above?
reexre, YES, yes !! i know your work, your software!!
yes, please, i can send to your some algorithms, links, etc, and your translate when you have time.
please star you the new thread if you can and like, yes, greate good news my friend!!
edi: user reexre, you can download the sample file of Dave A Gordon Professional Image Modifier (vb.net) using AForge.net to study how make similar sample file using only pure VB6 and not AForge?
i think this sample file have few files and only source-code and not DLLS.
please answer to me.
Honestly I was not going to open a new thread.
Anyway, I saw that Elroy already did it here
Hope to find even other people interested in this too.
im trying to figure out how to get the context of a hdc/hwnd and send it to a direct2d bitmap.
using WIC, CreateBitmapFromHBITMAP but that require hBitmap and hPalette so its not really what i need.
so they idea is: copy picture1.hdc to ID2D1Bitmap and render it to a direct2d RenderTarget.
also, it would be nice to be able to take a screenshot of any hwnd/hdc and send it to a ID2D1Bitmap.
still the examples i can find googling are based in c++.
any idea?
ok i figure it out.
so, first we create a compatiblebitmap using: getdc, createcompatibledc,createCompatibleBitmap and use selectobject (u can find tons of examples for that)
what we need is: thisone = CreateCompatibleBitmap(hDC, width, height)
now we use BitBlt to take the screenshot and we store it into the created compatibledc. thats it for the gdi part.
now we use CreateBitmapFromHBITMAP to create a wicbitmap:
and lastly we create a ID2D1Bitmap using:Code:Set wicBitmap = cWICFactory.CreateBitmapFromHBITMAP(thisone, ByVal 0&, WICBitmapUsePremultipliedAlpha)
Set cConverter = cWICFactory.CreateFormatConverter()
cConverter.Initialize wicBitmap, WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, Nothing, 0, WICBitmapPaletteTypeMedianCut
of course to render it we use BeginDraw,DrawBitmap and EndDrawCode:Set hBitmap = hTarget.CreateBitmapFromWicBitmap(ByVal cConverter, ByVal 0&)