ASP.NET libwebp.dll如何将WebP映像保存到磁盘 [英] ASP.NET libwebp.dll how to save WebP image to disk
问题描述
我使用
我对你的样本也有问题,所以我检查来源,看起来你使用不同的方法然后是样本,不知道为什么。
所以我改变并看起来有效。
< DllImport(libwebp.dll,CallingConvention: = CallingConvention.Cdecl)GT;
私有共享函数WebPEncodeBGRA(ByVal rgba As IntPtr,ByVal width As Integer,ByVal height As Integer,ByVal stride As Integer,ByVal quality_factor As Single,< Out> ByRef output as IntPtr)As Integer
End函数
< DllImport(libwebp.dll,CallingConvention:= CallingConvention.Cdecl)>
私有共享函数WebPFree(ByVal p As IntPtr)As Integer
结束函数
和导入
导入System.Runtime.InteropServices
我从 Thise说明'libwebp-0.6.0.zip \ x64 \ bin',它可以工作。
当我从
尝试附加你的dll时,请在这里下载已编译和压缩的libwebp.dll。这是我正在使用的图像文件:
得到完全相同的异常,看起来不是64
对于图像我不确定,可能你需要逆转它
'data.strinde = webp_data'不确定什么是webp_data ewxacly,但你可以查看
'data.Scan0 = webp_data'不确定什么是webp_data ewxacly,但你可以检查
source.UnlockBits(data)
source.Save(Server.MapPath( images \)+audio.png)
I've built libwebp.dll
for WebP, using these instructions (I downloaded this source code)
I've added the libwebp.dll
file to the bin
folder of my project.
I then added this code (found here):
Private Declare Function WebPEncodeBGRA Lib "libwebp.dll" (ByVal rgba As IntPtr, ByVal width As Integer, ByVal height As Integer, ByVal stride As Integer, ByVal quality_factor As Single, ByRef output As IntPtr) As Integer
Private Declare Function WebPFree Lib "libwebp.dll" (ByVal p As IntPtr) As Integer
Private Sub Encode()
Dim source As Bitmap = New Bitmap(Server.MapPath("images\") + "audio.png")
Dim data As BitmapData = source.LockBits(New Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim webp_data As IntPtr
Dim i As Integer = WebPEncodeBGRA(data.Scan0, source.Width, source.Height, data.Stride, 80, webp_data)
WebPFree(webp_data)
End Sub
I get the error:
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
What I also did (after comments from Dai below):
- I built the dll for a 64-bit architecture like so:
nmake /f Makefile.vc CFG=release-dynamic RTLIBCFG=dynamic OBJDIR=output ARCH=x64
(also see here) - I checked IIS for the application pool in question and it has the property
Enable32-Bit Applications
set toFalse
- I'm running Windows 10 64 bit
- Both
Environment.Is64BitProcess
andEnvironment.Is64BitOperatingSystem
in code-behind evaluate asTrue
How can I encode the image and save the encoded image to disk in WebP format?
To test on your machine:
Download the compiled and zipped libwebp.dll here. This is the image file I'm using:
i also have problem with yours sample, so i check sources and looks like u use different approach then is in sample, don't know why.
so i change and looks it works.
<DllImport("libwebp.dll", CallingConvention:=CallingConvention.Cdecl)>
Private Shared Function WebPEncodeBGRA(ByVal rgba As IntPtr, ByVal width As Integer, ByVal height As Integer, ByVal stride As Integer, ByVal quality_factor As Single, <Out> ByRef output As IntPtr) As Integer
End Function
<DllImport("libwebp.dll", CallingConvention:=CallingConvention.Cdecl)>
Private Shared Function WebPFree(ByVal p As IntPtr) As Integer
End Function
and import
Imports System.Runtime.InteropServices
i Have use dll from Download libwebp-0.6.0.zip from Thise instructions 'libwebp-0.6.0.zip\x64\bin' and it works.
When i try attache your dll from Download the compiled and zipped libwebp.dll here. This is the image file I'm using:
got exactly this same exception, looks like is not 64
for image i'm not sure, probaly u need reverse it
'data.strinde = webp_data 'not sure what is webp_data ewxacly, but you can check
'data.Scan0 = webp_data 'not sure what is webp_data ewxacly, but you can check
source.UnlockBits(data)
source.Save(Server.MapPath("images\") + "audio.png")
这篇关于ASP.NET libwebp.dll如何将WebP映像保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!