22using System . Drawing . Imaging ;
33using System . Drawing ;
44using System . IO ;
5+ using System . Drawing . Drawing2D ;
56
67namespace ASPNetImage
78{
@@ -254,6 +255,17 @@ public string Filename
254255 }
255256 }
256257
258+ /// <summary>
259+ /// Gets the classes .NET image instance
260+ /// </summary>
261+ public Image RawNetImage
262+ {
263+ get
264+ {
265+ return this . _image ;
266+ }
267+ }
268+
257269 /// <summary>
258270 /// Gets or sets the image format to be used when saving the image. Not currently
259271 /// supported and only JPG format is output.
@@ -461,10 +473,6 @@ public void Chord(int intX1, int intY1, int intX2, int intY2, int intX3, int int
461473 {
462474 }
463475
464- public void ClearImage ( )
465- {
466- }
467-
468476 public void ClearTexture ( )
469477 {
470478 }
@@ -509,10 +517,6 @@ public void FillPath()
509517 {
510518 }
511519
512- public void FillRect ( int intLeft , int intTop , int intRight , int intBottom )
513- {
514- }
515-
516520 public void FishEye ( int intDegree )
517521 {
518522 }
@@ -532,6 +536,20 @@ public int GetPixel(int intX, int intY)
532536
533537 public void GradientOneWay ( int intBeginColor , int intEndColor , int intDirection )
534538 {
539+ //Graphics graphicsDest = Graphics.FromImage(this._image);
540+ //LinearGradientBrush thisBrush;
541+
542+ //switch (intDirection)
543+ //{
544+ // case 0:
545+ // // up
546+ // thisBrush = new LinearGradientBrush(
547+ // new Point(this._image.Width / 2, this._image.Height - 1),
548+ // new Point(this._image.Width / 2, 0),
549+ // Color.FromArgb(intBeginColor),
550+ // Color.FromArgb(intEndColor));
551+
552+ //}
535553 }
536554
537555 public void GradientTwoWay ( int intBeginColor , int intEndColor , int intDirection , int intInOut )
@@ -670,6 +688,22 @@ public void Wave(int intGraphicSize, int intWaveSize)
670688
671689 #endregion
672690
691+ /// <summary>
692+ /// Clears the entire image with the current BackgroundColor
693+ /// </summary>
694+ public void ClearImage ( )
695+ {
696+ Graphics graphicsDest = Graphics . FromImage ( this . _image ) ;
697+ graphicsDest . CompositingMode = System . Drawing . Drawing2D . CompositingMode . SourceCopy ;
698+ Color brushColor = Color . FromArgb ( this . BackgroundColor ) ;
699+ Brush coloredBrush = new SolidBrush ( brushColor ) ;
700+ graphicsDest . FillRectangle ( coloredBrush , 0 , 0 , this . _image . Width , this . _image . Height ) ;
701+ graphicsDest . DrawImage ( this . _image , 0 , 0 ) ;
702+
703+ graphicsDest . Dispose ( ) ;
704+ coloredBrush . Dispose ( ) ;
705+ }
706+
673707 /// <summary>
674708 /// Crops the image with the specified dimensions
675709 /// </summary>
@@ -690,6 +724,26 @@ public void CropImage(int startX, int startY, int width, int height)
690724 graphicsCrop . Dispose ( ) ;
691725 }
692726
727+ /// <summary>
728+ /// Fills the specified rectangle with the current PenColor
729+ /// </summary>
730+ /// <param name="intLeft"></param>
731+ /// <param name="intTop"></param>
732+ /// <param name="intRight"></param>
733+ /// <param name="intBottom"></param>
734+ public void FillRect ( int intLeft , int intTop , int intRight , int intBottom )
735+ {
736+ Graphics graphicsDest = Graphics . FromImage ( this . _image ) ;
737+ graphicsDest . CompositingMode = System . Drawing . Drawing2D . CompositingMode . SourceCopy ;
738+ Color brushColor = Color . FromArgb ( this . PenColor ) ;
739+ Brush coloredBrush = new SolidBrush ( brushColor ) ;
740+ graphicsDest . FillRectangle ( coloredBrush , intLeft , intTop , intRight - intLeft , intBottom - intTop ) ;
741+ graphicsDest . DrawImage ( this . _image , 0 , 0 ) ;
742+
743+ graphicsDest . Dispose ( ) ;
744+ coloredBrush . Dispose ( ) ;
745+ }
746+
693747 /// <summary>
694748 /// Flips the image vertically (intDirection == 2) or horizontally (intDirection == 1)
695749 /// </summary>
@@ -893,18 +947,76 @@ public bool SaveImage()
893947 EncoderParameter imageEncoderParameter ;
894948 EncoderParameters imageEncoderParameters ;
895949
896- imageCodecInfo = GetEncoderInfo ( "image/jpeg" ) ;
897- imageEncoder = Encoder . Quality ;
898- imageEncoderParameters = new EncoderParameters ( 1 ) ;
899- imageEncoderParameter = new EncoderParameter ( imageEncoder , this . JPEGQuality ) ;
900- imageEncoderParameters . Param [ 0 ] = imageEncoderParameter ;
950+ switch ( this . ImageFormat )
951+ {
952+ case ImageFormats . BMP :
953+
954+ this . Filename = Path . ChangeExtension ( this . Filename , "bmp" ) ;
955+
956+ try
957+ {
958+ this . _image . Save ( this . Filename , System . Drawing . Imaging . ImageFormat . Bmp ) ;
959+ }
960+ catch ( Exception e )
961+ {
962+ this . _error = e . ToString ( ) ;
963+ }
964+ break ;
965+
966+ case ImageFormats . GIF :
967+
968+ this . Filename = Path . ChangeExtension ( this . Filename , "gif" ) ;
969+
970+ try
971+ {
972+ this . _image . Save ( this . Filename , System . Drawing . Imaging . ImageFormat . Gif ) ;
973+ }
974+ catch ( Exception e )
975+ {
976+ this . _error = e . ToString ( ) ;
977+ }
978+ break ;
979+
980+ case ImageFormats . PNG :
981+
982+ this . Filename = Path . ChangeExtension ( this . Filename , "png" ) ;
983+
984+ try
985+ {
986+ this . _image . Save ( this . Filename , System . Drawing . Imaging . ImageFormat . Png ) ;
987+ }
988+ catch ( Exception e )
989+ {
990+ this . _error = e . ToString ( ) ;
991+ }
992+
993+ break ;
994+
995+ case ImageFormats . JPEG :
996+ default :
901997
902- this . Filename = Path . ChangeExtension ( this . Filename , "jpg" ) ;
998+ imageCodecInfo = GetEncoderInfo ( "image/jpeg" ) ;
999+ imageEncoder = Encoder . Quality ;
1000+ imageEncoderParameters = new EncoderParameters ( 1 ) ;
1001+ imageEncoderParameter = new EncoderParameter ( imageEncoder , this . JPEGQuality ) ;
1002+ imageEncoderParameters . Param [ 0 ] = imageEncoderParameter ;
1003+
1004+ this . Filename = Path . ChangeExtension ( this . Filename , "jpg" ) ;
1005+
1006+ try
1007+ {
1008+ this . _image . Save ( this . Filename , imageCodecInfo , imageEncoderParameters ) ;
1009+ }
1010+ catch ( Exception e )
1011+ {
1012+ this . _error = e . ToString ( ) ;
1013+ }
1014+
1015+ break ;
1016+ }
9031017
9041018 try
9051019 {
906- this . _image . Save ( this . Filename , imageCodecInfo , imageEncoderParameters ) ;
907-
9081020 if ( File . Exists ( this . Filename ) )
9091021 {
9101022 if ( this . AutoClear )
0 commit comments