demo示例
opengl原理:
這樣拆分之後雖然可以正常渲染,但是帶來的問題是我的四個頂點都是死的,也就是四個頂點必須是畫布的四個頂點,改變頂點的座標後只能導致整張畫布的變動,而不是某乙個區域的變動,拉伸的話也是整張的拉伸,所以想要實現區域性處理的話這種分割方式不可行。
這樣一來就可以保證中間的矩形的高度可以任意變化而上下兩部分的高度不變只改變位置,也就是說我們這個demo中所做的任何拉伸操作都是對中間矩形的操作,換而言之就是改變最上面的矩形和最下面的矩形之間的距離來達到對中間區域的拉伸和壓縮的目的。根據拆分的方式我們用頂點的座標建立乙個陣列
//頂點陣列
glfloat vertices = ;
//填充紋理的陣列
glfloat texcoords = ;複製**
*****************custompanview********************
#import
@protocol custompanviewdelegate /**
* 開始拖拽
* * @param custompanview 自身
* @param centery 自身所在的y座標
*/- (void)begindragwithcoustompanview:(uiview *)custompanview centery:(cgfloat)centery;
@end
@inte***ce custompanview : uiview
@property (nonatomic, assign) iddelegate;
@end複製**
使用乙個delegate將拖移後的y座標返回,因為是豎直運動的所以我們只關心y軸座標。*****************custompanviewdelegate********************
#pragma mark -
#pragma mark 拖拽view的**方法
-(void)begindragwithcoustompanview:(uiview *)custompanview centery:(cgfloat)centery
if (custompanview.center.y <= imagetop)
// 獲取兩條線的座標
cgfloat topy = _topview.center.y;
cgfloat bottomy = _bottomview.center.y;
// 根據兩條線的座標重新整理裁剪區域ui
[_cutlabel setframe:cgrectmake(0, topy < bottomy ? topy : bottomy, screen_width, fabs(bottomy - topy))];
// 算出裁剪起始座標和結束座標
cgfloat frompoint = topy < bottomy ? (imagebottom - bottomy) / imageheight : (imagebottom - topy) / imageheight;
cgfloat topoint = topy < bottomy ? (imagebottom - topy) / imageheight : (imagebottom - bottomy) / imageheight;
//將中間的矩形的頂點座標和座標聯絡裁剪區域聯絡起來。
[self sendfromepoint:frompoint endpoint:topoint];
if (_cutlabel.frame.size.height < 30) else
[self.slider setvalue:0.0 animated:yes];
tmpheight = 0.0f;
}複製**
- (void)action:(uislider *)sender else
if (i >= 9) }}
//縮小時候如果編輯區域已經成為一條線了就不能在縮小了
if (vertices[11] > vertices[7])
}複製**
#pragma mark -
#pragma mark 獲取處理後的
- (uiimage *) createimage else
int imagewidth = screen_width * screenscale;
int datalength = imagewidth * imgheight * 4;
glubyte *data = (glubyte*)malloc(datalength * sizeof(glubyte));
glpixelstorei(gl_pack_alignment, 4);
glreadpixels(0, imagey, imagewidth, imgheight, gl_rgba, gl_unsigned_byte, data); //從記憶體中讀取畫素
cgdataproviderref ref = cgdataprovidercreatewithdata(null, data, datalength, null);
cgcolorspaceref colorspace = cgcolorspacecreatedevicergb();
cgimageref iref = cgimagecreate(imagewidth, imgheight, 8, 32, imagewidth * 4, colorspace, kcgbitmapbyteorder32big | kcgimagealphapremultipliedlast,ref, null, true, kcgrenderingintentdefault);
uigraphicsbeginimagecontext(cgsizemake(imagewidth, imgheight));
cgcontextref cgcontext = uigraphicsgetcurrentcontext();
cgcontextsetblendmode(cgcontext, kcgblendmodecopy);
cgcontextdrawimage(cgcontext, cgrectmake(0, 0, imagewidth, imgheight), iref);
cgimageref imagemasked = cgbitmapcontextcreateimage(cgcontext);
uiimage * image = [uiimage imagewithcgimage:imagemasked scale:screenscale orientation:uiimageorientationup];
uigraphicsendimagecontext();
free(data);
cfrelease(ref);
cfrelease(colorspace);
cgimagerelease(iref);
return image;
}複製**
在wxPython中使用OpenGL
參考資料只有wxpython doc的乙個例子。需要安裝pyopengl pyopengl.sourceforge.net 給opengl使用的視窗容器是wx.glcanvas.glcanvas,子類化它,並在子類的paint事件處理中這樣處理 def onpaint self,event dc w...
在wxPython中使用OpenGL
參考資料只有wxpython doc的乙個例子。需要安裝pyopengl pyopengl.sourceforge.net 給opengl使用的視窗容器是wx.glcanvas.glcanvas,子類化它,並在子類的paint事件處理中這樣處理 def onpaint self,event dc w...
在ios中使用soundtouch庫實現變聲
要在ios中實現乙個變聲技術,而且又要要求能在iphone 3g上也能執行,所以自帶的一些api就顯得比較麻煩,因此決定使用soundtouch開源庫,該庫可以實現變聲效果,包括可以調節聲音的頻率而不改變聲音的長度,大家可以使用openal試試,改變頻率之後,聲音就會變短了。呵呵,有了這個庫,其實我...