Search Results

Search found 118 results on 5 pages for 'bitmapdata'.

Page 2/5 | < Previous Page | 1 2 3 4 5  | Next Page >

  • AS3 How to check on non transparent pixels in a bitmapdata?

    - by Opoe
    I'm still working on my window cleaning game from one of my previous questions I marked a contribution as my answer, but after all this time I can't get it to work and I have to many questions about this so I decided to ask some more about it. As a sequel on my mentioned previous question, my question to you is: How can I check whether or not a bitmapData contains non transparent pixels? Subquestion: Is this possible when the masked image is a movieclip? Shouldn't I use graphics instead? Information I have: A dirtywindow movieclip on the bottom layer and a clean window movieclip on layer 2(mc1) on the layer above. To hide the top layer(the dirty window) I assign a mask to it. Code // this creates a mask that hides the movieclip on top var mask_mc:MovieClip = new MovieClip(); addChild(mask_mc) //assign the mask to the movieclip it should 'cover' mc1.mask = mask_mc; With a brush(cursor) the player wipes of the dirt ( actualy setting the fill from the mask to transparent so the clean window appears) //add event listeners for the 'brush' brush_mc.addEventListener(MouseEvent.MOUSE_DOWN,brushDown); brush_mc.addEventListener(MouseEvent.MOUSE_UP,brushUp); //function to drag the brush over the mask function brushDown(dragging:MouseEvent):void{ dragging.currentTarget.startDrag(); MovieClip(dragging.currentTarget).addEventListener(Event.ENTER_FRAME,erase) ; mask_mc.graphics.moveTo(brush_mc.x,brush_mc.y); } //function to stop dragging the brush over the mask function brushUp(dragging:MouseEvent):void{ dragging.currentTarget.stopDrag(); MovieClip(dragging.currentTarget).removeEventListener(Event.ENTER_FRAME,erase); } //fill the mask with transparant pixels so the movieclip turns visible function erase(e:Event):void{ with(mask_mc.graphics){ beginFill(0x000000); drawRect(brush_mc.x,brush_mc.y,brush_mc.width,brush_mc.height); endFill(); } }

    Read the article

  • Comparing bitmap data in AS3 pixel for pixel

    - by Jono
    Hi, I am looking for a fairly simple image comparison method in AS3. I have taken an image from a web cam (with no subject) passed it in to bitmap data, then a second image is taken (this time with a subject) to compare this data, from these two images I would like to create a mask from the pixels that match on both bitmaps. I have been scratching my head for a while, and I am not really making any progress. Could any one point me in the right direction for pixel comparison method, something like getPixel32() Cheers Jono

    Read the article

  • bitmap data as movie clip

    - by Ross
    Hi, I import my images with imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete); imageLoader.load(imageRequest); and then try and cast as a movieclip: var newImage:MovieClip = imageLoader.content as MovieClip; addChild(newImage); i keep getting errors, is this possible? Thanks, Ross

    Read the article

  • Creating Bitmaps from ARGB strings (in actionscript-3)???

    - by ashenwraith
    Hi, in actionscript 3, what's the fastest way to dump your data (not from a file) into a bitmap for display? I have it working with setPixels and colored rects but that's way too slow/inefficient. Is there a way to load in the raw bytes or hijack the loader class to put in custom loader data? What would be the best/fastest--should I start writing a byte encoder?

    Read the article

  • How do I replace colours in a movieclip?

    - by Oli
    I am trying to take a movieclip of a character and change the colour of their clothes. The character is comprised of vectors. So far I have semi-sucessfully used this method: stop the movieclip take the bitmap data from the current frame use threshold to replace the colour store the resulting bitmap data in an array add an onenterframe function - clear the current frame and add the bitmap data from the processed data in the array So - this works pretty well. Each frame is only processed once at the beginning and then the write to the movieclip is very quick. However! As the replacement is being performed on a bitmap there is an amount of aliasing that takes place to remove jaggies/pixelation. This produces colours that are not matched using threshold. So the main colour is replaced correctly but it is surrounded by a halo of mixed colours :( I am sure there should be a better way to do this. Any ideas or answers would be greatly apreciated - Thanks.

    Read the article

  • Replacing a colour/colours in a movieclip with different colours?

    - by Oli
    I am trying to take a movieclip of a character and change the colour of their clothes. The character is comprised of vectors. So far I have semi-sucessfully used this method: stop the movieclip take the bitmap data from the current frame use threshold to replace the colour store the resulting bitmap data in an array add an onenterframe function - clear the current frame and add the bitmap data from the processed data in the array So - this works pretty well. Each frame is only processed once at the beginning and then the write to the movieclip is very quick. However! As the replacement is being performed on a bitmap there is an amount of aliasing that takes place to remove jaggies/pixelation. This produces colours that are not matched using threshold. So the main colour is replaced correctly but it is surrounded by a halo of mixed colours :( I am sure there should be a better way to do this. Any ideas or answers would be greatly apreciated - Thanks.

    Read the article

  • .net bitmap file type limitations

    - by David Archer
    Hi, Given the line: Bitmap bitmap = new Bitmap(stream); where stream is a System.IO.Stream, are there any limitations on the image file type e.g png, jpg, gif etc that can be handled. i.e are all image file/stream header info clear enough to say "I am an image". I haven't run into any yet, but have only being using the pretty standard ones so far. Thanks

    Read the article

  • image with external interface

    - by Leo
    I need to send a picture to flash with external interface (as3)... can not be an url because don't have connection... I'm trying open the image file and send to flash like text but without success any idea?

    Read the article

  • Animating Tile with Blitting taking up Memory.

    - by Kid
    I am trying to animate a specific tile in my 2d Array, using blitting. The animation consists of three different 16x16 sprites in a tilesheet. Now that works perfect with the code below. BUT it's causing memory leakage. Every second the FlashPlayer is taking up +140 kb more in memory. What part of the following code could possibly cause the leak: //The variable Rectangle finds where on the 2d array we should clear the pixels //Fillrect follows up by setting alpha 0 at that spot before we copy in nxt Sprite //Tiletype is a variable that holds what kind of tile the next tile in animation is //(from tileSheet) //drawTile() gets Sprite from tilesheet and copyPixels it into right position on canvas public function animateSprite():void{ tileGround.bitmapData.lock(); if(anmArray[0].tileType > 42){ anmArray[0].tileType = 40; frameCount = 0; } var rect:Rectangle = new Rectangle(anmArray[0].xtile * ts, anmArray[0].ytile * ts, ts, ts); tileGround.bitmapData.fillRect(rect, 0); anmArray[0].tileType = 40 + frameCount; drawTile(anmArray[0].tileType, anmArray[0].xtile, anmArray[0].ytile); frameCount++; tileGround.bitmapData.unlock(); } public function drawTile(spriteType:int, xt:int, yt:int):void{ var tileSprite:Bitmap = getImageFromSheet(spriteType, ts); var rec:Rectangle = new Rectangle(0, 0, ts, ts); var pt:Point = new Point(xt * ts, yt * ts); tileGround.bitmapData.copyPixels(tileSprite.bitmapData, rec, pt, null, null, true); } public function getImageFromSheet(spriteType:int, size:int):Bitmap{ var sheetColumns:int = tSheet.width/ts; var col:int = spriteType % sheetColumns; var row:int = Math.floor(spriteType/sheetColumns); var rec:Rectangle = new Rectangle(col * ts, row * ts, size, size); var pt:Point = new Point(0,0); var correctTile:Bitmap = new Bitmap(new BitmapData(size, size, false, 0)); correctTile.bitmapData.copyPixels(tSheet, rec, pt, null, null, true); return correctTile; }

    Read the article

  • AS3 - At exactly 23 empty alpha channels, images below stop drawing

    - by user46851
    I noticed, while trying to draw large numbers of circles, that occasionally, there would be some kind of visual bug where some circles wouldn't draw properly. Well, I narrowed it down, and have noticed that if there is 23 or more objects with 00 for an alpha value on the same spot, then the objects below don't draw. It appears to be on a pixel-by-pixel basis, since parts of the image still draw. Originally, this problem was noticed with a class that inherited Sprite. It was confirmed to also be a problem with Sprites, and now Bitmaps, too. If anyone can find a lower-level class than Bitmap which doesn't have this problem, please speak up so we can try to find the origin of the problem. I prepared a small test class that demonstrates what I mean. You can change the integer value at line 20 in order to see the three tests I came up with to clearly show the problem. Is there any kind of workaround, or is this just a limit that I have to work with? Has anyone experienced this before? Is it possible I'm doing something wrong, despite the bare-bones implementation? package { import flash.display.Sprite; import flash.events.Event; import flash.display.Bitmap; import flash.display.BitmapData; public class Main extends Sprite { public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); // entry point Test(3); } private function Test(testInt:int):void { if(testInt==1){ addChild(new Bitmap(new BitmapData(200, 200, true, 0xFFFF0000))); for (var i:int = 0; i < 22; i++) { addChild(new Bitmap(new BitmapData(100, 100, true, 0x00000000))); } } if(testInt==2){ addChild(new Bitmap(new BitmapData(200, 200, true, 0xFFFF0000))); for (var j:int = 0; j < 23; j++) { addChild(new Bitmap(new BitmapData(100, 100, true, 0x00000000))); } } if(testInt==3){ addChild(new Bitmap(new BitmapData(200, 200, true, 0xFFFF0000))); for (var k:int = 0; k < 22; k++) { addChild(new Bitmap(new BitmapData(100, 100, true, 0x00000000))); } var M:Bitmap = new Bitmap(new BitmapData(100, 100, true, 0x00000000)); M.x += 50; M.y += 50; addChild(M); } } } }

    Read the article

  • CGContextDrawPDFPage doesn't seem to persist in CGContext

    - by erichf
    I am trying to access the pixels of a CGContext written to with a PDF, but the bitmap buffer doesn't seem to update. Any help would be appreciated: //Get the reference to our current page pageRef = CGPDFDocumentGetPage(docRef, iCurrentPage); //Start with a media crop, but see if we can shrink to smaller crop CGRect pdfRect1 = CGRectIntegral(CGPDFPageGetBoxRect(pageRef, kCGPDFMediaBox)); CGRect r1 = CGRectIntegral(CGPDFPageGetBoxRect(pageRef, kCGPDFCropBox)); if (!CGRectIsEmpty(r1)) pdfRect1 = r1; int wide = pdfRect1.size.width + pdfRect1.origin.x; int high = pdfRect1.size.height + pdfRect1.origin.y; CGContextRef ctxBuffer = NULL; CGColorSpaceRef colorSpace; UInt8* bitmapData; int bitmapByteCount; int bitmapBytesPerRow; bitmapBytesPerRow = (wide * 4); bitmapByteCount = (bitmapBytesPerRow * high); colorSpace = CGColorSpaceCreateDeviceRGB(); bitmapData = malloc( bitmapByteCount ); if (bitmapData == NULL) { DebugLog (@"Memory not allocated!"); return; } ctxBuffer = CGBitmapContextCreate (bitmapData, wide, high, 8, // bits per component bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); // if (ctxBuffer== NULL) { free (bitmapData); DebugLog (@"Context not created!"); return; } CGColorSpaceRelease( colorSpace ); //White out the current context CGContextSetRGBFillColor(ctxBuffer, 1.0, 1.0, 1.0, 1.0); CGContextFillRect(ctxBuffer, CGContextGetClipBoundingBox(ctxBuffer)); CGContextDrawPDFPage(ctxBuffer, pageRef); //!!!This displays just fine to the context passed in from - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx. That is, I can see the PDf page rendered, so we know ctxBuffer was created correctly //However, if I view bitmapData in memory, it only shows as 0xFF (or whatever fill color I use) CGImageRef img = CGBitmapContextCreateImage(ctxBuffer); CGContextDrawImage(ctx, tiledLayer.frame, img); void *data = CGBitmapContextGetData (ctx); for (int i = 0; i < wide; i++) { for (int j = 0; j < high; j++) { //All of the bytes show as 0xFF (or whatever fill color I test with)?! int byteIndex = (j * 4) + i * 4; UInt8 red = bitmapData[byteIndex]; UInt8 green = bitmapData[byteIndex + 1]; UInt8 blue = bitmapData[byteIndex + 2]; UInt8 alpha = m_PixelBuf[byteIndex + 3]; } } I have also tried using CGDataProviderCopyData(CGImageGetDataProvider(img)) & CFDataGetBytePtr, but the results are the same?

    Read the article

  • Flash AS3 blur or liquify part of an image with mouse

    - by hamlet
    Hi, I am very beginner in flash. I want to load an image, show a cursor over the image and on mousedown I want to blur that actual part of the image. (e.g you can blur your face on the image and then save the new image). I can delete parts of the image with white line, but I would like to blur it instead // LIVE JPEG ENCODER 0.3 // from bytearray.org import asfiles.encoding.JPEGEncoder; import flash.external.ExternalInterface; ExternalInterface.addCallback("flash_saveImage", inflash_saveImage); var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleComplete); loader.load(new URLRequest(loaderInfo.parameters._filename)); //loader.load(new URLRequest("b.jpg")); var container_mc:MovieClip = new MovieClip;//create movieclip function handleComplete(e:Event):void { addChild(container_mc); var bitmapData:BitmapData = Bitmap(e.target.content).bitmapData; var matrix:Matrix = new Matrix(); container_mc.graphics.clear(); container_mc.graphics.beginBitmapFill(bitmapData, matrix, false); //container_mc.graphics.beginFill(0xFFFFFF,0); container_mc.graphics.drawRect(0, 0, bitmapData.width, bitmapData.height); container_mc.graphics.endFill(); swapChildren(container_mc, pencil); container_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing); container_mc.addEventListener(MouseEvent.MOUSE_UP, stopDrawing); container_mc.addEventListener(MouseEvent.MOUSE_MOVE, makeLine); } stage.addEventListener(MouseEvent.MOUSE_MOVE, moveCursor); Mouse.hide(); function moveCursor(event:MouseEvent):void { pencil.x = event.stageX; pencil.y = event.stageY; } function startDrawing(event:MouseEvent):void{ container_mc.graphics.lineStyle(20, 0xFFFFFF, 1); container_mc.graphics.moveTo(mouseX, mouseY); container_mc.addEventListener(MouseEvent.MOUSE_MOVE, makeLine); } function stopDrawing(event:MouseEvent):void{ container_mc.removeEventListener(MouseEvent.MOUSE_MOVE, makeLine); } function makeLine(event:MouseEvent):void{ container_mc.graphics.lineTo(mouseX, mouseY); } function inflash_saveImage ( ):void { var myURLLoader:URLLoader = new URLLoader(); var myBitmapSource:BitmapData = new BitmapData ( container_mc.width, container_mc.height ); // render the player as a bitmapdata myBitmapSource.draw ( container_mc ); // create the encoder with the appropriate quality var myEncoder:JPEGEncoder = new JPEGEncoder( 80 ); // generate a JPG binary stream to have a preview var myCapStream:ByteArray = myEncoder.encode ( myBitmapSource ); var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream"); var myRequest:URLRequest = new URLRequest ( "save.php" ); myRequest.requestHeaders.push (header); myRequest.method = URLRequestMethod.POST; myRequest.data = myCapStream; myURLLoader.load ( myRequest ); } Thanks, hamlet

    Read the article

  • Print a bitmap without printing a sprite?

    - by Carlos Barbosa
    Following up from: http://stackoverflow.com/questions/3021557/as3-printing-problem-blanks-swf-after-print-or-cancel I am trying to comeup with a function to print without creating a sprite, because that's what it seems to be causing my problem: public function printScreen():void { var pJob:PrintJob = new PrintJob(); var options:PrintJobOptions = new PrintJobOptions(); options.printAsBitmap = true; var bitmapData:BitmapData = new BitmapData(root.width, root.height); bitmapData.draw(root); var printThis:Bitmap = new Bitmap(bitmapData); try { pJob.start(); pJob.addPage(printThis, null, options); pJob.send(); } catch(e:Error) { trace("Error Printing") } } This is coming up with an: Error: Description Implicit coercion of a value of type flash.display:Bitmap to an unrelated type flash.display:Sprite. So how do you print a bitmap without creating a Sprite?

    Read the article

  • What is wrong with my JPGEncoder

    - by hitek
    Here is my code if (event.target.content is Bitmap) { infotext.text = "got something"; var image:Bitmap = Bitmap(event.target.content); var bitmapData:BitmapData = image.bitmapData; this.addChild(image); var j:JPGEncoder = new JPGEncoder(100); var bytes:ByteArray = new ByteArray(); bytes=j.encode(bitmapData); } else { throw new Error("What the heck bob?"); } When I run a debug session everything works fine till it reaches to the line bytes=j.encode(bitmapData); after that nothing happens and my program just goes into limbo Please help

    Read the article

  • Search BitmapData object for matching pixel values from another Bitmap.

    - by Cos
    Using Actionscript 3 is there a way to search one bitmap for the coordinates matching pixels of another bitmap? http://dl.dropbox.com/u/1914/wired.png Somehow you would have to loop through the bigger bitmap to find and the the pixel range that matches and return those coordinates. For example the Bitmap with the "E" is 250 pixels over and 14 pixels down in the bigger bitmap. I haven't been able to come up with the solution on my own. Thanks.

    Read the article

  • Flash as3 smooth threshold

    - by arkzai
    hello, I'm building a flash app that pulls images from flickr and removes the white background I'm dong this using threshold and i get a really ragged outcome is there any way to get a better and smoother color key? thanks photoNumber = Math.floor(Math.random() * (photos.length)); loader.load(new URLRequest(photos[photoNumber].path)); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,draw); trace ( "trying to load photo " + photoNumber ); function draw(e:Event) { trace ("show photo " + photoNumber) var W:int=e.target.content.width; var H:int=e.target.content.height; bitmapdata=new BitmapData(W,H); bitmap=new Bitmap(bitmapdata); bitmapdata.draw(e.target.content); var threshold:uint = 0xF9F8F800; var color:uint = 0x00000000; var maskColor:uint = 0x00FF0000; bitmapdata.threshold(bitmapdata,new Rectangle(0,0,W,H),new Point(0,0),">", threshold, color, maskColor, true); bitmap.smoothing = true; //bitmap.scaleX = bitmap.scaleY = 0.99; // <---- imgHolder.addChild(bitmap); } }

    Read the article

  • How to implement line of sight restriction in actionscript?

    - by Michiel Standaert
    I have a problem with a game i am programming. I am making some sort of security game and i would like to have some visual line of sight. The problem is that i can't restrict my line of sight so my cops can't see through the walls. Below you find the design, in which they can look through windows, but not walls. Further below you find an illustration of what my problem is exactly. this is what it looks like now. As you can see, the cops can see through walls. This is the map i would want to use to restrict the line of sight. So the way i am programming the line of sight now is just by calculating some points and drawing the sight accordingly, as shown below. Note that i also check for a hittest using bitmapdata to check whether or not my player has been spotted by any of the cops. private function setSight(e:Event=null):Boolean { g = copCanvas.graphics; g.clear(); for each(var cop:Cop in copCanvas.getChildren()) { var _angle:Number = cop.angle; var _radians:Number = (_angle * Math.PI) / 180; var _radius:Number = 50; var _x1:Number = cop.x + (cop.width/2); var _y1:Number = cop.y + (cop.height/2); var _baseX:Number = _x1 + (Math.cos(_radians) * _radius); var _baseY:Number = _y1 - (Math.sin(_radians) * _radius); var _x2:Number = _baseX + (25 * Math.sin(_radians)); var _y2:Number = _baseY + (25 * Math.cos(_radians)); var _x3:Number = _baseX - (25 * Math.sin(_radians)); var _y3:Number = _baseY - (25 * Math.cos(_radians)); g.beginFill(0xff0000, 0.3); g.moveTo(_x1, _y1); g.lineTo(_x2, _y2); g.lineTo(_x3, _y3); g.endFill(); } var _cops:BitmapData = new BitmapData(width, height, true, 0); _cops.draw(copCanvas); var _bmpd:BitmapData = new BitmapData(10, 10, true, 0); _bmpd.draw(me); if(_cops.hitTest(new Point(0, 0), 10, _bmpd, new Point(me.x, me.y), 255)) { gameover.alpha = 1; setTimeout(function():void{ gameover.alpha = 0; }, 5000); stop(); return true; } return false; } So now my question is: Is there someone who knows how to restrict the view so that the cops can't look through the walls? Thanks a lot in advance. ps: i have already looked at this tutorial by emanuele feronato, but i can't use the code to restric the visual line of sight.

    Read the article

  • unsigned char* buffer (FreeType2 Bitmap) to System::Drawing::Bitmap.

    - by Dennis Roche
    Hi, I'm trying to convert a FreeType2 bitmap to a System::Drawing::Bitmap in C++/CLI. FT_Bitmap has a unsigned char* buffer that contains the data to write. I have got somewhat working save it disk as a *.tga, but when saving as *.bmp it renders incorrectly. I believe that the size of byte[] is incorrect and that my data is truncated. Any hints/tips/ideas on what is going on here would be greatly appreciated. Links to articles explaining byte layout and pixel formats etc. would be helpful. Thanks!! C++/CLI code. FT_Bitmap *bitmap = &face->glyph->bitmap; int width = (face->bitmap->metrics.width / 64); int height = (face->bitmap->metrics.height / 64); // must be aligned on a 32 bit boundary or 4 bytes int depth = 8; int stride = ((width * depth + 31) & ~31) >> 3; int bytes = (int)(stride * height); // as *.tga void *buffer = bytes ? malloc(bytes) : NULL; if (buffer) { memset(buffer, 0, bytes); for (int i = 0; i < glyph->rows; ++i) memcpy((char *)buffer + (i * width), glyph->buffer + (i * glyph->pitch), glyph->pitch); WriteTGA("Test.tga", buffer, width, height); } // as *.bmp array<Byte>^ values = gcnew array<Byte>(bytes); Marshal::Copy((IntPtr)glyph->buffer, values, 0, bytes); Bitmap^ systemBitmap = gcnew Bitmap(width, height, PixelFormat::Format24bppRgb); // create bitmap data, lock pixels to be written. BitmapData^ bitmapData = systemBitmap->LockBits(Rectangle(0, 0, width, height), ImageLockMode::WriteOnly, bitmap->PixelFormat); Marshal::Copy(values, 0, bitmapData->Scan0, bytes); systemBitmap->UnlockBits(bitmapData); systemBitmap->Save("Test.bmp"); Reference, FT_Bitmap typedef struct FT_Bitmap_ { int rows; int width; int pitch; unsigned char* buffer; short num_grays; char pixel_mode; char palette_mode; void* palette; } FT_Bitmap; Reference, WriteTGA bool WriteTGA(const char *filename, void *pxl, uint16 width, uint16 height) { FILE *fp = NULL; fopen_s(&fp, filename, "wb"); if (fp) { TGAHeader header; memset(&header, 0, sizeof(TGAHeader)); header.imageType = 3; header.width = width; header.height = height; header.depth = 8; header.descriptor = 0x20; fwrite(&header, sizeof(header), 1, fp); fwrite(pxl, sizeof(uint8) * width * height, 1, fp); fclose(fp); return true; } return false; } Update FT_Bitmap *bitmap = &face->glyph->bitmap; // stride must be aligned on a 32 bit boundary or 4 bytes int depth = 8; int stride = ((width * depth + 31) & ~31) >> 3; int bytes = (int)(stride * height); target = gcnew Bitmap(width, height, PixelFormat::Format8bppIndexed); // create bitmap data, lock pixels to be written. BitmapData^ bitmapData = target->LockBits(Rectangle(0, 0, width, height), ImageLockMode::WriteOnly, target->PixelFormat); array<Byte>^ values = gcnew array<Byte>(bytes); Marshal::Copy((IntPtr)bitmap->buffer, values, 0, bytes); Marshal::Copy(values, 0, bitmapData->Scan0, bytes); target->UnlockBits(bitmapData);

    Read the article

  • mapping rect in small image to larger image (in order to do a copyPixels operation)

    - by skinnyTOD
    Hi all - this is (I think) a relatively simple math question but I've spent a day banging my head against it and have only the dents and no solution... I'm coding in actionscript 3 - the functionality is: large image loaded at runtime. The bitmapData is stored and a smaller version is created to display on the available screen area (I may end up just scaling the large image since it is in memory anyway). The user can create a rectangle hotspot on the smaller image (the functionality will be more complex: multiple rects with transparency: example a donut shape with hole, etc) 3 When the user clicks on the hotspot, the rect of the hotspot is mapped to the larger image and a new bitmap "callout" is created, using the larger bitmap data. The reason for this is so the "callout" will be better quality than just scaling up the area of the hotspot. The image below shows where I am at so far- the blue rect is the clicked hotspot. In the upper left is the "callout" - copied from the larger image. I have the aspect ratio right but I am not mapping to the larger image correctly. Ugly code below... Sorry this post is so long - I just figured I ought to provide as much info as possible. Thanks for any tips! --trace of my data values *source BitmapDada 1152 864 scaled to rect 800 600 scaled BitmapData 800 600 selection BitmapData 58 56 scaled selection 83 80 ratio 1.44 before (x=544, y=237, w=58, h=56) (x=544, y=237, w=225.04, h=217.28) * Image here: http://i795.photobucket.com/albums/yy237/skinnyTOD/exampleST.jpg public function onExpandCallout(event:MouseEvent):void{ if (maskBitmapData.getPixel32(event.localX, event.localY) != 0){ var maskClone:BitmapData = maskBitmapData.clone(); //amount to scale callout - this will vary/can be changed by user var scale:Number =150 //scale percentage var normalizedScale :Number = scale/=100; var w:Number = maskBitmapData.width*normalizedScale; var h:Number = maskBitmapData.height*normalizedScale; var ratio:Number = (sourceBD.width /targetRect.width); //creat bmpd of the scaled size to copy source into var scaledBitmapData:BitmapData = new BitmapData(maskBitmapData.width * ratio, maskBitmapData.height * ratio, true, 0xFFFFFFFF); trace("source BitmapDada " + sourceBD.width, sourceBD.height); trace("scaled to rect " + targetRect.width, targetRect.height); trace("scaled BitmapData", bkgnImageSprite.width, bkgnImageSprite.height); trace("selection BitmapData", maskBitmapData.width, maskBitmapData.height); trace("scaled selection", scaledBitmapData.width, scaledBitmapData.height); trace("ratio", ratio); var scaledBitmap:Bitmap = new Bitmap(scaledBitmapData); var scaleW:Number = sourceBD.width / scaledBitmapData.width; var scaleH:Number = sourceBD.height / scaledBitmapData.height; var scaleMatrix:Matrix = new Matrix(); scaleMatrix.scale(ratio,ratio); var sRect:Rectangle = maskSprite.getBounds(bkgnImageSprite); var sR:Rectangle = sRect.clone(); var ss:Sprite = new Sprite(); ss.graphics.lineStyle(8, 0x0000FF); //ss.graphics.beginFill(0x000000, 1); ss.graphics.drawRect(sRect.x, sRect.y, sRect.width, sRect.height); //ss.graphics.endFill(); this.addChild(ss); trace("before " + sRect); w = uint(sRect.width * scaleW); h = uint(sRect.height * scaleH); sRect.inflate(maskBitmapData.width * ratio, maskBitmapData.height * ratio); sRect.offset(maskBitmapData.width * ratio, maskBitmapData.height * ratio); trace(sRect); scaledBitmapData.copyPixels(sourceBD, sRect, new Point()); addChild(scaledBitmap); scaledBitmap.x = offsetPt.x; scaledBitmap.y = offsetPt.y; } }

    Read the article

  • actionscript3: reflect-class applied on rotationY

    - by algro
    Hi, I'm using a class which applies a visual reflection-effect to defined movieclips. I use a reflection-class from here: link to source. It works like a charm except when I apply a rotation to the movieclip. In my case the reflection is still visible but only a part of it. What am I doing wrong? How could I pass/include the rotation to the Reflection-Class ? Thanks in advance! This is how you apply the Reflection Class to your movieclip: var ref_mc:MovieClip = new MoviClip(); addChild(ref_mc); var r1:Reflect = new Reflect({mc:ref_mc, alpha:50, ratio:50,distance:0, updateTime:0,reflectionDropoff:1}); Now I apply a rotation to my movieclip: ref_mc.rotationY = 30; And Here the Reflect-Class: package com.pixelfumes.reflect{ import flash.display.MovieClip; import flash.display.DisplayObject; import flash.display.BitmapData; import flash.display.Bitmap; import flash.geom.Matrix; import flash.display.GradientType; import flash.display.SpreadMethod; import flash.utils.setInterval; import flash.utils.clearInterval; public class Reflect extends MovieClip{ //Created By Ben Pritchard of Pixelfumes 2007 //Thanks to Mim, Jasper, Jason Merrill and all the others who //have contributed to the improvement of this class //static var for the version of this class private static var VERSION:String = "4.0"; //reference to the movie clip we are reflecting private var mc:MovieClip; //the BitmapData object that will hold a visual copy of the mc private var mcBMP:BitmapData; //the BitmapData object that will hold the reflected image private var reflectionBMP:Bitmap; //the clip that will act as out gradient mask private var gradientMask_mc:MovieClip; //how often the reflection should update (if it is video or animated) private var updateInt:Number; //the size the reflection is allowed to reflect within private var bounds:Object; //the distance the reflection is vertically from the mc private var distance:Number = 0; function Reflect(args:Object){ /*the args object passes in the following variables /we set the values of our internal vars to math the args*/ //the clip being reflected mc = args.mc; //the alpha level of the reflection clip var alpha:Number = args.alpha/100; //the ratio opaque color used in the gradient mask var ratio:Number = args.ratio; //update time interval var updateTime:Number = args.updateTime; //the distance at which the reflection visually drops off at var reflectionDropoff:Number = args.reflectionDropoff; //the distance the reflection starts from the bottom of the mc var distance:Number = args.distance; //store width and height of the clip var mcHeight = mc.height; var mcWidth = mc.width; //store the bounds of the reflection bounds = new Object(); bounds.width = mcWidth; bounds.height = mcHeight; //create the BitmapData that will hold a snapshot of the movie clip mcBMP = new BitmapData(bounds.width, bounds.height, true, 0xFFFFFF); mcBMP.draw(mc); //create the BitmapData the will hold the reflection reflectionBMP = new Bitmap(mcBMP); //flip the reflection upside down reflectionBMP.scaleY = -1; //move the reflection to the bottom of the movie clip reflectionBMP.y = (bounds.height*2) + distance; //add the reflection to the movie clip's Display Stack var reflectionBMPRef:DisplayObject = mc.addChild(reflectionBMP); reflectionBMPRef.name = "reflectionBMP"; //add a blank movie clip to hold our gradient mask var gradientMaskRef:DisplayObject = mc.addChild(new MovieClip()); gradientMaskRef.name = "gradientMask_mc"; //get a reference to the movie clip - cast the DisplayObject that is returned as a MovieClip gradientMask_mc = mc.getChildByName("gradientMask_mc") as MovieClip; //set the values for the gradient fill var fillType:String = GradientType.LINEAR; var colors:Array = [0xFFFFFF, 0xFFFFFF]; var alphas:Array = [alpha, 0]; var ratios:Array = [0, ratio]; var spreadMethod:String = SpreadMethod.PAD; //create the Matrix and create the gradient box var matr:Matrix = new Matrix(); //set the height of the Matrix used for the gradient mask var matrixHeight:Number; if (reflectionDropoff<=0) { matrixHeight = bounds.height; } else { matrixHeight = bounds.height/reflectionDropoff; } matr.createGradientBox(bounds.width, matrixHeight, (90/180)*Math.PI, 0, 0); //create the gradient fill gradientMask_mc.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod); gradientMask_mc.graphics.drawRect(0,0,bounds.width,bounds.height); //position the mask over the reflection clip gradientMask_mc.y = mc.getChildByName("reflectionBMP").y - mc.getChildByName("reflectionBMP").height; //cache clip as a bitmap so that the gradient mask will function gradientMask_mc.cacheAsBitmap = true; mc.getChildByName("reflectionBMP").cacheAsBitmap = true; //set the mask for the reflection as the gradient mask mc.getChildByName("reflectionBMP").mask = gradientMask_mc; //if we are updating the reflection for a video or animation do so here if(updateTime > -1){ updateInt = setInterval(update, updateTime, mc); } } public function setBounds(w:Number,h:Number):void{ //allows the user to set the area that the reflection is allowed //this is useful for clips that move within themselves bounds.width = w; bounds.height = h; gradientMask_mc.width = bounds.width; redrawBMP(mc); } public function redrawBMP(mc:MovieClip):void { // redraws the bitmap reflection - Mim Gamiet [2006] mcBMP.dispose(); mcBMP = new BitmapData(bounds.width, bounds.height, true, 0xFFFFFF); mcBMP.draw(mc); } private function update(mc):void { //updates the reflection to visually match the movie clip mcBMP = new BitmapData(bounds.width, bounds.height, true, 0xFFFFFF); mcBMP.draw(mc); reflectionBMP.bitmapData = mcBMP; } public function destroy():void{ //provides a method to remove the reflection mc.removeChild(mc.getChildByName("reflectionBMP")); reflectionBMP = null; mcBMP.dispose(); clearInterval(updateInt); mc.removeChild(mc.getChildByName("gradientMask_mc")); } } }

    Read the article

  • Flash/ActionScript3 crashes on getPixel/32

    - by Quandary
    Question: The below code crashes flash... Why? The crash causing lines seem to be //var uiColor:uint = bmpd.getPixel(i,j); var uiColor:uint = bmpd.getPixel32(i,j); trace("Color: "+ uiColor); I am trying to take a snapshot of a movieclip and iterate through all pixels in the image and get the pixel's color. import flash.display.BitmapData; import flash.geom.*; function takeSnapshot(mc:MovieClip):BitmapData { var sp:BitmapData = new BitmapData(mc.width, mc.height, true, 0x000000); sp.draw(mc, new Matrix(), new ColorTransform(), "normal"); return sp; } var mcMyClip:MovieClip=new MovieClip() var xxx:cMovieClipLoader=new cMovieClipLoader(); xxx.LoadImageAbsSize(mcMyClip,"http://localhost/flash/images/picture.gif", 500,500) //this.addChild(mcMyClip); function WhenImageIsLoaded() { var bmpd:BitmapData=takeSnapshot(mcMyClip); var i,j:uint; for(i=0; i < bmpd.width;++i) { for(j=0; j < bmpd.height;++j) { //var uiColor:uint = bmpd.getPixel(i,j); var uiColor:uint = bmpd.getPixel32(i,j); trace("Color: "+ uiColor); } } var myBitmap:Bitmap = new Bitmap(bmpd); this.addChild(myBitmap); } setTimeout(WhenImageIsLoaded,1000);

    Read the article

  • How do I specify a crossdomain policy file to allow Flash to grab a bitmap from an RTMP (Wowza) vide

    - by Ken Smith
    I'm trying to get a bitmap/snapshot of a Wowza video stream playing on my client, like so: var bitmapData:BitmapData = new BitmapData(view.videoPlayerComponent.width, view.videoPlayerComponent.height); bitmapData.draw(view.videoPlayerComponent); When I do this, I get this error message: SecurityError: Error #2123: Security sandbox violation: BitmapData.draw: http://localhost:51150/Resources/WRemoteWebCam.swf cannot access rtmp://localhost/videochat/smithkl42._default/. No policy files granted access. I presume the error comes from not being able to locate the appropriate crossdomain.xml file. I'm not quite sure where it's looking for it, and a wireshark sniff was inconclusive, so I've tried placing one in each of the following places: http://localhost/crossdomain.xml http://localhost:1935/crossdomain.xml http://localhost:51150/crossdomain.xml I can retrieve the file successfully from each of those three locations. (I'm pretty sure that the last one wouldn't have any effect, since it's just the location of the web site which hosts the page that hosts the .swf file, but on the off chance...) These are the contents of the file that it's grabbing in each instance: <cross-domain-policy> <allow-access-from domain="*" to-ports="*" /> </cross-domain-policy> And it's still throwing that same error message. I've also followed the instructions on the Wowza forums, to turn on StreamVideoSampleAccess in the [install]\conf[appname]\Application.xml, with no joy: <Client> <IdleFrequency>-1</IdleFrequency> <Access> <StreamReadAccess>*</StreamReadAccess> <StreamWriteAccess>*</StreamWriteAccess> <StreamAudioSampleAccess>*</StreamAudioSampleAccess> <StreamVideoSampleAccess>*</StreamVideoSampleAccess> <SharedObjectReadAccess>*</SharedObjectReadAccess> <SharedObjectWriteAccess>*</SharedObjectWriteAccess> </Access> </Client> Any thoughts?

    Read the article

  • Vsync in Flex/Flash/AS3?

    - by oshyshko
    I work on a 2D shooter game with lots of moving objects on the screen (bullets etc). I use BitmapData.copyPixels(...) to render entire screen to a buffer:BitmapData. Then I "copyPixels" from "buffer" to screen:BitmapData. The framerate is 60. private var bitmap:Bitmap = new Bitmap(); private var buffer:Bitmap = new Bitmap(); private function start():void { addChild(bitmap); } private function onEnterFrame():void { // render into "buffer" // copy "buffer" -> "bitmap" } The problem is that the sprites are tearing apart: some part of a sprite got shifted horizontally. It looks like a PC game with VSYNC turned off. Did anyone solve this problem? UPDATE: the question is not about performance, but about getting rid of screen tearing. [!] UPDATE: I've created another question and here you may try both implementations: using Flash way or BitmapData+copyPixels()

    Read the article

  • How to capture page with google map?

    - by Max
    I have a UIComponent with Google map in the continer. I need to capture this container for making a preview. My integration looks like the following: <mx:UIComponent id="mapContainer" width="410" height="300" /> googleMap = new Map(); mapContainer.addChild(googleMap); But if I do("this" - is my UIComponent) var bmd:BitmapData = new BitmapData(this.width, this.height, true, 0x00ffffff); bmd.draw(this); I see the following: An ActionScript error has occurred: SecurityError: Error #2123: Security sandbox violation: BitmapData.draw: http://localhost/ cannot access http://mt1.google.com/vt/lyrs=m@121&hl=en&src=api&x=1&y=1&z=1&s=Gali. No policy files granted access. at flash.display::BitmapData/draw() I now, that I can to add it host to allowed on the custom client. But I need to have working system on any computer ) I've tried to hide it: templateGoogleMapRenderer.mapContainer.setVisible(false); templateGoogleMapRenderer.mapContainer.includeInLayout = false; But it was unsuccessfully. May be I can override some method in my UIComponent, that flex use during BitmapData/draw() ? Capture with hidden map is success result for me )

    Read the article

< Previous Page | 1 2 3 4 5  | Next Page >