Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
c# - saving images to file

 
Post new topic   Reply to topic Printable version
 View previous topic  can't compile c++ code Post :: Post Digital Hockey  View next topic  
Author Message
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sat May 17, 2008 11:15 am    Post subject: c# - saving images to file Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Sat May 17, 2008 1:41 pm    Post subject: Reply to topic Reply with quote

Fill a byte array with the data you need to save then simply use one of these functions.
1.
http://msdn.microsoft.com/en-us/library/system.io.file.writeallbytes.aspx
2.
http://msdn.microsoft.com/en-us/library/system.io.file.readallbytes.aspx
3. see above.
_________________
Rediscover online gaming. Get Subspace | STF The future...prehaps
Back to top
View users profile Send private message Add User to Ignore List
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sat May 17, 2008 4:50 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Bak
?ls -s
0 in


Age:19
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Sat May 17, 2008 6:42 pm    Post subject: Reply to topic Reply with quote

lookup how e-mail encodes attachments

http://en.wikipedia.org/wiki/Base64
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sat May 17, 2008 9:07 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Bak
?ls -s
0 in


Age:19
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Sat May 17, 2008 9:12 pm    Post subject: Reply to topic Reply with quote

what if your bytes contain newlines
Back to top
View users profile Send private message Add User to Ignore List AIM Address
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sat May 17, 2008 9:57 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Samapico
No, these DO NOT look like penises, ok?


Age:32
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Sat May 17, 2008 10:09 pm    Post subject: Reply to topic Reply with quote

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.
_________________
DCME co-developer
17th Parallel Head Sysop
Subspace: The Future
Back to top
View users profile Send private message Add User to Ignore List
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sun May 18, 2008 10:13 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Doc Flabby
Server Help Squatter


Joined: Feb 26 2006
Posts: 636
Offline

PostPosted: Sun May 18, 2008 10:34 am    Post subject: Reply to topic Reply with quote

Encode your binary as base64 as bak said earlier
Code: Show/Hide


public string EncodeTo64(byte[] toEncode)
    {
      return System.Convert.ToBase64String(toEncodeAsBytes);
    }
Back to top
View users profile Send private message Add User to Ignore List
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sun May 18, 2008 11:13 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sun May 18, 2008 11:29 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Samapico
No, these DO NOT look like penises, ok?


Age:32
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Sun May 18, 2008 11:50 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sun May 18, 2008 12:18 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sun May 18, 2008 9:18 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Samapico
No, these DO NOT look like penises, ok?


Age:32
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Mon May 19, 2008 2:29 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Animate Dreams
Gotta buy them all!
(Consumer whore)


Age:31
Gender:Gender:Male
Joined: May 01 2004
Posts: 821
Location: Middle Tennessee
Offline

PostPosted: Mon May 19, 2008 7:09 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address MSN Messenger
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Mon May 19, 2008 9:17 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Bak
?ls -s
0 in


Age:19
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Mon May 19, 2008 9:20 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List AIM Address
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Sat May 24, 2008 9:03 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
k0zy
Server Help Squatter


Gender:Gender:Male
Joined: Jan 11 2003
Posts: 571
Location: Germany
Offline

PostPosted: Sun May 25, 2008 9:14 am    Post subject: Reply to topic Reply with quote

tcsoccerman wrote:
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?


Code: Show/Hide
imageList1.ImageSize = new Size(255,255);

http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist(VS.71).aspx

What did you google?
Second hit on the query "imagelist larger images"
_________________
It's a shark! Oh my god! Unbelievable!
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Age:32
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Mon May 26, 2008 6:36 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Mon May 26, 2008 7:55 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
tcsoccerman
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Mon May 26, 2008 8:00 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Non-Subspace Related Coding All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 135 page(s) served in previous 5 minutes.

phpBB Created this page in 0.115035 seconds : 48 queries executed (48.1%): GZIP compression disabled