3
Ext.define('ImageModel', {
        extend: 'Ext.data.Model',
        fields: ['PicID', 'PicUploadedDateTime','PicData']
    });

    var ImgStore = Ext.create('Ext.data.JsonStore', {
        model: 'ImageModel',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'get-image.php',
            baseParams: {  //here you can define params you want to be sent on each request from this store
                        mainid: 'value1',
                        startdate: 'value2',
                        enddate: 'value3'
                        },
            reader: {
                type: 'json',
                root: 'images'
            }
        }
    });

    var listView = Ext.create('Ext.grid.Panel', {
        region: 'west',
        id : 'imagelist',
        title: 'Select Image',
        width: 200,
        split: true,
        collapsible: true,
        floatable: false,
        title:'Select Image',
        renderTo: Ext.getBody(),
        store: ImgStore,
        multiSelect: true,
        viewConfig: {
            emptyText: 'No images to display'
        },

        columns: [
            {
            text: 'Date Time Uploaded',
            //xtype: 'datecolumn',
            //format: 'Y-m-d H:i:s',
            flex: 65,
            width: 100,
            dataIndex: 'PicUploadedDateTime'
        }]
    });

listView.on('selectionchange', function(view, nodes){
        Ext.getCmp('displayimage') = nodes[0].get("PicData") // display the image on here
        //when listview selected the image,will display the image at here.
    });

i have create a listview,when selectionchange on listview,will show the image on Ext.getCmp('displayimage') .

nodes[0].get("PicData") is the selected image data
the image data are blob value(all are the JPEG hex value),how to display the image from extjs?

UPDATE

this is my displayimage code

button.on('click', function(){
        if (!win) {
            win = Ext.create('widget.window', {
                title: 'View Image',
                closable: true,
                closeAction: 'hide',
                width: 600,
                minWidth: 350,
                height: 550,
                layout: {
                    type: 'border',
                    padding: 5
                        },
                items:[
                        listView, 
                    {                           
                    region: 'center',
                    //xtype: 'tabpanel',
                    minheight: 350,
                    items: [{
                        //title: 'Bogus Tab',
                        xtype : 'image',
                        id : 'displayimage',
                            }]
                    },
                    {
                    region: 'north',
                    margin : "5 0 5 0",
                    //xtype: 'tabpanel',
                    minheight: 350,
                    items: [dr]
                    }]
            });

after i change the code to

Ext.getCmp('displayimage').src = 'data:image/jpeg;base64,'+nodes[0].get("PicData") // 

Image corrupt or truncated

this is the error message i get from firebug,but i can sure that my binary data are correct,because i have tried to use python convert it to .jpeg file

this is an .jpeg example blob value(binary string) from a database,
http://pastebin.ca/raw/2314500

2 Answers 2

1

Need to adding in model methods (and use converter from my answer of you another question):

getImage: function() {
    return this.getBase64(this.get('PicData'));
},
getBase64: function(str) {
    return btoa(String.fromCharCode.apply(null, str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
}

Example on jsfiddle with your image & my wife photo.

Sign up to request clarification or add additional context in comments.

Comments

1

Assuming that your Ext.getCmp('displayimage') represents an Ext.Img component , you can set its "src" property to contain the image data, but

  • you must have it encoded as base64, not hex

  • you have to add a prefix ( for example data:image/jpeg;base64, if the image is a Jpeg one) indicating that you will pass actual data instead of a regular Url

So you should write something like:

listView.on('selectionchange', function(view, nodes){
    Ext.getCmp('displayimage').src = 'data:image/jpeg;base64,'+nodes[0].get("PicData") // display the image on here
    //when listview selected the image,will display the image at here.
});

7 Comments

Ext.getCmp('displayimage').src is a xtype : 'container' , but still can't display the image.why?
If you want to pass raw image data to display it inside a web page, you have to use either a regular <img src="smething"> html tag, or an Ext.img component (xtype 'image') with its "src" attribute set. So you should add such a component, maybe inside your 'displayimage' container. Can you show the complete source code for this page?
So, I can see that your displayimage is an Ext.Img (xtype 'image') component, which is great. Did you check what is the html rendered inside your 'win' Window using the 'inspect element' option of your browser? Is there an <img> tag? What does its src attribute contain? Any error message on the console? By the way, did you follow what I put in my answer?
No!?! i dont have any <img> tag? because it is not html page. i have no idea what u are saying =.="
If not to build a web UI, what do you use ExtJS for? Which browser do you use to test your code?
|