FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OneScript/src/TestApp/Controls/ImageArray.cs at develop · bapho-bush/OneScript · GitHub
bapho-bush
/
OneScript
Public
forked from
EvilBeaver/OneScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OneScript
/
src
/
TestApp
/
Controls
/
ImageArray.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
144 lines (110 loc) · 4.14 KB
Breadcrumbs
OneScript
/
src
/
TestApp
/
Controls
/
ImageArray.cs
Copy path
File metadata and controls
144 lines (110 loc) · 4.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Drawing
;
using
System
.
Windows
.
Media
;
using
System
.
Windows
.
Media
.
Imaging
;
namespace
V8Reader
.
Core
{
class
ImageArray
{
Bitmap
m_CompleteImage
;
public
int
Count
{
get
;
private
set
;
}
public
int
IconWidth
{
get
;
private
set
;
}
public
int
IconHeight
{
get
;
private
set
;
}
public
ImageArray
(
Bitmap
Source
,
int
ItemWidth
,
int
ItemHeight
)
{
if
(
ItemWidth
<=
0
||
ItemHeight
<=
0
)
throw
new
ArgumentException
(
)
;
m_CompleteImage
=
(
Bitmap
)
Source
.
Clone
(
)
;
Count
=
m_CompleteImage
.
Width
/
ItemWidth
;
IconWidth
=
ItemWidth
;
IconHeight
=
ItemHeight
;
}
public
Bitmap
this
[
int
index
]
{
get
{
return
GetItem
(
index
)
;
}
}
private
Bitmap
GetItem
(
int
index
)
{
if
(
index
<
0
||
index
>=
Count
)
throw
new
IndexOutOfRangeException
(
)
;
int
startPoint
=
IconWidth
*
index
;
Bitmap
ItemBitmap
=
new
Bitmap
(
IconWidth
,
IconHeight
,
m_CompleteImage
.
PixelFormat
)
;
Graphics
.
FromImage
(
ItemBitmap
)
.
DrawImage
(
m_CompleteImage
,
new
Rectangle
(
0
,
0
,
IconWidth
,
IconHeight
)
,
new
Rectangle
(
startPoint
,
0
,
IconWidth
,
IconHeight
)
,
GraphicsUnit
.
Pixel
)
;
return
ItemBitmap
;
}
}
class
WPFImageArray
{
public
WPFImageArray
(
BitmapImage
Source
,
int
ItemWidth
,
int
ItemHeight
)
{
m_CompleteImage
=
Source
.
Clone
(
)
;
m_CompleteImage
.
Freeze
(
)
;
Load
(
ItemWidth
,
ItemHeight
)
;
}
public
WPFImageArray
(
Uri
ResourceURI
,
int
ItemWidth
,
int
ItemHeight
)
{
m_CompleteImage
=
new
BitmapImage
(
ResourceURI
)
;
Load
(
ItemWidth
,
ItemHeight
)
;
}
public
ImageSource
this
[
int
index
]
{
get
{
return
GetItem
(
index
)
;
}
}
private
ImageSource
GetItem
(
int
index
)
{
if
(
index
<
0
||
index
>=
Count
)
throw
new
IndexOutOfRangeException
(
)
;
if
(
m_Cache
.
ContainsKey
(
index
)
)
{
return
m_Cache
[
index
]
;
}
int
startPoint
=
IconWidth
*
index
;
var
Frame
=
new
System
.
Windows
.
Int32Rect
(
startPoint
,
0
,
IconWidth
,
IconHeight
)
;
byte
[
]
bits
=
new
byte
[
m_CompleteImage
.
PixelHeight
*
stride
]
;
m_CompleteImage
.
CopyPixels
(
Frame
,
bits
,
stride
,
0
)
;
WriteableBitmap
target
=
new
WriteableBitmap
(
IconWidth
,
IconHeight
,
m_CompleteImage
.
DpiX
,
m_CompleteImage
.
DpiY
,
m_CompleteImage
.
Format
,
null
)
;
// Write the pixel data to the WriteableBitmap.
target
.
WritePixels
(
new
System
.
Windows
.
Int32Rect
(
0
,
0
,
IconWidth
,
IconHeight
)
,
bits
,
stride
,
0
)
;
target
.
Freeze
(
)
;
m_Cache
.
Add
(
index
,
target
)
;
return
target
;
}
private
void
Load
(
int
ItemWidth
,
int
ItemHeight
)
{
//int bytesPerPixel = (width * m_CompleteImage.Format.BitsPerPixel + 7) / 8;
//stride = width * bytesPerPixel;
stride
=
m_CompleteImage
.
PixelWidth
*
(
m_CompleteImage
.
Format
.
BitsPerPixel
/
8
)
;
Count
=
(
int
)
m_CompleteImage
.
Width
/
ItemWidth
;
IconWidth
=
ItemWidth
;
IconHeight
=
ItemHeight
;
}
public
int
Count
{
get
;
private
set
;
}
public
int
IconWidth
{
get
;
private
set
;
}
public
int
IconHeight
{
get
;
private
set
;
}
private
BitmapImage
m_CompleteImage
;
private
int
stride
;
private
Dictionary
<
int
,
ImageSource
>
m_Cache
=
new
Dictionary
<
int
,
ImageSource
>
(
)
;
}
}
Back
|
FazBrowse Home
|
New Git URL