Hi,
I would like to know how to copy a portion of an image in an irregular shape using bitmap data or any other function. Kindly let me know if you need further explanation in this.
Regards,
Kameshwaran A.
You will get portion of an image using BitmapData class method copyPixels(), refer the syntax:
|
So in that case you have to define the portation that you expect from the image bitmapdata.
Hi Bharat,
Thanks for the information. I have used the above the syntax to crop the image with rectangle points. But, i need to know how can i use the above syntax to copy the irregular shape.
For ex:
for rect i have used the below code
desBmp.copyPixels(srcBmp,new Rectangle(x, y, w, h),new Point(0, 0));
If i want to copy for triangle / polystar / user defined points(polygon), in these case how can i use the above the sytax.
Regards,
Kameshwara A.
hi
I dont know how to extract that particular content and convert them in to movieclip.
To be much clear about my requirement,
I have 600*800 image and i loaded in to the interface. I am allowing the user to draw the particular portion over the image inorder have that particular portion and save it in their gallery.
Previously i have given only rectangle option so there's no issue for me in doing that using bitmap.
But now i need to give the free tool so that user can choose any part like text or face or ..
once user has drawn the portion, i will having the co ordinate like below,
x1y1,x2y2, x3y3,x4y4,x5y5,x6y6, x7y7,x8y8
i need to copy the portion that covers in the coordinate and i need to show the preview to the user.
I hope it will explain my prolem prity clear.
import flash.geom.Point;
import flash.display.BitmapData
var bmp:BitmapData = BitmapData.loadBitmap("bmpID");
var img:MovieClip = createEmptyMovieClip("img",0);
img.attachBitmap(bmp,0);
var mc:MovieClip = this.createEmptyMovieClip("mc",1);
var ptA:Array = [];
img.onMouseDown = function(){
this.onMouseUp = function(){
//delete this.onMouseDown
delete this.onEnterFrame;
}
var pt:Point = new Point(_xmouse,_ymouse);
ptA.push(pt);
this.moveTo(pt.x,pt.y);
this.onEnterFrame = function(){
var pt:Point = new Point(_xmouse,_ymouse);
ptA.push(pt)
with(this){
lineStyle(1,0x000000);
lineTo(pt.x,pt.y);
}
}
}
this.onMouseUp = function(){
mc.beginBitmapFill(bmp);
mc.moveTo(ptA[0].x,ptA[0].y);
for(var i:Number=1;i<ptA.length;i++){
mc.lineTo(ptA[i].x,ptA[i].y);
}
mc.endFill();
ptA.length = 0;
}
I have checked but it is not working for me. Let me tell you what i have done.
I have copied this code and put in the test file. in library i have a movieclip with linkage id "bmpID" and i have placed a image inside.
when i publish i couldn't able to see the image but i can draw. Once i have drawn using line. i can't see the image of the portion.
I don't know what mistake i have made. Guide me.
if you don't want the bitmap on-stage, use:
import flash.geom.Point;
import flash.display.BitmapData
var bmp:BitmapData = BitmapData.loadBitmap("bmpID");
var img:MovieClip = createEmptyMovieClip("img",0);
//img.attachBitmap(bmp,0);
var mc:MovieClip = this.createEmptyMovieClip("mc",1);
var ptA:Array = [];
img.onMouseDown = function(){
this.onMouseUp = function(){
//delete this.onMouseDown
delete this.onEnterFrame;
}
var pt:Point = new Point(_xmouse,_ymouse);
ptA.push(pt);
this.moveTo(pt.x,pt.y);
this.onEnterFrame = function(){
var pt:Point = new Point(_xmouse,_ymouse);
ptA.push(pt)
with(this){
lineStyle(1,0x000000);
lineTo(pt.x,pt.y);
}
}
}
this.onMouseUp = function(){
mc.beginBitmapFill(bmp);
mc.moveTo(ptA[0].x,ptA[0].y);
for(var i:Number=1;i<ptA.length;i++){
mc.lineTo(ptA[i].x,ptA[i].y);
}
mc.endFill();
ptA.length = 0;
}
// here's the a file with that code: http://www.kglad.com/Files/forums/bmpFill.fla
North America
Europe, Middle East and Africa
Asia Pacific