[Mono-osx] Save jpg with compression.
GordyGordy
gordontruslove at hotmail.com
Fri Oct 26 15:10:23 UTC 2012
This is my code for saving a jpg with compression. It's pretty simple, just
set the NSImageCompressionFactor apparently.
public void SaveImage(NSImage MyNSImage,string Location, float Quality)
{
NSBitmapImageRep BRep=(NSBitmapImageRep)MyNSIMage.Representations[0];
NSDictionary Dic= NSDictionary.FromObjectAndKey(new
NSNumber(Quality),new NSString("NSImageCompressionFactor"));
NSData
D=BRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Jpeg,Dic);
System.IO.Stream S=D.AsStream();
SaveStream(Location,S);
S.Dispose();
D.Dispose();
}
void SaveStream(string FileName, Stream Source)
{
FileStream FS=File.OpenWrite(FileName);
int Read=0;
byte[] Buffer=new byte[1024];
Source.Seek(0, SeekOrigin.Begin);
do{
Read = Source.Read(Buffer, 0, 1024);
FS.Write(Buffer, 0, Read);
}while(Read>0);
FS.Close();
}
It always saves as 100% though, what am I doing wrong? Hope some clever
person knows the answer.
--
View this message in context: http://mono.1490590.n4.nabble.com/Save-jpg-with-compression-tp4657135.html
Sent from the Mono - OSX mailing list archive at Nabble.com.
More information about the Mono-osx
mailing list