Click here to Skip to main content
16,020,512 members
Home / Discussions / C#
   

C#

 
AnswerRe: TabPage Text Pin
BillWoodruff23-Nov-11 21:18
professionalBillWoodruff23-Nov-11 21:18 
QuestionCan we get A Name for the Row of DataGridView ... Pin
nassimnastaran23-Nov-11 8:48
nassimnastaran23-Nov-11 8:48 
AnswerRe: Can we get A Name for the Row of DataGridView ... Pin
PIEBALDconsult23-Nov-11 9:04
mvePIEBALDconsult23-Nov-11 9:04 
GeneralRe: Can we get A Name for the Row of DataGridView ... Pin
nassimnastaran23-Nov-11 9:36
nassimnastaran23-Nov-11 9:36 
GeneralRe: Can we get A Name for the Row of DataGridView ... Pin
PIEBALDconsult23-Nov-11 10:29
mvePIEBALDconsult23-Nov-11 10:29 
GeneralRe: Can we get A Name for the Row of DataGridView ... Pin
nassimnastaran24-Nov-11 5:28
nassimnastaran24-Nov-11 5:28 
AnswerRe: Can we get A Name for the Row of DataGridView ... Pin
Luc Pattyn23-Nov-11 10:10
sitebuilderLuc Pattyn23-Nov-11 10:10 
Questionc# Convert a large bitmap into jpeg format Pin
mgulde23-Nov-11 8:04
mgulde23-Nov-11 8:04 
Hello all,

I am currently handling very large images, which are basically generated by stitching together many smaller images (e.g. panorama or photo mosaic software). In order to avoid out-of-memory exceptions (in memory are only "maps" of how to arrange the smaller images), I wrote some code saving these images line by line as bitmaps using BinaryWriter and LockBits. So far, so good.

The problem is now that I would like to save these images as Jpegs (or PNGs) as well. Since I am pretty new to c# I can only think of two ways for now:

1) Similar to the bitmap saving procedure. Generating some jpeg header and saving the big images line by line, compressing them somehow before. I have no idea how to perform the compression though.

2) Streaming the already saved bitmap into the memory and saving it as encoded jpeg.

Since the second approach seemed easier, I tried something like this:

C#
FileStream fsr = new FileStream("input.bmp", FileMode.Open, FileAccess.Read);
FileStream fsw = new FileStream("output.jpg", FileMode.CreateNew, FileAccess.Write);

EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80L);

Bitmap bmp = new Bitmap(fsr);
bmp.Save(fsw, GetEncoder(ImageFormat.Jpeg), encoderParameters);

bmp.Dispose();


The problem is now that the save-method tries to completely load the bitmap into memory first, causing an out-of-memory exception.

I would be more than happy for any suggestions on how to solve or circumvent this problem!

Cheers,
Max


Update: I now edited the code so that it saves bands of 8 lines as bmp. These bands I would now like to save to the same jpeg file - any ideas?

modified 24-Nov-11 8:04am.

AnswerRe: c# Convert a large bitmap into jpeg format Pin
darkDercane23-Nov-11 9:00
professionaldarkDercane23-Nov-11 9:00 
AnswerRe: c# Convert a large bitmap into jpeg format Pin
harold aptroot23-Nov-11 9:25
harold aptroot23-Nov-11 9:25 
AnswerRe: c# Convert a large bitmap into jpeg format Pin
Luc Pattyn23-Nov-11 10:17
sitebuilderLuc Pattyn23-Nov-11 10:17 
GeneralRe: c# Convert a large bitmap into jpeg format Pin
mgulde23-Nov-11 22:31
mgulde23-Nov-11 22:31 
GeneralTry/Catch Opinions Pin
mjackson1123-Nov-11 7:08
mjackson1123-Nov-11 7:08 
GeneralRe: Try/Catch Opinions Pin
PIEBALDconsult23-Nov-11 7:16
mvePIEBALDconsult23-Nov-11 7:16 
GeneralRe: Try/Catch Opinions Pin
Not Active23-Nov-11 7:28
mentorNot Active23-Nov-11 7:28 
GeneralRe: Try/Catch Opinions Pin
PIEBALDconsult23-Nov-11 7:37
mvePIEBALDconsult23-Nov-11 7:37 
GeneralRe: Try/Catch Opinions Pin
Not Active23-Nov-11 7:47
mentorNot Active23-Nov-11 7:47 
AnswerRe: Try/Catch Opinions Pin
Eddy Vluggen23-Nov-11 7:45
professionalEddy Vluggen23-Nov-11 7:45 
GeneralRe: Try/Catch Opinions Pin
SledgeHammer0123-Nov-11 7:58
SledgeHammer0123-Nov-11 7:58 
GeneralRe: Try/Catch Opinions Pin
Pete O'Hanlon23-Nov-11 8:37
mvePete O'Hanlon23-Nov-11 8:37 
GeneralRe: Try/Catch Opinions Pin
PIEBALDconsult23-Nov-11 9:09
mvePIEBALDconsult23-Nov-11 9:09 
GeneralRe: Try/Catch Opinions Pin
Pete O'Hanlon23-Nov-11 9:29
mvePete O'Hanlon23-Nov-11 9:29 
AnswerRe: Try/Catch Opinions Pin
Luc Pattyn23-Nov-11 10:26
sitebuilderLuc Pattyn23-Nov-11 10:26 
GeneralRe: Try/Catch Opinions Pin
Pete O'Hanlon23-Nov-11 10:33
mvePete O'Hanlon23-Nov-11 10:33 
GeneralRe: Try/Catch Opinions Pin
Luc Pattyn23-Nov-11 10:56
sitebuilderLuc Pattyn23-Nov-11 10:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.