gpt4 book ai didi

带有从网络流式传输的图像的 Android 页面 curl ?

转载 作者:行者123 更新时间:2023-11-30 03:37:47 24 4
gpt4 key购买 nike

所以,我正在使用 https://github.com/harism/android_page_curl ,这个项目实现了curl功能来创建一本书。但我想在直接从 Web 流式传输图像时实现相同的效果,显然是以异步方式。

但是我需要一个 OpenGL ,进度条。但是我对 OPENGL 没有任何了解,所以我该如何调整这段代码并实现我想要的功能。

此外,请查看此问题,以便更清楚地了解我想要实现的目标...

PageCurl(magazine) with Image from web

package fi.harism.curl;


public class CurlActivity extends Activity {

private CurlView mCurlView;
Button btn;
private AQuery aq;
Drawable d =null;
TextView mText;
List<String> data;
MediaPlayer mPlayer;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

int index = 0;
if (getLastNonConfigurationInstance() != null) {
index = (Integer) getLastNonConfigurationInstance();
}

mCurlView = (CurlView) findViewById(R.id.curl);
mCurlView.setPageProvider(new PageProvider());
mCurlView.setSizeChangedObserver(new SizeChangedObserver());
mCurlView.setCurrentIndex(index);
mCurlView.setBackgroundColor(Color.GREEN);
}

@Override
public void onPause() {
super.onPause();
mCurlView.onPause();
}

@Override
public void onResume() {
super.onResume();
mCurlView.onResume();
}

@Override
public Object onRetainNonConfigurationInstance() {
return mCurlView.getCurrentIndex();
}

