Author |
Message |
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sat May 17, 2008 11:15 am Post subject: c# - saving images to file |
|
|
|
|
I'm trying to save images to a file along with some strings, and i have a few questions.
1.Can i save a whole image "data" in one line.
2.Can i open a whole image "data" (in one line).
3.How can i do this. |
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sat May 17, 2008 4:50 pm Post subject: |
|
|
|
|
thanks for the response.
the thing is i need to stick those bytes in between some strings.
example:
subspace
rules
everyone
(insert bitmap bytes here in one line)
because
it's
addicting |
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:25 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sat May 17, 2008 9:07 pm Post subject: |
|
|
|
|
not sure i'm getting it. i didn't see where it does the saving. i'm going to give it a go anyways, using bytes. |
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:25 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Sat May 17, 2008 9:12 pm Post subject: |
|
|
|
|
what if your bytes contain newlines |
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sat May 17, 2008 9:57 pm Post subject: |
|
|
|
|
i'm going to try something like this
streamwritervar.WriteLine(binarywriter.write(bytes));
.Writeline only writes one line. that should make me safe. |
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sat May 17, 2008 10:09 pm Post subject: |
|
|
|
|
You could work with a binary file instead of a text file...
It would need headers and things like that so that your program knows, for example, the size (in bytes) of the image.
Kind of how .lvl files are... there's a bitmap at the start of the file, then there is the tile data.
You can check out the LVZ and eLVL file structure for some more complex examples too. _________________ (Insert a bunch of dead links here) |
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sun May 18, 2008 10:13 am Post subject: |
|
|
|
|
ooo i'm not looking to revamp my whole saving system. but isn't there a way to mix binary with text.
example:
hi
samapico
(insert wierd chineese characters/binary)
thanks
for
the
help
that's what I'm hoping to do. |
|
Back to top |
|
|
Doc Flabby Server Help Squatter
Joined: Feb 26 2006 Posts: 636 Offline
|
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sun May 18, 2008 11:13 am Post subject: |
|
|
|
|
i've figured out how to write and read binary. thanks guys.
now i have a small problem.
basically when i want to open it, i need to pass how many bytes to read as a arg. like this: "BinaryReaderVariable.ReadBytes(int count);"
how do i know how many bytes to read?
if i were to save something in that same file inorder to know how many bytes to read, what would it be
(it would look something like this)
write:
binarywriter.write(some int here)
binarywriter.write(write image bytes)
read:
int count = binaryreader.readint32();
binaryreader.readbytes(count);
thank you very much for your help!!!!! |
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sun May 18, 2008 11:29 am Post subject: |
|
|
|
|
nvm i got it to work!
int count = byte[].Length;
only problem is that it sordof gets screwed up. lower quality stuff. |
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun May 18, 2008 11:50 am Post subject: |
|
|
|
|
tcsoccerman wrote: | ooo i'm not looking to revamp my whole saving system. but isn't there a way to mix binary with text.
example:
hi
samapico
(insert wierd chineese characters/binary)
thanks
for
the
help
that's what I'm hoping to do. |
That might not work properly... because in your line containing the data bytes, there might very well be bytes with the value 13 or 10, which are newline characters... So your data would then be split in different lines.
If you tell it how many bytes to read, however, it should work I guess. Your file should then look like:
the size
of the pic data is
452
(insert binary data)
so you know
how many
to read
when loading |
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sun May 18, 2008 12:18 pm Post subject: |
|
|
|
|
yeh thats what i did.
my problem now is that when i try to save an empty string it screws everything up. do i have to go throw every variable in every object and make it = " ";??? can you do a foreach(string in player/staffmember/financeitem)? |
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sun May 18, 2008 9:18 pm Post subject: |
|
|
|
|
i got it all worked out. and yes if the value was null or string was empty, i would have to make the string = " ";
i still have that photo quality loss problem though. sometimes it happens sometimes it doesn't. probably something to do with .png/.jpg conversions to .bmp. |
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon May 19, 2008 2:29 am Post subject: |
|
|
|
|
hmmm, are you using a picturebox control? Maybe the image is resized in the control, and then you might be saving the content of the control, instead of the original image |
|
Back to top |
|
|
Animate Dreams Gotta buy them all! (Consumer whore)
Age:36 Gender: Joined: May 01 2004 Posts: 821 Location: Middle Tennessee Offline
|
Posted: Mon May 19, 2008 7:09 pm Post subject: |
|
|
|
|
Do you really have to use that Base64 thing? I've never saved any pictures, but in C++, I just saved things to files in binary format by putting everything in a struct(using fixed size char arrays for the text) and wrote to the file that way. I don't know what Base64 is, but it doesn't seem like it would be necessary. Or is it a C# thing? |
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Mon May 19, 2008 9:17 pm Post subject: |
|
|
|
|
Something to do with emails. i didn't use it, i used binary as well, but you have to convert it to bytes first. |
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:25 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Mon May 19, 2008 9:20 pm Post subject: |
|
|
|
|
base64 is a way to convert arbitrary binary data into ascii letters and numbers.
the inverters of email couldn't send arbitrary binary data so they needed to convert everything into letters and numbers. result: all email attachments take up 4/3 the download size than they need to. |
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sat May 24, 2008 9:03 pm Post subject: |
|
|
|
|
slightly related to this problem, google has failed to help me with my imagelist problems.
i'm trying to store large images in the imagelist, but it always reduces the images to the size of small icons (256x256 to like 16x16). When i do "imagelist.ImageSize = 256, 256", it gives index errors.
Has anyone here successfuly stored large images in imagelists? |
|
Back to top |
|
|
k0zy Server Help Squatter
Gender: Joined: Jan 11 2003 Posts: 571 Location: Germany Offline
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon May 26, 2008 6:36 pm Post subject: |
|
|
|
|
Don't use imageLists :S
Well, in some cases, it's probably good to use, but I would avoid it for large images.
ImageLists are usually used for all the small images of a toolbar, for example.
I'd use an array of Images if I were you... gives you more flexibility, as images can have different sizes.
And as Bob Dole pointed out, you can't just write "256, 256"... Always check the types. ImageSize is definitly a 'Size' type variable. So you have to set it to a 'Size' variable. A 'new' object often works for these things. |
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Mon May 26, 2008 7:55 pm Post subject: |
|
|
|
|
thats what i did, i was just using psuedo code. ty anyways.
i'll use an image array then, getting the images from the same directory as the executable. |
|
Back to top |
|
|
tcsoccerman Server Help Squatter
Age:31 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Mon May 26, 2008 8:00 pm Post subject: |
|
|
|
|
not gonna lie, must of the questions i ask here i shouldn't, because by the time you answer i already did what you answered with. I'm just lazy. thanks anyways guys. |
|
Back to top |
|
|
|