logo
down
shadow

Using a loop to create multiple childs of the same bitmap (AS3)


Using a loop to create multiple childs of the same bitmap (AS3)

Content Index :

Using a loop to create multiple childs of the same bitmap (AS3)
Tag : actionscript-3 , By : DotNetWise
Date : November 21 2020, 07:35 AM

like below fixes the issue I have a bitmap that I want more than one of at different positions on the stage. I'd guess that this is achievable using a loop but I'm not sure how. , Using a loop to create multiple instances of SpikesImage:
for(var i:int = 0; i < 10; i++)
{
    var spikes:Bitmap = new SpikesImage();
    spikes.x = i * spikes.width;

    addChild(spikes);
}
var screen:Bitmap = new Bitmap();
screen.bitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);

var spikes:Bitmap = new SpikesImage();
var drawPosition:Point = new Point();
var drawRect:Rectangle = spikes.bitmapData.rect;

for(var i:int = 0; i < 10; i++)
{
    drawPosition.x = i * spikes.width;

    screen.bitmapData.copyPixels(
        spikes.bitmapData,
        drawRect,
        drawPosition
    );
}

addChild(screen);

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

how to create a bitmap which is composed multiple images?


Tag : java , By : Boyer C.
Date : March 29 2020, 07:55 AM
may help you . you have two options:
create a relative layout, include 4 images views and set one image to each bitmap that's a bit more complex, use Bitmap.createBitmap(int width, int height, Bitmap.Config config); to create a mutable bitmap with the size you want, create a new canvas with new Canvas(bitmap); to create a canvas into that bitmap, and use canvas.drawBitmap(...) to draw the 4 bitmaps into the final one.

How to create a regex that matches CREATE BITMAP (...); DML in multiple files?


Tag : regex , By : Mena
Date : March 29 2020, 07:55 AM
this will help I have several DDL scripts that contains lines such as this: , To grab the commands which starts with CREATE BITMAP through grep,
$ grep -oPz 'CREATE BITMAP[\S\s]*?;$' file
CREATE BITMAP INDEX MY_SCHEMA.MY_TABLE_BITMAP_INDEX_1
  ON MY_SCHEMA.MY_TABLE (MY_COLUMN2) TABLESPACE MY_TABLESPACE;
-Z, --null                print 0 byte after FILE name
-o, --only-matching       show only the part of a line matching PATTERN
-P, --perl-regexp         PATTERN is a Perl regular expression

Attempting to create Save bitmap funcion for multiple BPP formats


Tag : cpp , By : David
Date : March 29 2020, 07:55 AM
this will help I think there was memory allocation problem for palette images, plus error with header data. This one should work:
BOOL SaveHBitmap(const char* filename, HBITMAP hbitmap, HDC hdc)
{
    BITMAP bitmap;
    if (!GetObject(hbitmap, sizeof(BITMAP), (void*)&bitmap))
        return FALSE;

    // Convert the color format to a count of bits.  
    WORD clrbits = (WORD)(bitmap.bmPlanes * bitmap.bmBitsPixel);
    if (clrbits == 1) clrbits = 1;
    else if (clrbits <= 4)  clrbits = 4;
    else if (clrbits <= 8)  clrbits = 8;
    else if (clrbits <= 16) clrbits = 16;
    else if (clrbits <= 24) clrbits = 24;
    else clrbits = 32;

    //clrUsed is zero for 24 bit and higher
    int clrUsed = (clrbits <= 8) ? (1 << clrbits) : 0;
    TRACE("clrUsed %d\n", clrUsed);

    int bitmapInfoSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * clrUsed;
    PBITMAPINFO bitmapInfo = (PBITMAPINFO)new char[bitmapInfoSize];
    memset(bitmapInfo, 0, bitmapInfoSize);

    // Initialize the fields in the BITMAPINFO structure.  
    bitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bitmapInfo->bmiHeader.biWidth = bitmap.bmWidth;
    bitmapInfo->bmiHeader.biHeight = bitmap.bmHeight;
    bitmapInfo->bmiHeader.biPlanes = bitmap.bmPlanes;
    bitmapInfo->bmiHeader.biBitCount = bitmap.bmBitsPixel;
    bitmapInfo->bmiHeader.biClrUsed = clrUsed;
    bitmapInfo->bmiHeader.biCompression = BI_RGB;

    // Compute the number of bytes in the array of color indices and store the result in biSizeImage.  
    // The width must be DWORD aligned unless the bitmap is RLE compressed. 
    int dibSize = ((bitmap.bmWidth * clrbits + 31) & ~31) / 8 * bitmap.bmHeight;
    char* dib = new char[dibSize];

    bitmapInfo->bmiHeader.biSizeImage = dibSize;

    // Set biClrImportant to 0, indicating that all of the device colors are important.  
    bitmapInfo->bmiHeader.biClrImportant = 0;

    PBITMAPINFOHEADER bmpInfoHeader = (PBITMAPINFOHEADER)bitmapInfo;

    if (!GetDIBits(hdc, hbitmap, 0, bmpInfoHeader->biHeight, dib, bitmapInfo, 0))
    {
        delete bitmapInfo;
        delete[]dib;
        return FALSE;
    }

    BITMAPFILEHEADER bmpFileHeader = { 0 };
    bmpFileHeader.bfType = 0x4d42;
    bmpFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + clrUsed * sizeof(RGBQUAD);
    bmpFileHeader.bfSize = bmpFileHeader.bfOffBits + dibSize;

    HANDLE hfile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hfile != INVALID_HANDLE_VALUE)
    {
        DWORD dwTmp;
        WriteFile(hfile, (void*)&bmpFileHeader, sizeof(BITMAPFILEHEADER), &dwTmp, NULL);
        WriteFile(hfile, (void*)bmpInfoHeader, sizeof(BITMAPINFOHEADER) + clrUsed * sizeof(RGBQUAD), &dwTmp, NULL);
        WriteFile(hfile, (void*)dib, dibSize, &dwTmp, NULL);
        CloseHandle(hfile);
    }

    delete bitmapInfo;
    delete[]dib;

    return TRUE;
}