/**
* Bitmap provider.
*/
private class PageProvider implements CurlView.PageProvider {

private String[] mBitmapStrings={"http://myserver.com/image/img%20p1.png",
"http://myserver.com/image/img%20p2.png",
"http://myserver.com/image/img%20p3.png",
"http://myserver.com/image/img%20p4.png"};

@Override
public int getPageCount() {
return mBitmapStrings.length;
}


private Bitmap loadBitmap(int width, int height, int index) throws MalformedURLException, IOException {
Bitmap b = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
b.eraseColor(0xFFFFFFFF);
Canvas c = new Canvas(b);

if(index==mBitmapStrings.length)
{
index=0;
}

Drawable d = new BitmapDrawable(drawable_from_url(mBitmapStrings[index]));

int margin = 7;
int border = 3;
Rect r = new Rect(margin, margin, width - margin, height - margin);

int imageWidth = r.width() - (border * 2);
int imageHeight = imageWidth * d.getIntrinsicHeight()
/ d.getIntrinsicWidth();
if (imageHeight > r.height() - (border * 2)) {
imageHeight = r.height() - (border * 2);
imageWidth = imageHeight * d.getIntrinsicWidth()
/ d.getIntrinsicHeight();
}

r.left += ((r.width() - imageWidth) / 2) - border;
r.right = r.left + imageWidth + border + border;
r.top += ((r.height() - imageHeight) / 2) - border;
r.bottom = r.top + imageHeight + border + border;

Paint p = new Paint();
p.setColor(0xFFC0C0C0);
c.drawRect(r, p);
r.left += border;
r.right -= border;
r.top += border;
r.bottom -= border;

d.setBounds(r);
d.draw(c);

return b;
}

@Override
public void updatePage(CurlPage page, int width, int height, int index) {

Bitmap front;
try {
front = loadBitmap(width, height, index);
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(180, 180, 180), CurlPage.SIDE_BACK);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

/**
* CurlView size changed observer.
*/
private class SizeChangedObserver implements CurlView.SizeChangedObserver {
@Override
public void onSizeChanged(int w, int h) {
/*if (w > h) {
mCurlView.setViewMode(CurlView.SHOW_TWO_PAGES);
mCurlView.setMargins(.1f, .05f, .1f, .05f);
} else {*/
mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
//mCurlView.setMargins(.1f, .1f, .1f, .1f);
mCurlView.setMargins(0,0,0,0);

//}
}
}

Bitmap drawable_from_url(String url) throws java.net.MalformedURLException, java.io.IOException {
Bitmap x;

HttpURLConnection connection = (HttpURLConnection)new URL(url) .openConnection();
connection.setRequestProperty("User-agent","Mozilla/4.0");

connection.connect();
InputStream input = connection.getInputStream();

x = BitmapFactory.decodeStream(input);
return x;
}
}

----编辑----

Also , I am using android-query library for asynchronous image/file loading. Would it be feasible to use it with this project in case of streaming images from web. How?

最佳答案

public class CurlActivity extends Activity {

private CurlView mCurlView;
Bitmap y;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

int index = 0;
if (getLastNonConfigurationInstance() != null) {
index = (Integer) getLastNonConfigurationInstance();
}
mCurlView = (CurlView) findViewById(R.id.curl);
mCurlView.setPageProvider(new PageProvider());
mCurlView.setSizeChangedObserver(new SizeChangedObserver());
mCurlView.setCurrentIndex(index);
mCurlView.setBackgroundColor(0xFF202830);


}

@Override
public void onPause() {
super.onPause();
mCurlView.onPause();
}

@Override
public void onResume() {
super.onResume();
mCurlView.onResume();
}

@Override
public Object onRetainNonConfigurationInstance() {
return mCurlView.getCurrentIndex();
}

/**
* Bitmap provider.
*/
private class PageProvider implements CurlView.PageProvider {

// Bitmap resources.
/*private int[] mBitmapIds = { R.drawable.obama, R.drawable.road_rage,
R.drawable.taipei_101, R.drawable.world };*/
private String[] mBitmapIds = {"your url","your url",
"your urlg", "your url" }; //your image url

@Override
public int getPageCount() {
return 5;
}

private Bitmap loadBitmap(int width, int height, int index) {
Bitmap b = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
b.eraseColor(0xFFFFFFFF);
Canvas c = new Canvas(b);
//Uri url = Uri.parse("http://stackoverflow.com");
//Drawable d =getResources().getDrawable(url);
//Drawable d = getResources().getDrawable(mBitmapIds[index]);
try {
drawableFromUrl(mBitmapIds[index]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Drawable d = new BitmapDrawable(getResources(),y);
//Drawable d = new BitmapDrawable(drawable_from_url(y));
int margin = 7;
int border = 3;
Rect r = new Rect(margin, margin, width - margin, height - margin);

int imageWidth = r.width() - (border * 2);
int imageHeight = imageWidth * d.getIntrinsicHeight()
/ d.getIntrinsicWidth();
if (imageHeight > r.height() - (border * 2)) {
imageHeight = r.height() - (border * 2);
imageWidth = imageHeight * d.getIntrinsicWidth()
/ d.getIntrinsicHeight();
}

r.left += ((r.width() - imageWidth) / 2) - border;
r.right = r.left + imageWidth + border + border;
r.top += ((r.height() - imageHeight) / 2) - border;
r.bottom = r.top + imageHeight + border + border;

Paint p = new Paint();
p.setColor(0xFFC0C0C0);
c.drawRect(r, p);
r.left += border;
r.right -= border;
r.top += border;
r.bottom -= border;

d.setBounds(r);
d.draw(c);

return b;
}

@Override
public void updatePage(CurlPage page, int width, int height, int index) {

switch (index) {
// First case is image on front side, solid colored back.
case 0: {
Bitmap front = loadBitmap(width, height, 0);
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(180, 180, 180), CurlPage.SIDE_BACK);
break;
}
// Second case is image on back side, solid colored front.
case 1: {
Bitmap back = loadBitmap(width, height, 2);
page.setTexture(back, CurlPage.SIDE_BACK);
page.setColor(Color.rgb(127, 140, 180), CurlPage.SIDE_FRONT);
break;
}
// Third case is images on both sides.
case 2: {
Bitmap front = loadBitmap(width, height, 1);
Bitmap back = loadBitmap(width, height, 3);
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setTexture(back, CurlPage.SIDE_BACK);
break;
}
// Fourth case is images on both sides - plus they are blend against
// separate colors.
case 3: {
Bitmap front = loadBitmap(width, height, 2);
Bitmap back = loadBitmap(width, height, 1);
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setTexture(back, CurlPage.SIDE_BACK);
page.setColor(Color.argb(127, 170, 130, 255),
CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(255, 190, 150), CurlPage.SIDE_BACK);
break;
}
// Fifth case is same image is assigned to front and back. In this
// scenario only one texture is used and shared for both sides.
case 4:
Bitmap front = loadBitmap(width, height, 0);
page.setTexture(front, CurlPage.SIDE_BOTH);
page.setColor(Color.argb(127, 255, 255, 255),
CurlPage.SIDE_BACK);
break;
}
}

}

/**
* CurlView size changed observer.
*/
private class SizeChangedObserver implements CurlView.SizeChangedObserver {
@Override
public void onSizeChanged(int w, int h) {
if (w > h) {
mCurlView.setViewMode(CurlView.SHOW_TWO_PAGES);
mCurlView.setMargins(.1f, .05f, .1f, .05f);
} else {
mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
mCurlView.setMargins(.1f, .1f, .1f, .1f);
}
}
}

public void drawableFromUrl(String url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.connect();
InputStream input = connection.getInputStream();

y = BitmapFactory.decodeStream(input);

}
}

关于带有从网络流式传输的图像的 Android 页面 curl ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16373550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com