176 messaggi dal 04 giugno 2007
Contributi | Blog
Il codice originario in questione ha sfortunatamente più bachi di una seteria.

Il problema principale è che l'autore del server COM ha fatto un lavoro molto approssimativo. Ho provato con tre webcam diverse su due macchine e il codice originario in C# e due su tre non funzionano proprio alla funzione GrabFrame con errori vari, tutte COM exception con HRESULT diversi e non costanti.
Quando funzionava, stavo eseguendo per errore il progetto in C# usando una Philips Vesta 675 del 2001 sulla mia macchina secondaria (una macchina che per caso aveva VFW con il codec giusto). Se può essere una consolazione, il risultato non cambia con la traduzione in VB (corretto l'errore di conversione dell'array)

Il COM server è scritto usando un CODEC specifico Intel molto vecchio (2001) e non più supportato, che molti sistemi non hanno più. Se non hai quel codec ti becchi un E_NOTIMPL=0x80040001

Nota a margine, anche se riuscissimo a fare funzionare il tutto, avresti dei memory leak fuori scala. La funzione è implementata in modo degno del museo degli orrori: crea un reference a memoria allocata dal layer nativo e non usa il Dispose pattern correttamente.

Magari con un po' di sforzo puoi scriverti un wrapper per il WIA o il TWAIN della tua cam. Da qualche parte ricordo un TWAIN.net fatto bene che avevo usato tempo fa per lo scanner. Quello sì che era fatto bene.
Sto scrivendo ora una soluzione alternativa che usi un driver WIA
http://www.microsoft.com/downloads/details.aspx?FamilyID=a332a77a-01b8-4de6-91c2-b7ea32537e29&DisplayLang=en

Appena ho qualcosa di funzionante lo posto

Saluti

--Alessandro
176 messaggi dal 04 giugno 2007
Contributi | Blog
Fatto. Questo funziona con qualunque imaging device compatibile WIA

Code behind VB:

Imports WIA
Imports System.Drawing
Imports System.IO
Imports System.Net

Partial Class _Default
    Inherits System.Web.UI.Page


    Private device As Device = Nothing
    Private jpegKey As Microsoft.Win32.RegistryKey
    Private jpegGuid As String


    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        jpegKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("CLSID\{D2923B86-15F1-46FF-A19A-DE825F919576}\SupportedExtension\.jpg")
        jpegGuid = CType(jpegKey.GetValue("FormatGUID"), String)

        'find the right WIA device by Device ID
        'Look in the registry for the right ID after the GUID for your imaging device
        Dim manager As DeviceManager = New DeviceManagerClass
        For Each info As DeviceInfo In manager.DeviceInfos
            If (info.DeviceID = "{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0015") Then
                device = info.Connect
                Exit For
            End If
        Next
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If device IsNot Nothing Then
            Dim item As Item = device.ExecuteCommand(CommandID.wiaCommandTakePicture)
            For Each format As String In item.Formats
                If format = jpegGuid Then
                    Dim myImage As WIA.ImageFile = CType(item.Transfer(format), WIA.ImageFile)
                    Dim picture() As Byte = myImage.FileData.BinaryData
                    'Add the hour to the jpeg picture 
                    Dim ms As MemoryStream = New MemoryStream(picture)
                    Dim bmp As Bitmap = New Bitmap(ms)
                    Dim g As Graphics = Graphics.FromImage(bmp)
                    Dim strDate As String = (DateTime.Now.ToLongDateString + (" - " + DateTime.Now.ToLongTimeString))
                    Dim drawFormat As StringFormat = New StringFormat
                    drawFormat.Alignment = StringAlignment.Center
                    g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.Black), New RectangleF(1, 1, 320, 240), drawFormat)
                    g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.White), New RectangleF(0, 0, 320, 240), drawFormat)
                    bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
                    g.Dispose()
                    bmp.Dispose()
                End If
            Next
        End If
    End Sub
End Class