void foo()
{
    const char* filename = "c:\\test\\test8bit.bmp";

    if (IDOK != ::MessageBox(0, "this will over-write the file", 0, MB_OKCANCEL))
        return;

    HBITMAP hbitmap = (HBITMAP)LoadImage(0, filename, IMAGE_BITMAP, 0, 0,
        LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);
    if (!hbitmap) return;

    //modify hbitmap here
    //...

    HDC hdc = CreateCompatibleDC(0);
    SaveHBitmap(filename, hbitmap, hdc);
    DeleteDC(hdc);

    ShellExecute(0, 0, filename, 0, 0, SW_SHOW);
}

How to do this loop thru all childs and sub childs until no more childs?


Tag : php , By : hellboy32
Date : March 29 2020, 07:55 AM
I wish did fix the issue. This is the best I can help you with, showing how to recurse over simplexml to build a standard array/object structure.
$html = simplexml_load_string( file_get_contents('https://en.wikipedia.org/wiki/HTML5') );

$output = process_html( $html );

print_r($output);

function process_html( SimpleXMLElement $nodes )
{
  $array = array();
  /* @var $node SimpleXMLElement */
  foreach( $nodes as $node )
  {
    $object = new stdClass();
    $object->tag = $node->getName();
    $object->text = trim( (string) $node );
    if( $node->attributes() )
    {
      $object->attributes = new stdClass();
      foreach( $node->attributes() as $attrKey => $attr )
      {
        $object->attributes->{$attrKey} = (string) $attr;
      }
    }
    if( count( $node->children() ) )
    {
      // Here is the recursion
      $object->children = process_html( $node->children() );
    }
    $array[] = $object;
  }
  return $array;
}

Create multiple bitmap image from canvas and print that by using DrawingVisual in wpf C#?


Tag : chash , By : Andrew Bailey
Date : March 29 2020, 07:55 AM
To fix this issue I'm trying to create multiple bitmap image from canvas by doing some alteration and store them into drawing visual control.After that it will go for print in a thermal printer. , Check if it helps:
 public void ConvertCanvasToBitmap_second(Canvas surface)
    {
        //mycanvas.Background = new SolidColorBrush(Colors.White);
        RenderTargetBitmap [] renderTargetBitmaps = new RenderTargetBitmap [2];
        Label lblPagination = new Label
        {
            Name = "lblPagination",
            FontSize = 6
        };
        surface.Children.Add(lblPagination);
        Canvas.SetRight(lblPagination, 0);
        Canvas.SetBottom(lblPagination, 0);
        // Get the size of canvas
        System.Windows.Size size = new System.Windows.Size(surface.Width, surface.Height);
        // Measure and arrange the surface
        // VERY IMPORTANT
        surface.Measure(size);
        surface.Arrange(new Rect(size));
        for (int i = 0; i < 2; i++)
        {
            lblPagination.Content = (i + 1).ToString();
            // Create a render bitmap and push the surface to it
            RenderTargetBitmap renderBitmap =
              new RenderTargetBitmap(
                (int)size.Width,
                (int)size.Height,
                96d,
                96d,
                PixelFormats.Pbgra32);
            renderBitmap.Render(surface);

            renderTargetBitmaps[i] = renderBitmap;
        }


        for (int i = 0; i < renderTargetBitmaps.Length; i++)
        {
            var vis = new DrawingVisual();
            using (var dc = vis.RenderOpen())
            {
                dc.DrawImage(renderTargetBitmaps[i], new Rect(0, 0, (int)size.Width, (int)size.Height));
            }

            PrintDialog printDlg = new PrintDialog();
            printDlg.PrintVisual(vis, "Label Printing.");
        }
    }
Related Posts Related QUESTIONS :
shadow
Privacy Policy - Terms - Contact Us © scrbit.com