News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

GdipSaveImageToFile problem

Started by jj2007, November 06, 2016, 01:37:03 PM

Previous topic - Next topic

jj2007

      gdi+ GdipCreateBitmapFromGraphics, 100, 50, gicbImg, addr hTmpBmp            ; MasmForum
      gdi+ GdipSaveImageToFile, hTmpBmp, wChr$("TestImage.gif"), addr gif, 0
      gdi+ GdipSaveImageToFile, hTmpBmp, wChr$("TestImage.jpg"), addr jpeg, 0
      gdi+ GdipSaveImageToFile, hTmpBmp, wChr$("TestImage2.jpg"), addr jpeg2, 0
      gdi+ GdipSaveImageToFile, hTmpBmp, wChr$("TestImage3.jpg"), addr jpeg3, 0
      gdi+ GdipSaveImageToFile, hTmpBmp, wChr$("TestImage.bmp"), addr bmp, 0
      gdi+ GdipSaveImageToFile, hTmpBmp, wChr$("TestImage.png"), addr png, 0
      gdi+ GdipDisposeImage, hTmpBmp


jpeg GuidFromString({557cf401-1a04-11d3-9a73-0000f81ef32e}) ; SOF
png GuidFromString({557cf406-1a04-11d3-9a73-0000f81ef32e})
jpeg2 GuidFromString({25336920-03F9-11cf-8FD0-00AA00686F13}) ; CLSID at:
; HKEY_CLASSES_ROOT\MIME\Database\Content Type\image/jpeg
; HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MIME\Database\Content Type\image/jpeg
jpeg3 GuidFromString({607fd4e8-0a03-11d1-ab1d-00c04fc9b304})
gif GuidFromString({25336920-03F9-11cf-8FD0-00AA00686F13})
bmp GuidFromString({25336920-03F9-11cf-8FD0-00AA00686F13})


Trouble is that most of them fail - and the only one that doesn't bark at me creates a black image :(
** line 41, GdipCreateBitmapFromGraphics      Ok
** line 42, GdipSaveImageToFile               FileNotFound
** line 43, GdipSaveImageToFile               Ok
** line 44, GdipSaveImageToFile               FileNotFound
** line 45, GdipSaveImageToFile               FileNotFound
** line 46, GdipSaveImageToFile               FileNotFound
** line 47, GdipSaveImageToFile               Ok
** line 48, GdipDisposeImage                  Ok

Vortex


TWell

#2
Build in encoders:
Clsid:    {557CF400-1A04-11D3-9A73-0000F81EF32E}
FormatID: {B96B3CAB-0728-11D3-9D7B-0000F81EF32E}
CodecName: Built-in BMP Codec
FormatDescription: BMP
FilenameExtension: *.BMP;*.DIB;*.RLE
MimeType: image/bmp
Version:  1

Clsid:    {557CF401-1A04-11D3-9A73-0000F81EF32E}
FormatID: {B96B3CAE-0728-11D3-9D7B-0000F81EF32E}
CodecName: Built-in JPEG Codec
FormatDescription: JPEG
FilenameExtension: *.JPG;*.JPEG;*.JPE;*.JFIF
MimeType: image/jpeg
Version:  1

Clsid:    {557CF402-1A04-11D3-9A73-0000F81EF32E}
FormatID: {B96B3CB0-0728-11D3-9D7B-0000F81EF32E}
CodecName: Built-in GIF Codec
FormatDescription: GIF
FilenameExtension: *.GIF
MimeType: image/gif
Version:  1

Clsid:    {557CF405-1A04-11D3-9A73-0000F81EF32E}
FormatID: {B96B3CB1-0728-11D3-9D7B-0000F81EF32E}
CodecName: Built-in TIFF Codec
FormatDescription: TIFF
FilenameExtension: *.TIF;*.TIFF
MimeType: image/tiff
Version:  1

Clsid:    {557CF406-1A04-11D3-9A73-0000F81EF32E}
FormatID: {B96B3CAF-0728-11D3-9D7B-0000F81EF32E}
CodecName: Built-in PNG Codec
FormatDescription: PNG
FilenameExtension: *.PNG
MimeType: image/png
Version:  1

mabdelouahab

Quote
Type: image/bmp,  GUID: {557CF400-1A04-11D3-9A73-0000F81EF32E}
Type: image/jpeg,  GUID: {557CF401-1A04-11D3-9A73-0000F81EF32E}
Type: image/gif,    GUID: {557CF402-1A04-11D3-9A73-0000F81EF32E}
Type: image/tiff,    GUID: {557CF405-1A04-11D3-9A73-0000F81EF32E}
Type: image/png,   GUID: {557CF406-1A04-11D3-9A73-0000F81EF32E}

GetEncoderClsids proc
   LOCAL num,_size,pImageCodecInfo
   invoke GdipGetImageEncodersSize, addr num ,addr _size
   .if _size
      MOV pImageCodecInfo,halloc(_size)
      invoke GdipGetImageEncoders,num, _size, pImageCodecInfo
      MOV ESI,pImageCodecInfo
      XOR EDI,EDI
   @@:invoke StringFromGUID2,esi,addr strGuid,255
      printf("\nType: %s,GUID: %s",[ESI].ImageCodecInfo.MimeType,addr strGuid)
      ADD ESI, sizeof ImageCodecInfo
      INC EDI
      CMP EDI,num
      JNE   @B      
      hfree(pImageCodecInfo)
   .endif
   ret
GetEncoderClsids endp

jj2007

Thanks to all of you - that was truely inspiring (=I ruthlessly stole your ideas) :biggrin:

Jokes apart, I got it running, see here, but WOW, Microsoft has built features into GdiPlus that I would never had thought of :dazzled:
QuoteDesperate user: While loading a JPG file using Gdiplus::Bitmap::FromFile(fileName), the file is being locked, so i am not able to delete the file.
...
Expert: GDI+ does tend to hold files open for images for the duration of the image.

Yeah, it "does tend", actually it defends the files like a lioness her kids until you shut down GdiPlus completely. It's almost as perfect as the RichEdit control :greensml:

But I cheated them, and a simple SaveImageToFile wFiles$(imgCt) will do the job now :P
The "w" before Files$() simply means it expects Unicode, so that you can drag your Arabic ladies collection over the exe 8)

servoguy

#5
Quote from: Vortex on November 06, 2016, 07:30:44 PM
Hi Jochen,

Here is an example.

Thanks very much for this excellent info. Exactly what I was looking for.    :t
MSDN is less helpful than usual here, they just tell you to use the C++ Class.


... read some code .... notices some stuff .... brain starts to hurt ...reads a bit more ....gets dizzy ..... OMG its actually built that way  ;) lol ok ok ... I get it, but seriously thanks for the info, cool snippet.