{
public sealed class Bitmap : Image {
+ # region Static fields
+
+ static readonly image.ColorModel _jpegColorModel = new image.DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
+
+ #endregion
+
#region constructors
Bitmap (PlainImage orig) {
base.Initialize( orig, false );
}
+ [MonoTODO]
private Bitmap (SerializationInfo info, StreamingContext context) {
throw new NotImplementedException ();
}
internal Bitmap (java.awt.Image nativeObject, ImageFormat format)
:base (nativeObject, format) {}
+ [MonoTODO]
private Bitmap (java.awt.Image nativeObject, ImageFormat format, PixelFormat pixFormat)
:this (nativeObject, format) {
if (pixFormat != this.PixelFormat)
public Bitmap (string filename)
:this (filename, false) {}
+ [MonoTODO]
public Bitmap (Stream stream, bool useIcm)
:this (stream, useIcm, null) {}
+ [MonoTODO]
public Bitmap (string filename, bool useIcm)
:this (filename, useIcm, null) {}
}
internal Bitmap (string filename, bool useIcm, ImageFormat format) {
- // TBD: useIcm param
- java.io.File file = vmw.common.IOUtils.getJavaFile (filename);
- if (!file.exists ())
- throw new System.IO.FileNotFoundException (filename);
- Initialize (new stream.FileImageInputStream (file), format);
+ using(FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
+ // TBD: useIcm param
+ io.InputStream jis = vmw.common.IOUtils.ToInputStream (stream);
+ Initialize (new stream.MemoryCacheImageInputStream (jis), format);
+ }
}
public Bitmap (Type type, string resource) {
}
}
#if INTPTR_SUPPORT
+ [MonoTODO]
public Bitmap (int width, int height, int stride, PixelFormat format, IntPtr scan0)
{
throw new NotImplementedException();
catch (Exception) {
throw new OutOfMemoryException ("Out of memory");
}
+ finally {
+ ic.Dispose();
+ }
}
#endregion
protected override void InternalSave (stream.ImageOutputStream output, Guid clsid) {
ImageCodec ic = ImageCodec.CreateWriter( clsid );
+ using (ic) {
+
+ PlainImage plainImage = CurrentImage;
+ plainImage.NativeImage.flush();
+
+ if ( ImageCodec.ClsidToImageFormat( clsid ).Equals( ImageFormat.Jpeg ) ) {
+ image.ColorModel cm = ((image.BufferedImage)CurrentImage.NativeImage).getColorModel();
+ if (cm.hasAlpha()) {
+ if (cm is image.DirectColorModel) {
+ image.Raster raster = ((image.BufferedImage)CurrentImage.NativeImage).getRaster();
+ image.DataBuffer db = raster.getDataBuffer();
+ image.DirectColorModel dcm = (image.DirectColorModel)cm;
+ image.SinglePixelPackedSampleModel jpegSampleModel = new image.SinglePixelPackedSampleModel(
+ db.getDataType(), Width, Height,
+ new int[] {dcm.getRedMask(), dcm.getGreenMask(), dcm.getBlueMask()} );
+
+ image.BufferedImage tb = new image.BufferedImage(
+ _jpegColorModel,
+ image.Raster.createWritableRaster( jpegSampleModel, db, null ),
+ false, null );
- // .net saves in png if cannot find requested encoder. act id 316563
- if (ic == null)
- ic = ImageCodec.CreateWriter( ImageFormat.Png );
+ plainImage = new PlainImage( tb, plainImage.Thumbnails, ImageFormat.Jpeg, plainImage.HorizontalResolution, plainImage.VerticalResolution, plainImage.Dimension );
+ plainImage.NativeMetadata = plainImage.NativeMetadata;
+ }
+ }
+ }
- if (ic != null) {
ic.NativeStream = output;
- ic.WritePlainImage( CurrentImage );
- }
- else {
- throw new NotSupportedException("The requested format encoder is not supported");
+ ic.WritePlainImage( plainImage );
}
}
case PixelFormat.Indexed:
return BufferedImage.TYPE_BYTE_INDEXED;
default:
- return 0;
+ return BufferedImage.TYPE_INT_ARGB;
}
}
public Bitmap Clone (RectangleF rect, PixelFormat pixFormat)
{
- PlainImage plainImage = (PlainImage)CurrentImage.Clone();
- plainImage.NativeImage = ((BufferedImage)plainImage.NativeImage).getSubimage((int)rect.X,(int)rect.Y,(int)rect.Width,(int)rect.Height);
-
- if (pixFormat != this.PixelFormat)
- throw new NotImplementedException ("Converting PixelFormat is not implemented yet.");
-
+ PlainImage plainImage = CurrentImage.Clone(false);
+ BufferedImage clone = new BufferedImage( (int)rect.Width, (int)rect.Height, ToBufferedImageFormat( pixFormat ) );
+ awt.Graphics2D g = clone.createGraphics();
+ try {
+ g.drawImage( NativeObject, -(int)rect.X, -(int)rect.Y, null );
+ }
+ finally {
+ g.dispose();
+ }
+
+ plainImage.NativeImage = clone;
return new Bitmap(plainImage);
}
#endregion
#region LockBits
- // TBD: implement this
+ [MonoTODO]
public BitmapData LockBits (Rectangle rect, ImageLockMode flags, PixelFormat format) {
throw new NotImplementedException();
}
#region MakeTransparent
public void MakeTransparent ()
{
- Color clr = GetPixel(0,0);
+ Color clr = Color.FromArgb(0,0,0);
MakeTransparent (clr);
}
public void MakeTransparent (Color transparentColor)
{
- byte A = transparentColor.A;
image.WritableRaster raster = NativeObject.getRaster();
int numBands = raster.getNumBands();
+ if (numBands != 4)
+ return;
+
int maxWidth = raster.getWidth() + raster.getMinX();
int maxHeight = raster.getHeight() + raster.getMinY();
int[] srcPix = new int[numBands];
for (int y = raster.getMinY(); y < maxHeight; y++) {
for (int x = raster.getMinX(); x < maxWidth; x++) {
/*srcPix =*/ raster.getPixel(x, y, srcPix);
- for (int z = 0; z < numBands; z++) {
- int argb = srcPix[z];
- if ((uint)argb >> 24 == A) {
- argb &= 0x00FFFFFF;
- srcPix[z] = argb;
- }
+ if (srcPix[0] == transparentColor.R &&
+ srcPix[1] == transparentColor.G &&
+ srcPix[2] == transparentColor.B) {
+ srcPix[3] = 0;
+ raster.setPixel(x, y, srcPix);
}
}
}
#endregion
#region UnlockBits
- // TBD: implement this
+ [MonoTODO]
public void UnlockBits (BitmapData bitmap_data)
{
throw new NotImplementedException();
#endregion
#if INTPTR_SUPPORT
+ [MonoTODO]
public static Bitmap FromHicon (IntPtr hicon)
{
throw new NotImplementedException();
}
+ [MonoTODO]
public static Bitmap FromResource (IntPtr hinstance, string bitmapName) //TBD: Untested
{
throw new NotImplementedException();
}
+ [MonoTODO]
public IntPtr GetHbitmap ()
{
throw new NotImplementedException();
}
+ [MonoTODO]
public IntPtr GetHbitmap (Color background)
{
throw new NotImplementedException();
}
+ [MonoTODO]
public IntPtr GetHicon ()
{
throw new NotImplementedException();