|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Save Picture QWith the code below, the 'PathToIconFile.ico' is a 256 colour Icon File When the SavePicture Method is called the Icon in 'ADifferentPath.ico' is 16 colours, or at least that's what it looks like. Where am I going wrong? Why does the Icon File not get saved like the original? Thanks in advance? Ivar Picture1.Picture = LoadPicture("PathToIconFile.ico") DoEvents SavePicture Picture1.Picture, "ADifferentPath.ico" DoEvents 'BreakPoint Here To look at picturebox, 256 colours Picture1.Picture = LoadPicture("ADifferentPath.ico") 'PictureBox now has 16 colours There isn't a color depth choice. According to the
docs, I think, it saves in the color depth currently being used on the system. I don't know how it could end up saving 16-color, but if you want to control it you might consider building the icon yourself. There are sample projects around, and an icon file is not very complex. You just need a fairly simple header, followed by the bitmap, followed by a 2-color mask bitmap that specifies the transparent area. Actually 24-bit color icons are easier than 256-color. The latter requires a color table in the file to display properly. Without that it's functionally a 24-bit color icon: It won't display properly with 16-bit display or lower. Show quoteHide quote > > With the code below, the 'PathToIconFile.ico' is a 256 colour Icon File > When the SavePicture Method is called the Icon in 'ADifferentPath.ico' is 16 > colours, or at least that's what it looks like. > Where am I going wrong? Why does the Icon File not get saved like the > original? > > Thanks in advance? > > Ivar > > Picture1.Picture = LoadPicture("PathToIconFile.ico") > DoEvents > SavePicture Picture1.Picture, "ADifferentPath.ico" > DoEvents > 'BreakPoint Here To look at picturebox, 256 colours > Picture1.Picture = LoadPicture("ADifferentPath.ico") > 'PictureBox now has 16 colours > >
Show quote
Hide quote
"Ivar" <Ivar.ekstromer***@ntlworld.com> wrote in message SavePicture saves a BMP file, regardless of the extension used.news:zJlol.13008$FN7.5337@newsfe04.ams2... > Hi all. > > With the code below, the 'PathToIconFile.ico' is a 256 colour Icon File > When the SavePicture Method is called the Icon in 'ADifferentPath.ico' is > 16 colours, or at least that's what it looks like. > Where am I going wrong? Why does the Icon File not get saved like the > original? > > Thanks in advance? > > Ivar > > Picture1.Picture = LoadPicture("PathToIconFile.ico") > DoEvents > SavePicture Picture1.Picture, "ADifferentPath.ico" > DoEvents > 'BreakPoint Here To look at picturebox, 256 colours > Picture1.Picture = LoadPicture("ADifferentPath.ico") > 'PictureBox now has 16 colours Look at your saved 'ico' file with a hex editor & you will see that the first 2 bytes are &H42 &H4d = > "BM" = > .bmp "Norm Cook" <normc***@cableone.net> wrote in message Actually that's not strictly true. SavePicture will save an .ico or a .wmf news:eznQTsblJHA.1168@TK2MSFTNGP05.phx.gbl... > SavePicture saves a BMP file, regardless of the extension used. > Look at your saved 'ico' file with a hex editor & you will see > that the first 2 bytes are &H42 &H4d = "BM" or a .emf image in icon or metafile format as appropriate if the image was loaded from file directly into the Picture property of a PictureBox (or into a stdPicture object), although it saves an icon usually without its transparency information and in a default size and a default colour depth, which I think is system dependent and which is usually not the same as the loaded depth and size, a fact which the OP seems to have already discovered. You are correct though about SavePicture saving a Picture property in the ..bmp format regardless of the format that was originally loaded if the Picture property has been modified since loading, for example if it was assigned to it from the Image property of a PictureBox. This of course prevents you from loading an icon and then modifying it and then using SavePicture to save it out again as an icon, which I assume is what the OP eventually wants to do otherwise he would just be renaming the original .ico file if he merely wanted to make a copy of it. If the OP actually does want to load and modify and then save icon files then the following might be of help to him, although I've never tried it myself so I don't know how much code needs to be added to make it perform what the OP seems to eventually want to do: http://www.vbaccelerator.com/home/vb/code/Libraries/Graphics_and_GDI/Reading_and_Saving_ICO_Files_in_VB/article.asp Mike "Norm Cook" <normc***@cableone.net> wrote in message news:eznQTsblJHA.1168@TK2MSFTNGP05.phx.gbl... Not according to VB's documentation for the SavePicture statement:> > SavePicture saves a BMP file, regardless of the extension used. > "If a graphic was loaded from a file to the Picture property of an object, either at design time or at run time, and it’s a bitmap, icon, metafile, or enhanced metafile, it's saved using the same format as the original file. If it is a GIF or JPEG file, it is saved as a bitmap file." -- Mike
Show quote
Hide quote
"MikeD" <nob***@nowhere.edu> wrote in message Mike & Mike: Thanks for the clarification. I read the helpnews:u5NTShflJHA.1388@TK2MSFTNGP06.phx.gbl... > > "Norm Cook" <normc***@cableone.net> wrote in message > news:eznQTsblJHA.1168@TK2MSFTNGP05.phx.gbl... >> >> SavePicture saves a BMP file, regardless of the extension used. >> > > Not according to VB's documentation for the SavePicture statement: > > "If a graphic was loaded from a file to the Picture property of an object, > either at design time or at run time, and it’s a bitmap, icon, metafile, > or enhanced metafile, it's saved using the same format as the original > file. If it is a GIF or JPEG file, it is saved as a bitmap file." > > -- > Mike on savepicture before answering, but apparently didn't really understand it. Loading a pbox with an icon at design time, I note that: SavePicture Picture1.Image => bmp SavePicture Picture1.Picture => ico "Norm Cook" <normc***@cableone.net> wrote in message news:uDmrTXolJHA.5028@TK2MSFTNGP04.phx.gbl... Which is also documented in VB's Help for the SavePicture statement:> > Mike & Mike: Thanks for the clarification. I read the help > on savepicture before answering, but apparently didn't really > understand it. Loading a pbox with an icon at design time, > I note that: > > SavePicture Picture1.Image => bmp > SavePicture Picture1.Picture => ico > "Graphics in an Image property are always saved as bitmap (.bmp) files regardless of their original format." -- Mike Hi Ivar,
If you have the path to the original icon, why use SavePicture when you can just copy the original file ? Show quoteHide quote "Ivar" <Ivar.ekstromer***@ntlworld.com> wrote in message news:zJlol.13008$FN7.5337@newsfe04.ams2... > Hi all. > > With the code below, the 'PathToIconFile.ico' is a 256 colour Icon File > When the SavePicture Method is called the Icon in 'ADifferentPath.ico' is > 16 colours, or at least that's what it looks like. > Where am I going wrong? Why does the Icon File not get saved like the > original? > > Thanks in advance? > > Ivar > > Picture1.Picture = LoadPicture("PathToIconFile.ico") > DoEvents > SavePicture Picture1.Picture, "ADifferentPath.ico" > DoEvents > 'BreakPoint Here To look at picturebox, 256 colours > Picture1.Picture = LoadPicture("ADifferentPath.ico") > 'PictureBox now has 16 colours > "Ivar" <Ivar.ekstromer***@ntlworld.com> wrote in message Sorry I've not replied, had to go earn money for bills & kids etc.news:zJlol.13008$FN7.5337@newsfe04.ams2... > Hi all. > > With the code below, the 'PathToIconFile.ico' is a 256 colour Icon File > When the SavePicture Method is called the Icon in 'ADifferentPath.ico' is > 16 colours, or at least that's what it looks like. > Where am I going wrong? Why does the Icon File not get saved like the > original? > > Thanks in advance? > > Ivar Anyway: been having a play today and looking at some sample codes and the above can now be done with the class that listed by Mike W. but! it don't fix my problem. This is what I'm trying to achieve: A Usercontrol has a property page. On that property page is a means of loading an .ICO file That pic (as StdPicture, also Tried IPicture and iPictureDisp) is then put in a Class that belongs to the Usercontrol. In UserControl Property bag I 'Write' the picture as stdpicture. In the Read Properties I load the stdPicture in to the class. But it gets stored in the frx file as 16 colours even thou the stdpicture in the class is a 256 colours when first loaded via the property page. The question should have been about saving and retrieving the stdpicture as a 256 colour in the read and write of a property bag in a user control. I could have a go at saving the bits as a string in the property bag, but I'm hoping someone can come up with the magic answer Thanks Again Ivar Hi Ivar,
Show quoteHide quote "Ivar" <Ivar.ekstromer***@ntlworld.com> wrote in message Does saving the Image work for you as that would be a bitmap.news:UCXol.9763$qy7.2089@newsfe30.ams2... > > "Ivar" <Ivar.ekstromer***@ntlworld.com> wrote in message > news:zJlol.13008$FN7.5337@newsfe04.ams2... >> Hi all. >> >> With the code below, the 'PathToIconFile.ico' is a 256 colour Icon File >> When the SavePicture Method is called the Icon in 'ADifferentPath.ico' is >> 16 colours, or at least that's what it looks like. >> Where am I going wrong? Why does the Icon File not get saved like the >> original? >> >> Thanks in advance? >> >> Ivar > > Sorry I've not replied, had to go earn money for bills & kids etc. > Anyway: been having a play today and looking at some sample codes and the > above can now be done with the class that listed by Mike W. but! it don't > fix my problem. > This is what I'm trying to achieve: > A Usercontrol has a property page. > On that property page is a means of loading an .ICO file > That pic (as StdPicture, also Tried IPicture and iPictureDisp) is then put > in a Class that belongs to the Usercontrol. > In UserControl Property bag I 'Write' the picture as stdpicture. In the > Read Properties I load the stdPicture in to the class. But it gets stored > in the frx file as 16 colours even thou the stdpicture in the class is a > 256 colours when first loaded via the property page. > The question should have been about saving and retrieving the stdpicture > as a 256 colour in the read and write of a property bag in a user control. > > I could have a go at saving the bits as a string in the property bag, but > I'm hoping someone can come up with the magic answer > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message But then he would have a 32 bit solid rectangular bitmap (or whatever the news:uVfv0p7lJHA.4420@TK2MSFTNGP05.phx.gbl... > Does saving the Image work for you as that would be a bitmap. system colour depth is) and he would have lost the transparency mask. It would no longer be an icon. Mike "Ivar" <Ivar.ekstromer***@ntlworld.com> wrote in message I still can't see exactly what you want to do with the icons apart from news:UCXol.9763$qy7.2089@newsfe30.ams2... > The question should have been about saving and retrieving > the stdpicture as a 256 colour in the read and write of a > property bag in a user control. storing and retrieving them, but if you are merely moving them about from place to place, rather than modifying their images, then perhaps you can simply store and retrieve the raw .ico file data, perhaps as a Byte array or whatever? You can then transfer the Byte array data into the Picture property of a PictureBox (or an Image Control) whenever you wish to display the icon. One thing I have noticed is that VB is not very good at drawing an icon when it is assigned to a Picture property, with the edges not being smooth as they usually are when the OS displays them, so you might also need to look into using DrawIcon and its other associated stuff. Mike
optional args to a class.Init method
Anyway to move Image control at runtime Dim WithEvents * As HTMLDocument with an Iframe - access denied!? Recommended IDE for the PocketPC Automatic determine .Rows in MSHFLexgrid Unsigned C long to signed VB5 Long query. Cannot pass a control array ? convert Unicode string Use ColumnClick and Click Event in MSHFLexGrid Remove empty elements from end of array |
|||||||||||||||||||||||