无法将 image int 设置到 webview 中?

发布于 2024-12-07 06:35:55 字数 1184 浏览 0 评论 0 原文

好吧,这就是我的问题。我有一个包含大量图片的应用程序,我希望能够捏缩放这些图片,但由于 ImageViewer 本身不支持此功能,我想我应该使用 Webviewer,但事情就是这样。我所有的图片都保存到我的“图片”int 中,它是我想要加载到网络查看器中的图片函数。不是特定的 \drawable\bla.jpg 到处搜索但没有找到任何有关它的信息。我将附上一些代码以供参考。

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=getIntent();
int picture=intent.getIntExtra("picture", 22);
setContentView(R.layout.pictureframe);        
ImageView image = (ImageView) findViewById(R.id.pansarvagn);
image.setBackgroundResource(picture);

这是我想要的地方

Webview image = (WebView) findViewById(R.id.pansarvagn);
image.(setdata bla bla)

图片函数。

public void displayPicture(int pictureresource){
Intent intent = new Intent();
intent.putExtra("picture", pictureresource);
intent.setClass(getApplicationContext(), Picture.class);
startActivity(intent);

,这是调用的

Button tank = (Button) findViewById(R.id.tank);
tank.setOnClickListener(new View.OnClickListener() {
   public void onClick(View v) {
 displayPicture(R.drawable.tank);
}

为了进一步详细说明,我想将图像放入我可以放大的网络视图中。因此,网络视图中的某种图像视图可以用我的图片填充网络视图。然后我希望能够放大它。

Allright so here's my problem. I have an app which contains alot of pictures and i wanted to be able to pinchzoom these, but since the ImageViewer doesnt support this natively I thought I'd use the Webviewer instead, but heres the thing. all my pictures are saved into my "picture" int and its the picture function i want to load into the webviewer. not a specific \drawable\bla.jpg Searched all around but didnt find anything about it. I'll attach some code for reference.

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=getIntent();
int picture=intent.getIntExtra("picture", 22);
setContentView(R.layout.pictureframe);        
ImageView image = (ImageView) findViewById(R.id.pansarvagn);
image.setBackgroundResource(picture);

and its here where i want smth like

Webview image = (WebView) findViewById(R.id.pansarvagn);
image.(setdata bla bla)

and this is the picture function

public void displayPicture(int pictureresource){
Intent intent = new Intent();
intent.putExtra("picture", pictureresource);
intent.setClass(getApplicationContext(), Picture.class);
startActivity(intent);

called by

Button tank = (Button) findViewById(R.id.tank);
tank.setOnClickListener(new View.OnClickListener() {
   public void onClick(View v) {
 displayPicture(R.drawable.tank);
}

To further elaborate i want to put an image into a webview which i will be able to zoom into. so some sort of imageview inside the webview to fill up the webview with my picture. and then I want to be able to zoom in on it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染火枫林 2024-12-14 06:35:55

您需要创建自己的 ContentProvider 并覆盖它的 openFile(..) 方法。然后您可以将其提供给 WebView:

myWebView.loadUrl("content://your.content.provider/someImageName");

这是一个示例: http://www.techjini.com/blog/2009/01/10/android-tip-1-contentprovider-accessing-local-file-system-from-webview-showing-image-in- webview-using-content/

注意:使用这种方法,您需要将图像保存在某个地方。你将无法凭记忆为他们服务。

You need to create you own ContentProvider and override it's opeenFile(..) method. Then you can feed it to WebView:

myWebView.loadUrl("content://your.content.provider/someImageName");

Here is an example: http://www.techjini.com/blog/2009/01/10/android-tip-1-contentprovider-accessing-local-file-system-from-webview-showing-image-in-webview-using-content/

Note: with this approach you will need to save your images somewhere. You will not be able to serve them from memory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文