November 22, 2017, 12:59:18 AM

Author Topic: Reinit Image  (Read 1287 times)

zerocreativity1

  • Newbie
  • *
  • Posts: 16
    • View Profile
Reinit Image
« on: March 28, 2014, 06:43:49 PM »
I had a case where i need to edit an image after its constructed.  Is there any disadvantages in doing this? If not could a push the code to the HaxePunk Image Class.

public function ReInit(source:Dynamic, clipRect:Rectangle = null, name:String = "")
   {
      init();
      _source = null; _region = null;
      // check if the _source or _region were set in a higher class
      if (_source == null && _region == null)
      {
         _class = name;
         if (Std.is(source, TextureAtlas))
         {
            setAtlasRegion(cast(source, TextureAtlas).getRegion(name));
         }
         else if (Std.is(source, AtlasRegion))
         {
            setAtlasRegion(source);
         }
         else if (Std.is(source, TileAtlas))
         {
            setAtlasRegion(cast(source, TileAtlas).getRegion(0));
         }
         else if (HXP.renderMode == RenderMode.HARDWARE)
         {
            if (Std.is(source, String))
               _class = source;
            else if (name == "")
               _class = Type.getClassName(Type.getClass(source));

            setAtlasRegion(Atlas.loadImageAsRegion(source));
         }
         else if (Std.is(source, BitmapData))
         {
            setBitmapSource(source);
         }
         else
         {
            if (Std.is(source, String))
               _class = source;
            else if (name == "")
               _class = Type.getClassName(Type.getClass(source));

            setBitmapSource(HXP.getBitmap(source));
         }

         if (_source == null && _region == null)
            throw "Invalid source image.";
      }

      if (clipRect != null)
      {
         if (clipRect.width == 0) clipRect.width = _sourceRect.width;
         if (clipRect.height == 0) clipRect.height = _sourceRect.height;
         if (!blit)
         {
            _region = _region.clip(clipRect); // create a new clipped region
         }
         _sourceRect = clipRect;
      }

      if (blit)
      {
         _bitmap = new Bitmap();
         _colorTransform = new ColorTransform();

         createBuffer();
         updateBuffer();
      }
      
   }

ibilon

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 581
    • View Profile
    • My website
Re: Reinit Image
« Reply #1 on: March 29, 2014, 03:14:34 AM »
I don't really see the point, why not create a new image?

zerocreativity1

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Reinit Image
« Reply #2 on: April 02, 2014, 09:49:51 PM »
Basically I made a "CollabImage" Class that inherited from Image. That took multiple images and stuck them together. Both for performance reasons, and because it avoided lines on resize. But i wanted to edit the Image after its been created.

What would be the ideal way of doing something like that?