[Closed] How to support DDS with dotnet drawing bitmap
(
local bmpDisplayed = dotNetObject “System.Drawing.Bitmap” “c: est.dds”
local bmpRectangle = dotNetObject “System.Drawing.Rectangle” 0 0 512 512rollout uiDotNetPictureBox “.NET PictureBox” width:512 height:512
(
dotNetControl uiPictureBox “System.Windows.Forms.PictureBox” pos:[0,0] width:320 height:240on uiPictureBox Paint senderArg paintEventArgs do
(
Graphics = paintEventArgs.Graphics
Graphics.DrawImage bmpDisplayed bmpRectangle
)
)try(destroyDialog uiDotNetPictureBox) catch()
createdialog uiDotNetPictureBox style:#(#style_titlebar, #style_border, #style_sysmenu)
)
it’s not working with .dds file
local bmpDisplayed = dotNetObject “System.Drawing.Bitmap” “c: est.dds”
can anyone help me to fix this problem ?
Thanks
I think you have to use DirectX Managed (no longer supported now) or XNA to load a DDS bitmap and get it as a .NET bitmap object.
Here’s what’s probably the worst way to do it
(
rollout uiDotNetPictureBox ".NET PictureBox" width:512 height:512
(
button btn_doit "You can do it!"
dotNetControl uiPictureBox "System.Windows.Forms.PictureBox" width:320 height:240
on btn_doit pressed do
(
local bmpRectangle = dotNetObject "System.Drawing.Rectangle" 0 0 512 512
theBitmap=openBitmap @"C: est.dds"
theImage=dotnetObject "System.Drawing.Bitmap" theBitmap.Width theBitmap.Height
for i=0 to theBitmap.Width-1 do
(
for j=0 to theBitmap.Height-1 do
(
bWH=getPixels theBitmap [i,j] 1
theColor=(dotnetClass "System.Drawing.Color").FromARGB bWH[1].r bWH[1].g bWH[1].b
theImage.SetPixel i j theColor
)
)
close theBitmap
theBitmap=""
uiPictureBox.Image=theImage
)
)
try(destroyDialog uiDotNetPictureBox) catch()
createdialog uiDotNetPictureBox style:#(#style_titlebar, #style_border, #style_sysmenu)
)
You can also use a third party image library like Freeimage, as it reads DDS files –
http://freeimage.sourceforge.net/
If you download the FreeimageNet wrapper dll, you can use it alongside the (unmanaged) Freeimage library. One great thing to note is this library will allow you to load formats that were previously incompatible with Windows/DotNet, most notably TARGAs.
Note you will need the Freeimage.dll in the same directory as the FreeimageNet.dll
dotnet.loadassembly ((getdir#scripts)+"\LoneRobot\ClassLib\FreeImageNet")
Freeimage = Dotnetclass "FreeImageAPI.Freeimage"
LoadFlags = Dotnetclass "FreeImageAPI.FREE_IMAGE_LOAD_FLAGS"
ImageFormat = Dotnetclass "FreeImageAPI.FREE_IMAGE_FORMAT"
-- load a DDS as a .Net bitmap
DDSfile = Freeimage.LoadBitmap ((getdir#scripts)+@"\logo.dds") LoadFlags.default ImageFormat.FIF_DDS
-- also, you could load a TGA as a .Net bitmap if you liked.
-- DDSfile = Freeimage.LoadBitmap ((getdir#scripts)+@" esttga.tga") LoadFlags.default ImageFormat.FIF_TARGA
clipboard =(dotNetClass "System.Windows.Forms.Clipboard")
clipboard.setimage DDSFile
DDSDotNetImage = getclipboardBitmap()
Display DDSDotNetImage
Artur: It’s the worst way because of the speed. It’s very slow because of getPixels and setPixels etc…
Pete: I didn’t knew FreeimageNet library. That looks very interesting to load bitmap types not supported by the framework.
Hey Yannick,
I’ve been using it for a while, and had purchased a .net wrapper for it (Advanced Image library). Freeimage is fast! This was before the C# wrapper on the site was released. Freeimage is x86 only on the site but I found that somewhere it had been compiled for X64. Haven’t had the time to test it with that yet, my X64 machine is standing in as my media center at the moment!
Yes, it does bridge the gap in formats, with the notable exception of RPF/RLA, which is the only thing to take the shine off it.
Thanks for sharing this resource Pete. I’ve been looking for a decent image library for a while. I find it really annoying that standard .NET requires you to use the System.Drawing.Color to get/set pixels because each channel is reduced to a byte instead of a ushort for 16bpc images. Will be checking this out for sure.
glad to be of help. One thing to remember is if you are not using the loadbitmap method, you are opening a freeimage bitmap, which is where all the adjustments and filters can be applied to a low level object. It’s a great deal faster than most other methods i’ve tried. Perhaps i’ll write an article if i get time.
Yeah, it’s way slow. I’ve found the FreeImage and the DevIL libraries but for some reason my brain and max didnt want to work together, I was doing dotnet.loadassembly “C:\FreeImageNet.dll” and it was giving me an error… dont know why, I’ve created some classes and added the .dll in the end and it worked, but as I’ve seen in LoneRobot example he didnt used it and it seems to work… Well, maybe next time Cheers all.