wyrd Posted June 18, 2004 Posted June 18, 2004 With Bitmaps there's an option to LockBits which provides a BitmapData class and access to the actual bytes in memory. However, I want to load something other than a bitmap (a TGA to be more specific). Using Image.LoadFromFile gives me a nice Image object, unfortunately I see nothing similar to LockBits. Thanks in advance. Quote Gamer extraordinaire. Programmer wannabe.
Menge Posted June 18, 2004 Posted June 18, 2004 There's always [C#] public Bitmap( Image original ); btw... didn't know .Net could load TGAs Quote Menge
wyrd Posted June 18, 2004 Author Posted June 18, 2004 No kiddin'? Wonder how I missed that constructor. Anyway.. don't know if it loads TGAs or not, I hope so. :) If it doesn't, I'll have to find another format that uses alphas and .NET accepts. There anywhere I can find a list of supported image types? EDIT: Maybe it doesn't supports TGAs. I load a TGA using Image.FromFile(file) and then create a bitmap with Bitmap(img), after that it gives me an out of memory exception. Quite odd. Quote Gamer extraordinaire. Programmer wannabe.
wyrd Posted June 18, 2004 Author Posted June 18, 2004 Yup it was the TGA file format that was the problem to begin with. I used a PNG file just to test, and it loaded fine using the regular Bitmap constructor (no Image). Meh.. anyone know a good format that allows alphas and is acceptable by .NET? Quote Gamer extraordinaire. Programmer wannabe.
*Experts* mutant Posted June 18, 2004 *Experts* Posted June 18, 2004 I'm not sure if that is all the formats supported natively but take a look at this class which lists some image formats: System.Drawing.Imaging.ImageFormat Quote
wyrd Posted June 18, 2004 Author Posted June 18, 2004 Hmm.. looks like I'll just go ahead with PNG since it allows alpha channels. Thanks for the help guys. Quote Gamer extraordinaire. Programmer wannabe.
wyrd Posted June 18, 2004 Author Posted June 18, 2004 Yeah.. I never looked at the PNG format before. They are certainly smaller in file size. Only 6k for an image that was ~24 in both BMP and TGA format. Unless there's some serious reason why I shouldn't be using it, I think I'll stick with it for future projects. :) Quote Gamer extraordinaire. Programmer wannabe.
ThePentiumGuy Posted June 18, 2004 Posted June 18, 2004 png's are good their format doesn't look lossy at all (like jpg's) since youre using them in an app its good but on a webpage it wont 'show up' - you have to physically open it yourself in like notepad or something btw - 6k for an image?? my png's (lets say 32x32) are measured in BYTES ;) (dont remmeber how many tho) edit: earlier, looking at your title Getting byte data from an Image. i was gonna suggest using RAW files. the only thing it stores are the bytes in an image (i use them for heightmaps.. well im trying to figure it out) prob: not sure if you can do Alpha im not sure if .DDS would work either - use the textureviewer in the sdk , but im not sure if it'll suit your purposes pent Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
pbounaix Posted July 14, 2004 Posted July 14, 2004 in C# you can do something like this: #region ConvertImageToBytes /// <summary> /// Converts Image (from path) to string /// </summary> /// <param name="imagePath">string</param> /// <returns>byte[]</returns> public byte[] ConvertImageToBytes(string imagePath) { FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); byte[] b = br.ReadBytes((int)fs.Length); br.Close(); fs.Close(); return b; } #endregion [/Code] gl Quote
predseda Posted July 23, 2004 Posted July 23, 2004 Hmm, .png is good but there is a one problem. PNG uses similar bitmap data comprimation like GIF. It means that in all PNG file can be used only 256 different colors of 24bit palette (16,7 milion colors). Theese colors are defined in the head of file. So if you are working with internet bitmaps it is good to use PNG (btw. Mozilla supports Alpha channel) , but if you are working with photos or professional images it is a big restriction. If you would like to edit images for professional use, I thing you ought to study PDF file structure. :-) OK, I know that it looks difficulty but its better like create new file format. You can downlad pdf SDK form adobe.com, but it's pay-for-use. Quote
Administrators PlausiblyDamp Posted July 23, 2004 Administrators Posted July 23, 2004 Err, PNG isn't limited to 256 colours - certainly one of the formats it supports is 256 bit palette-based colours but that isn't the only format. Out of interest it supports palette based in 1, 2, 4 or 8 bit formats, greyscale up to 16bits and true colour up to 48 bits. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
predseda Posted July 24, 2004 Posted July 24, 2004 :eek: Really? The hell, if this is true then I am the happiest developer worldwide! ...that also means that I had downloaded bad PNG format specifications time ago. So... PNG! :cool: Ok, but the first queston was how to extract data from image file... Any idea? Quote
predseda Posted July 25, 2004 Posted July 25, 2004 By the way... Any idea how to save bitmap as PNG with option to set image quality ? Thanks. Quote
Hamburger1984 Posted July 25, 2004 Posted July 25, 2004 just a tought: use the FreeImage-Library [Sourceforge-page] ..it supports all common Image-Formats and is a lot faster for loading Images that the .NET-Framework. to draw those Images you'd need a little bit of Interop- or API-Calls (to be exact you need two of them) but that should be acceptable.. the library is opensource and there's a C#-Wrapper in the package.. you can convert, open and save images in every supported format. Andreas Quote
predseda Posted July 26, 2004 Posted July 26, 2004 Dear Hamburger1984, I will NEVER import to my application something, what is protected by GNU GPL licence - product of Free Software Foundation. FSF with some other organizations are sects based on communistic ideology wich is recuiting young developers for non-payed work. Best example is GNU/Linux - developers are creating it for free, but linux distribution management advantages from technical support. Uncrowned (or crowned?) king of this all is Richard Stallman - man, wich resonds expressly comunistic idea - intellectulal work never can be payed as manual work. You may think - it's free, so I can use it and GNU ideology never mind me. But I am from country wich was before second world war country with sewenth world's best economic and after 40 years of communism we are now at 60th position. So I am looking at GNU bit another. If you would like to use FreeImage-Library you must paste this in about box: This software uses the FreeImage open source image library. See http://freeimage.sourceforge.net for details. FreeImage is used under the (GNU GPL or FIPL), version (licence version). But I departed out of problem. So... back to programming: Time ago was posted in forum Graphics question by ThePentiumGuy, how to draw image from array to screen - but fast. PlausiblyDamp posted answer - shorcout to PascalsTriangle tutoriual. In that tutorial is a method how to covert Integer Array to Bitmap object. So must exists way to convert Bitmap to Integer Array i think. But how? Any idea? For better understand: 1. Load image from file to bitmap object - No problem 2. Convert Bitmap Object to Integer array - how??? 3. Edit the image = edit the array - No problem 4. Save changed image / draw on scren - No problem So how to convert bitmap object to Integer Array - using .Net framework. predseda Quote
Hamburger1984 Posted July 26, 2004 Posted July 26, 2004 hey hey predseda.. no need to get pissed off here.. if you don't like OpenSource (the idea to share thoughts for free - like for example on this forum [why are you using it? should look for a company to pay for the tips you get here for free]) that's your problem.. I don't see a problem with using such library and giving credit to the people that created it, but that's my opinion.. with that post I just wanted to point out, that there's a faster way to open, convert and save images than using the Framework (which isn't capable to do real converting at all - only 24bpp.. happy birthday!! ;)) Have a nice day! Andreas Quote
predseda Posted July 26, 2004 Posted July 26, 2004 Hamburger1984, I like OpenSource idea for example Mozilla project, but not GNU. I don't see a problem with using such library and giving credit to the people that created it, but that's my opinion.. - Yes me too, but not GNU. I don't agree with GNU GPL backgroung. ...and save images than using the Framework (which isn't capable to do real converting at all - only 24bpp.. happy birthday!! ;)) 24bpp?? wake up man, it suppots up to 64bpp = 16R + 16G +16B + 16A But I think 24bit = over 16 milion colors is adequate accuracy. Why to use third-party componet when I can use built-in function? predseda Quote
Hamburger1984 Posted July 26, 2004 Posted July 26, 2004 (edited) well okay.. maybe I missread your post.. but as I said - I'd use that library because of speed, better compression (why save a grayscale-image at 24 (or 32) bpp when you only need 8bpp?.. but that depends on what you need.. ..and btw.. can you show me how to save a .NET Bitmap with 64bpp or if you like with 1bpp (b/w) or 8bpp (grayscale)? if there's a possibility to do this I'd like to learn how.. prove me wrong that the .NET-Framework isn't very flexible when it comes to saving Images.. (I know you could use API-Calls to the GDI+ Library, which supports different bpps afaik.. - but I'm talking about the Framework..) Andreas ..and btw.. parts of Mozilla are under GNU-License ..to actually answer the question asked: take a look at these articles: - Image Processing Part 1 - Image Processing Part 2 - Image Processing Part 3 - Image Processing Part 4 - Image Processing Part 5 Edited July 26, 2004 by Hamburger1984 Quote
predseda Posted July 26, 2004 Posted July 26, 2004 (edited) Dim MyBitMap as Bitmap MyBitMap = New Bitmap(Width, Height, Imaging.PixelFormat.Format32bppRgb) Vivat Microsoft .Net ;) I have seen that tutorials time ago, but I don't know why I thought they are using GetPixel method. The hell! It looks good. And It looks that there is no Bitmap to Integer Array converting! But I have minimum knowledge about C#... So I will try to translate it. Parts of Mozilla are GNU-GPL ? Maybe, I am not sure, but I have never seen gnu craps (neither word GNU) on mozilla.org predseda Edited July 26, 2004 by predseda Quote
Hamburger1984 Posted July 26, 2004 Posted July 26, 2004 ...okay.. that's it.. ;) I don't think this "discussion" will lead anywhere, since you don't read AND understand.. first: read the link I posted (this one) .. you only need to read the first paragraph: "This page details the licenses under which Mozilla source code can be obtained. At the moment, parts of the source are available under either the Netscape Public License (NPL) or the Mozilla Public License (MPL), often in combination with either the GNU General Public License (GPL) or the GNU Lesser General Public License (LGPL), or both. mozilla.org is working towards having all the code in the tree licensed under a MPL/LGPL/GPL tri-license; for more information, see the Relicensing FAQ. Any code checked into our CVS tree needs to comply with the licensing policy." see? wasn't that complicated, was it? second: read the other links I posted.. you'll notice that the author does use Get/SetPixel BUT also uses LockBits and (fast) unsafe code to access Pixels.. third: you haven't proven anything with your snippet of code.. see attachment and explain what good a bitmap is if you can't manipulate it (draw on it).. furthermore you can create a (for example) 1bpp-Bitmap but you can't save it as 1bpp.. too bad... http://xtremedotnettalk.com/images/smilies/wink.gif ...and finally: let's stop this discussion - as I said it doesn't lead anywhere good... Cheers AndreasbitDepth.zip Quote
predseda Posted July 26, 2004 Posted July 26, 2004 1. Ok, mozilla is GNU licence based, It is also not resounds typical GNU ideas like Vote for Microsoft 100% free!!! etc... And there is is no fee for updates and technical support (maybe because of donations) and this is rarity. I think it is a big shame for any software to use GNU GPL. 2. ...use Get/SetPixel BUT also uses LockBits and (fast) unsafe code to access Pixels.. Yes, Lockbits - there shall be the key, now I am using another, fast method, but this looks better (I will do some speed test and I will tell you.). Using Lockbits looks easy, I will try it tomorrow mornig (I am in the same time zone like you) so I will tell you. 3. third: you haven't proven anything with your snippet of code.. see attachment and explain what good a bitmap is if you can't manipulate it (draw on it).. furthermore you can create a (for example) 1bpp-Bitmap but you can't save it as 1bpp.. too bad... I will send you tutorial, how to manipulate. How to save... hmmm. I am solving this now. ( I asked PlausiblyPamp how to with PNGs on page 1) I have idea how, I am sure that it is posibble, evently to save in CMYK mode (of course only formats wich support CMYK like jpeg). When I will know how-to I will post it. ...and finally: let's stop this discussion - as I said it doesn't lead anywhere good... Hehehe :) Really? Wait for tutorial and you will see if no. Or better idea: Download it from this forum - search in graphics - Pascal's Triangle. Vielen dank fur dein zeit. Ich habe lernt deutsch funf jahre, aber jetzt Ich weiss nur einige worter. ;) predseda Quote
predseda Posted July 26, 2004 Posted July 26, 2004 Hamburger1984, By the way...What did you mean with this? ...will lead anywhere, since you don't read AND understand.. Ok man, I have no experience with C#, but I am VB.Net developer (or lowly I want to be), so don't think I am fool... And next, your attachment is in C#, so bye-bye :) , I can help you only with VB.Net. ( I think you know VB.Net syntax or not? ) Tutorial Pascal's Triangle is written in VB.Net too. predseda Quote
*Gurus* divil Posted July 26, 2004 *Gurus* Posted July 26, 2004 Use the LockBits method. You may think you have an Image object, but really you have a Bitmap object. You never have an Image in .net - even if you use Image.FromFile, you end up with a Bitmap. So just cast it. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.