Pagina ASPX:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" ContentType="image/jpeg" %>


Perché funzioni è necessario che scarichi il COM Server per WIA da questo SDK di Microsoft http://www.microsoft.com/downloads/details.aspx?FamilyID=a332a77a-01b8-4de6-91c2-b7ea32537e29&DisplayLang=en che funziona da XP SP1 in poi.
devi anche fare la registrazione del componente facendo
RegSvr32 WiaAut.Dll da una command console sul server.
E ovviamente devi aggiungere una reference al tuo progetto alla dll wiaaut.dll

Grazie dell'occasione per giocare un po' con questo codice. C'è da divertirsi

--Alessandro
377 messaggi dal 10 settembre 2001
Contributi
fatto tutto, crewdo che io debba autorizzare qualcuno in più sul server!

Creating an instance of the COM component with CLSID {E1C5D730-7E97-4D8A-9E42-BBAE87C2059F} from the IClassFactory failed due to the following error: 80070005.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Creating an instance of the COM component with CLSID {E1C5D730-7E97-4D8A-9E42-BBAE87C2059F} from the IClassFactory failed due to the following error: 80070005.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Non vorrei commettere errori ed autorizzare chiunque a fare qualunque cosa sul server:
Chi devo autorizzare?

Grazie Riccardo

dopo la laurea dissi: ho finito gli esami, qualcuno mi rispose: Gli esami non finiscono mai ....
377 messaggi dal 10 settembre 2001
Contributi
è da stamattina che provo a dare autorizzazioni, ma nulla da fare, ti posto l'errore:

Creating an instance of the COM component with CLSID {E1C5D730-7E97-4D8A-9E42-BBAE87C2059F} from the IClassFactory failed due to the following error: 80070005.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Creating an instance of the COM component with CLSID {E1C5D730-7E97-4D8A-9E42-BBAE87C2059F} from the IClassFactory failed due to the following error: 80070005.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Grazie ancora
Riccardo

dopo la laurea dissi: ho finito gli esami, qualcuno mi rispose: Gli esami non finiscono mai ....
176 messaggi dal 04 giugno 2007
Contributi | Blog
Questo codice deve girare sotto un utente che abbia unmanaged code permissions per potere creare il componente COM.
Strano che il problema capiti solo ora: il tuo vecchio codice ha le stesse identiche caratteristiche.

Saluti

--Alessandro
377 messaggi dal 10 settembre 2001
Contributi
???


scusami, ma c'è una soluzione ?

Grazie.

Riccardo

dopo la laurea dissi: ho finito gli esami, qualcuno mi rispose: Gli esami non finiscono mai ....
176 messaggi dal 04 giugno 2007
Contributi | Blog
Certo che c'e' una soluzione.

Giusto per fare la prova del fuoco, il codice gira se impersoni admin nel web.config?

Sotto che OS giri?

Sei su un server in hosting o e' tuo?

Insomma, il solito.
377 messaggi dal 10 settembre 2001
Contributi
impersono admin nel web config in questo modo:
<identity impersonate="true" userName="administrator" password="password"/>
dove user e psw sono le stesse che uso per accedere allo spazio web e per accedere via destop remoto sul server, ma anche con questa impostazione nel web config "NULLA da FARE", sempre che queste credenziali siano quelle di admin, ma credo che siano proprio loro.

Il server è in hosting, ma è "mio", nel senso che ci accedo liberamente, ne ho io l'amministrazione, ci metto e ci tolgo ciò che voglio, un esempio, le dll le ho registrate io direttamente.

Il S.O del server credo che sia xp 2003, di questo non ne ho la certezza, posso accertarmene.

Ufff che casotto speriamo di uscirne vincitori.

Ti posto l'indirizzo della pagina che sto provando:
www.italianbakerycafe.com/webcamCapture.aspx



Riccardo

dopo la laurea dissi: ho finito gli esami, qualcuno mi rispose: Gli esami non finiscono mai ....

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.