panpf / sketch

Sketch is an image loading library designed for Compose Multiplatform and Android View. It is powerful and rich in functions. In addition to basic functions, it also supports GIF, SVG, video thumbnails, Exif Orientation, etc.
Apache License 2.0
2.05k stars 309 forks source link

Bitmap #62

Closed arunramya closed 6 years ago

arunramya commented 6 years ago

Get bitmap from inputstream. Please help me how to call via Sketch.

panpf commented 6 years ago

I do not understand your needs, please elaborate

arunramya commented 6 years ago

i got stream from file, through this stream how can i get bitmap?

arunramya commented 6 years ago

FileInputStream initialStream44 = new FileInputStream(new File(Environment.getExternalStorageDirectory() + "/output.jpg")); byte[] bufferr = new byte[initialStream44.available()]; initialStream44.read(bufferr);

Here how can i get bitmap by passing initialStream44. Please Help me.

panpf commented 6 years ago

Does not support reading bitmap directly from the input stream, if you know the path to the file, use the file path

arunramya commented 6 years ago

i know file path. but the file content contains two images. but i have got second image contents via stream. but now i want to get bitmap for the stream..

panpf commented 6 years ago

You can solve this problem by custom UriModel, refer to https://github.com/panpf/sketch/blob/master/sample/src/main/java/me/panpf/sketch/sample/util/XpkIconUriModel.java

You need to customize two UriModel, respectively, used to read different pictures in the same file

arunramya commented 6 years ago

I have implemented what you told.

How can i call that custom uri model while display bitmap?

arunramya commented 6 years ago

private class XpkIconUriModel extends AbsStreamDiskCacheUriModel {

private ByteArrayInputStream myInputStream;

@NonNull
@Override
protected InputStream getContent(@NonNull Context context, @NonNull String uri) throws GetDataSourceException
{

  FileInputStream strem = null;
  try
  {
    strem = new FileInputStream(uri);
    byte[] xxxx = new byte[strem.available()];
    strem.read(xxxx,0,xxxx.length);      

  } catch (Exception e)
  {
    e.printStackTrace();
    Log.e("Exception Here","oh sorry");
  }

  return strem;
}

@Override
protected boolean match(@NonNull String uri)
{
  return false;
}

}

panpf commented 6 years ago

An introduction to uri mode and a custom tutorial here https://github.com/panpf/sketch/blob/master/docs/wiki/uri_model.md

You can translate it to see